From bf56863cc80c583a16c1f03be40f0f4a7987e46b Mon Sep 17 00:00:00 2001 From: Lucas Pimentel Date: Mon, 21 Oct 2024 17:28:40 -0400 Subject: [PATCH] assert that baggage is null in the trace context extraction tests --- .../B3MultipleHeadersPropagatorTests.cs | 22 ++++++++++++++----- .../B3SingleHeaderPropagatorTests.cs | 13 +++++++++-- .../Propagators/DatadogPropagatorTests.cs | 19 +++++++++++++--- .../MultiSpanContextPropagatorTests.cs | 16 ++++++++++++++ .../W3CTraceContextPropagatorTests.cs | 2 ++ 5 files changed, 62 insertions(+), 10 deletions(-) diff --git a/tracer/test/Datadog.Trace.Tests/Propagators/B3MultipleHeadersPropagatorTests.cs b/tracer/test/Datadog.Trace.Tests/Propagators/B3MultipleHeadersPropagatorTests.cs index 5f978fe463b9..76dae77b8a0a 100644 --- a/tracer/test/Datadog.Trace.Tests/Propagators/B3MultipleHeadersPropagatorTests.cs +++ b/tracer/test/Datadog.Trace.Tests/Propagators/B3MultipleHeadersPropagatorTests.cs @@ -186,6 +186,8 @@ public void Extract_IHeadersCollection( SamplingPriority = samplingPriority, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Theory] @@ -234,6 +236,8 @@ public void Extract_CarrierAndDelegate( SamplingPriority = samplingPriority, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -255,12 +259,14 @@ public void ExtractAndInject_PreserveOriginalTraceId() const ulong expectedSpanId = 0x00f067aa0ba902b7UL; var context = B3Propagator.Extract(headers.Object); - var spanContext = context.SpanContext!; + var result = context.SpanContext!; + + result.Should().NotBeNull(); + result.TraceId128.Should().Be(expectedTraceId); + result.TraceId.Should().Be(expectedTraceId.Lower); + result.SpanId.Should().Be(expectedSpanId); - spanContext.Should().NotBeNull(); - spanContext.TraceId128.Should().Be(expectedTraceId); - spanContext.TraceId.Should().Be(expectedTraceId.Lower); - spanContext.SpanId.Should().Be(expectedSpanId); + context.Baggage.Should().BeNull(); // Check the injection restoring the 128 bits traceId. var headersForInjection = new Mock(MockBehavior.Strict); @@ -294,6 +300,7 @@ public void Extract_InvalidLength() headers.Verify(h => h.GetValues("x-b3-sampled"), Times.Never); // extractor doesn't get this far result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } [Fact] @@ -314,6 +321,7 @@ public void Extract_InvalidFormat() headers.Verify(h => h.GetValues("x-b3-sampled"), Times.Never); // extractor doesn't get this far result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } [Fact] @@ -334,6 +342,7 @@ public void Extract_EmptyTraceId() headers.Verify(h => h.GetValues("x-b3-sampled"), Times.Never); // extractor doesn't get this far result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } [Fact] @@ -355,6 +364,7 @@ public void Extract_EmptySpanId() headers.Verify(h => h.GetValues("x-b3-sampled"), Times.Never); // extractor doesn't get this far result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } [Fact] @@ -375,6 +385,7 @@ public void Extract_InvalidTraceId() headers.Verify(h => h.GetValues("x-b3-sampled"), Times.Never()); // extractor doesn't get this far result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } [Fact] @@ -395,6 +406,7 @@ public void Extract_InvalidSpanIdLength() headers.Verify(h => h.GetValues("x-b3-sampled"), Times.Never); // extractor doesn't get this far result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } } } diff --git a/tracer/test/Datadog.Trace.Tests/Propagators/B3SingleHeaderPropagatorTests.cs b/tracer/test/Datadog.Trace.Tests/Propagators/B3SingleHeaderPropagatorTests.cs index b92babe6c1bb..5a21842149b9 100644 --- a/tracer/test/Datadog.Trace.Tests/Propagators/B3SingleHeaderPropagatorTests.cs +++ b/tracer/test/Datadog.Trace.Tests/Propagators/B3SingleHeaderPropagatorTests.cs @@ -149,6 +149,8 @@ public void Extract_IHeadersCollection(string header, ulong traceIdUpper, ulong SamplingPriority = samplingPriority, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Theory] @@ -182,6 +184,8 @@ public void Extract_CarrierAndDelegate(string header, ulong traceIdUpper, ulong SamplingPriority = samplingPriority, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -204,6 +208,8 @@ public void ExtractAndInject_PreserveOriginalTraceId() spanContext.TraceId.Should().Be(traceId.Lower); spanContext.SpanId.Should().Be(expectedSpanId); + result.Baggage.Should().BeNull(); + // Check the injection restoring the 128 bits traceId. var headersForInjection = new Mock(); headersForInjection.Setup(h => h.Set("b3", expectedTraceParent)); @@ -224,6 +230,7 @@ public void Extract_InvalidLength() headers.Verify(h => h.GetValues("b3"), Times.Once()); result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } [Fact] @@ -233,10 +240,11 @@ public void Extract_InvalidFormat() headers.Setup(h => h.GetValues("b3")) .Returns(new[] { "00000000075bcd15=000000003ade68b1=1" }); - var context = B3Propagator.Extract(headers.Object); + var result = B3Propagator.Extract(headers.Object); headers.Verify(h => h.GetValues("b3"), Times.Once()); - context.SpanContext.Should().BeNull(); + result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } [Fact] @@ -250,6 +258,7 @@ public void Extract_EmptyStrings() headers.Verify(h => h.GetValues("b3"), Times.Once()); result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } } } diff --git a/tracer/test/Datadog.Trace.Tests/Propagators/DatadogPropagatorTests.cs b/tracer/test/Datadog.Trace.Tests/Propagators/DatadogPropagatorTests.cs index 1b04ee22a1e4..7ed73419e622 100644 --- a/tracer/test/Datadog.Trace.Tests/Propagators/DatadogPropagatorTests.cs +++ b/tracer/test/Datadog.Trace.Tests/Propagators/DatadogPropagatorTests.cs @@ -232,6 +232,8 @@ public void Extract_IHeadersCollection() PropagatedTags = PropagatedTagsCollection, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -260,6 +262,8 @@ public void Extract_CarrierAndDelegate() PropagatedTags = PropagatedTagsCollection, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -296,6 +300,7 @@ public void Extract_EmptyHeadersReturnsNull() var result = Propagator.Extract(headers.Object); result.SpanContext.Should().BeNull(); + result.Baggage.Should().BeNull(); } [Fact] @@ -321,6 +326,8 @@ public void Extract_TraceIdOnly() PropagatedTags = EmptyPropagatedTags, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -340,10 +347,12 @@ public void Identity() var headers = new NameValueHeadersCollection(new NameValueCollection()); Propagator.Inject(new PropagationContext(spanContext, TestBaggage), headers); - var extractedContext = Propagator.Extract(headers); + var result = Propagator.Extract(headers); + + result.SpanContext.Should().NotBeSameAs(spanContext); + result.SpanContext.Should().BeEquivalentTo(spanContext); - extractedContext.SpanContext.Should().NotBeSameAs(spanContext); - extractedContext.SpanContext.Should().BeEquivalentTo(spanContext); + result.Baggage.Should().BeNull(); } [Theory] @@ -389,6 +398,8 @@ public void Extract_InvalidSpanId(string spanId) PropagatedTags = PropagatedTagsCollection, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Theory] @@ -427,6 +438,8 @@ public void Extract_InvalidSamplingPriority(string samplingPriority, int? expect PropagatedTags = PropagatedTagsCollection, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } private static Mock SetupMockHeadersCollection() diff --git a/tracer/test/Datadog.Trace.Tests/Propagators/MultiSpanContextPropagatorTests.cs b/tracer/test/Datadog.Trace.Tests/Propagators/MultiSpanContextPropagatorTests.cs index 112bb363c2eb..2c5118b21df9 100644 --- a/tracer/test/Datadog.Trace.Tests/Propagators/MultiSpanContextPropagatorTests.cs +++ b/tracer/test/Datadog.Trace.Tests/Propagators/MultiSpanContextPropagatorTests.cs @@ -348,6 +348,8 @@ public void Extract_B3_IHeadersCollection() SamplingPriority = SamplingPriorityValues.AutoKeep, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -378,6 +380,8 @@ public void Extract_B3SingleHeader_IHeadersCollection() SamplingPriority = SamplingPriorityValues.AutoKeep, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -411,6 +415,8 @@ public void Extract_W3C_IHeadersCollection_traceparent() IsRemote = true, LastParentId = ZeroLastParentId, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -450,6 +456,8 @@ public void Extract_W3C_IHeadersCollection_traceparent_tracestate() IsRemote = true, LastParentId = ZeroLastParentId, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -493,6 +501,8 @@ public void Extract_Datadog_IHeadersCollection() PropagatedTags = PropagatedTagsCollection, IsRemote = true, }); + + result.Baggage.Should().BeNull(); } [Fact] @@ -516,6 +526,8 @@ public void ExtractAndInject_W3C_PreserveOriginalTraceId() result.TraceId.Should().Be(expectedTraceId.Lower); result.SpanId.Should().Be(expectedSpanId); + context.Baggage.Should().BeNull(); + // Check the injection restoring the 128 bits traceId. var headersForInjection = new Mock(); headersForInjection.Setup(h => h.Set("traceparent", expectedTraceParent)); @@ -550,6 +562,8 @@ public void ExtractAndInject_B3_PreserveOriginalTraceId() result.TraceId.Should().Be(expectedTraceId.Lower); result.SpanId.Should().Be(expectedSpanId); + context.Baggage.Should().BeNull(); + // Check the injection restoring the 128 bits traceId. var headersForInjection = new Mock(); headersForInjection.Setup(h => h.Set("x-b3-traceid", traceId)); @@ -582,6 +596,8 @@ public void ExtractAndInject_B3SingleHeader_PreserveOriginalTraceId() result.TraceId128.Should().Be(expectedTraceId); result.SpanId.Should().Be(expectedSpanId); + context.Baggage.Should().BeNull(); + // Check the injection restoring the 128 bits traceId. var headersForInjection = new Mock(); headersForInjection.Setup(h => h.Set("b3", expectedTraceParent)); diff --git a/tracer/test/Datadog.Trace.Tests/Propagators/W3CTraceContextPropagatorTests.cs b/tracer/test/Datadog.Trace.Tests/Propagators/W3CTraceContextPropagatorTests.cs index 9e7b2f13aa69..9ec73cd5dfe3 100644 --- a/tracer/test/Datadog.Trace.Tests/Propagators/W3CTraceContextPropagatorTests.cs +++ b/tracer/test/Datadog.Trace.Tests/Propagators/W3CTraceContextPropagatorTests.cs @@ -459,6 +459,8 @@ public void Extract_CarrierAndDelegate() ParentId = null, LastParentId = ZeroLastParentId }); + + result.Baggage.Should().BeNull(); } [Fact]