Exemplo n.º 1
0
 private static void InjectContext(IHeadersCollection headers, string traceId, string spanId, string samplingPriority, string origin)
 {
     headers.Add(HttpHeaderNames.TraceId, traceId);
     headers.Add(HttpHeaderNames.ParentId, spanId);
     headers.Add(HttpHeaderNames.SamplingPriority, samplingPriority);
     headers.Add(HttpHeaderNames.Origin, origin);
 }
Exemplo n.º 2
0
        internal void ExtractHeaderTags_MatchesCaseInsensitiveHeaders(IHeadersCollection headers)
        {
            // Initialize constants
            const string customHeader1Name    = "dd-custom-header1";
            const string customHeader1Value   = "match1";
            const string customHeader1TagName = "custom-header1-tag";

            const string customHeader2Name                = "DD-CUSTOM-HEADER-MISMATCHING-CASE";
            const string customHeader2Value               = "match2";
            const string customHeader2TagName             = "custom-header2-tag";
            string       customHeader2LowercaseHeaderName = customHeader2Name.ToLowerInvariant();

            // Add headers
            headers.Add(customHeader1Name, customHeader1Value);
            headers.Add(customHeader2Name, customHeader2Value);

            // Initialize header-tag arguments and expectations
            var headerTags = new Dictionary <string, string>();

            headerTags.Add(customHeader1Name, customHeader1TagName);
            headerTags.Add(customHeader2LowercaseHeaderName, customHeader2TagName);

            var expectedResults = new Dictionary <string, string>();

            expectedResults.Add(customHeader1TagName, customHeader1Value);
            expectedResults.Add(customHeader2TagName, customHeader2Value);

            // Test
            var tagsFromHeader = SpanContextPropagator.Instance.ExtractHeaderTags(headers, headerTags, TestPrefix);

            // Assert
            Assert.NotNull(tagsFromHeader);
            Assert.Equal(expectedResults, tagsFromHeader);
        }
Exemplo n.º 3
0
        internal void ExtractHeaderTags_ForEmptyStringMappings_CreatesNormalizedTagWithPrefix(IHeadersCollection headers)
        {
            string invalidCharacterSequence      = "*|&#$%&^`.";
            string normalizedReplacementSequence = new string('_', invalidCharacterSequence.Length);

            // Add headers
            headers.Add("x-header-test-runner", "xunit");
            headers.Add($"x-header-1DATADOG-{invalidCharacterSequence}", "true");

            // Initialize header-tag arguments and expectations
            var headerToTagMap = new Dictionary <string, string>
            {
                { "x-header-test-runner", string.Empty },
                { $"x-header-1DATADOG-{invalidCharacterSequence}", string.Empty },
            };

            var expectedResults = new Dictionary <string, string>
            {
                { TestPrefix + "." + "x-header-test-runner", "xunit" },
                { TestPrefix + "." + $"x-header-1datadog-{normalizedReplacementSequence}", "true" }
            };

            // Test
            var tagsFromHeader = SpanContextPropagator.Instance.ExtractHeaderTags(headers, headerToTagMap, TestPrefix);

            // Assert
            Assert.NotNull(tagsFromHeader);
            Assert.Equal(expectedResults, tagsFromHeader);
        }
        private static IHeadersCollection InjectContext(IHeadersCollection headers, string traceId, string spanId, string samplingPriority)
        {
            headers.Add(B3HttpHeaderNames.B3TraceId, traceId);
            headers.Add(B3HttpHeaderNames.B3SpanId, spanId);

            // Mimick the B3 injection mapping of samplingPriority
            switch (samplingPriority)
            {
            case "-1":
            // SamplingPriority.UserReject
            case "0":
                // SamplingPriority.AutoReject
                headers.Add(B3HttpHeaderNames.B3Flags, "0");
                break;

            case "1":
                // SamplingPriority.AutoKeep
                headers.Add(B3HttpHeaderNames.B3Sampled, "1");
                break;

            case "2":
                // SamplingPriority.UserKeep
                headers.Add(B3HttpHeaderNames.B3Flags, "1");
                break;

            default:
                // Invalid samplingPriority
                break;
            }

            return(headers);
        }
Exemplo n.º 5
0
 public static void Add(this IHeadersCollection headersCollection, string name, IEnumerable <string> value)
 {
     if (headersCollection == null)
     {
         throw new ArgumentNullException(nameof(headersCollection));
     }
     headersCollection.Add(new KeyValuePair <string, IEnumerable <string> >(name, value));
 }
Exemplo n.º 6
0
        public static void Add(this IHeadersCollection headersCollection, string name, string value)
        {
            if (headersCollection == null)
            {
                throw new ArgumentNullException(nameof(headersCollection));
            }
            if (headersCollection.Contains(name))
            {
                throw new InvalidOperationException($"The name of {name} already exists in the header collection");
            }

            headersCollection.Add(new KeyValuePair <string, IEnumerable <string> >(name, new List <string> {
                value
            }));
        }
Exemplo n.º 7
0
        internal void ExtractHeaderTags_EmptyHeaderTags_AddsNoTags(IHeadersCollection headers)
        {
            // Add headers
            headers.Add("x-header-test-runner", "xunit");

            // Initialize header-tag arguments and expectations
            var headerToTagMap  = new Dictionary <string, string>();
            var expectedResults = new Dictionary <string, string>();

            // Test
            var tagsFromHeader = SpanContextPropagator.Instance.ExtractHeaderTags(headers, headerToTagMap, TestPrefix);

            // Assert
            Assert.NotNull(tagsFromHeader);
            Assert.Equal(expectedResults, tagsFromHeader);
        }