| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Diagnostics; |
| | 7 | | using Azure.Core; |
| | 8 | | using Azure.Core.Pipeline; |
| | 9 | |
|
| | 10 | | namespace Azure.Data.AppConfiguration |
| | 11 | | { |
| | 12 | | internal class CustomHeadersPolicy : HttpPipelineSynchronousPolicy |
| | 13 | | { |
| | 14 | | private const string ActivityId = "Azure.CustomDiagnosticHeaders"; |
| | 15 | |
|
| 2 | 16 | | private static readonly Dictionary<string, bool> SupportedHeaders = new Dictionary<string, bool>(StringComparer. |
| 2 | 17 | | { |
| 2 | 18 | | { "x-ms-client-request-id", true }, |
| 2 | 19 | | { "x-ms-correlation-request-id", false }, |
| 2 | 20 | | { "correlation-context", false } |
| 2 | 21 | | }; |
| | 22 | |
|
| | 23 | | public override void OnSendingRequest(HttpMessage message) |
| | 24 | | { |
| 792 | 25 | | Activity activity = Activity.Current; |
| 1460 | 26 | | while (activity != null && activity.OperationName != ActivityId) |
| | 27 | | { |
| 668 | 28 | | activity = activity.Parent; |
| | 29 | | } |
| | 30 | |
|
| 792 | 31 | | if (activity == null) |
| | 32 | | { |
| 768 | 33 | | return; |
| | 34 | | } |
| | 35 | |
|
| 144 | 36 | | foreach (KeyValuePair<string, string> tag in activity.Tags) |
| | 37 | | { |
| 48 | 38 | | if (SupportedHeaders.TryGetValue(tag.Key, out bool isClientRequestId)) |
| | 39 | | { |
| 36 | 40 | | if (isClientRequestId) |
| | 41 | | { |
| | 42 | | // ClientRequestId policy will set the header from this Request property |
| 12 | 43 | | message.Request.ClientRequestId = tag.Value; |
| | 44 | | } |
| | 45 | | else |
| | 46 | | { |
| 24 | 47 | | message.Request.Headers.Add(tag.Key, tag.Value); |
| | 48 | | } |
| | 49 | | } |
| | 50 | | } |
| 24 | 51 | | } |
| | 52 | | } |
| | 53 | | } |