| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Runtime.InteropServices; |
| | 5 | |
|
| | 6 | | namespace Azure.Core.Pipeline |
| | 7 | | { |
| | 8 | | internal class TelemetryPolicy : HttpPipelineSynchronousPolicy |
| | 9 | | { |
| | 10 | | private readonly string _header; |
| | 11 | |
|
| 62 | 12 | | public TelemetryPolicy(string componentName, string componentVersion, string? applicationId) |
| | 13 | | { |
| 62 | 14 | | var platformInformation = $"({RuntimeInformation.FrameworkDescription}; {RuntimeInformation.OSDescription})" |
| 62 | 15 | | if (applicationId != null) |
| | 16 | | { |
| 4 | 17 | | _header = $"{applicationId} azsdk-net-{componentName}/{componentVersion} {platformInformation}"; |
| | 18 | | } |
| | 19 | | else |
| | 20 | | { |
| 58 | 21 | | _header = $"azsdk-net-{componentName}/{componentVersion} {platformInformation}"; |
| | 22 | | } |
| 58 | 23 | | } |
| | 24 | |
|
| | 25 | | public override void OnSendingRequest(HttpMessage message) |
| | 26 | | { |
| 1642 | 27 | | message.Request.Headers.Add(HttpHeader.Names.UserAgent, _header); |
| 1642 | 28 | | } |
| | 29 | | } |
| | 30 | | } |