Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tracing] Improve unit tests to assert baggage values when using multiple propagators #6471

Merged
merged 10 commits into from
Jan 2, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static MultiSpanContextPropagatorTests()
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.B3MultipleHeaders,
ContextPropagationHeaderStyle.B3SingleHeader,
ContextPropagationHeaderStyle.W3CBaggage,
};

Propagator = SpanContextPropagatorFactory.GetSpanContextPropagator(names, names, propagationExtractFirst: true);
Expand All @@ -62,11 +63,13 @@ static MultiSpanContextPropagatorTests()
{
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.W3CBaggage,
},
new[]
{
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.W3CBaggage,
},
propagationExtractFirst: true);

Expand All @@ -76,11 +79,13 @@ static MultiSpanContextPropagatorTests()
{
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.W3CBaggage,
},
new[]
{
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.W3CBaggage,
},
propagationExtractFirst: true);

Expand All @@ -90,11 +95,13 @@ static MultiSpanContextPropagatorTests()
{
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.W3CBaggage,
},
new[]
{
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.W3CBaggage,
},
propagationExtractFirst: false);

Expand All @@ -104,11 +111,13 @@ static MultiSpanContextPropagatorTests()
{
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.W3CBaggage,
},
new[]
{
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.W3CBaggage,
},
false);

Expand All @@ -118,11 +127,13 @@ static MultiSpanContextPropagatorTests()
{
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.B3MultipleHeaders,
ContextPropagationHeaderStyle.W3CBaggage,
},
new[]
{
ContextPropagationHeaderStyle.Datadog,
ContextPropagationHeaderStyle.B3MultipleHeaders,
ContextPropagationHeaderStyle.W3CBaggage,
},
propagationExtractFirst: false);

Expand All @@ -132,11 +143,13 @@ static MultiSpanContextPropagatorTests()
{
ContextPropagationHeaderStyle.B3MultipleHeaders,
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.W3CBaggage,
},
new[]
{
ContextPropagationHeaderStyle.B3MultipleHeaders,
ContextPropagationHeaderStyle.W3CTraceContext,
ContextPropagationHeaderStyle.W3CBaggage,
},
propagationExtractFirst: false);

Expand Down Expand Up @@ -181,6 +194,8 @@ public void Inject_All_IHeadersCollection()
headers.Verify(h => h.Set("traceparent", "00-000000000000000000000000075bcd15-000000003ade68b1-01"), Times.Once());
headers.Verify(h => h.Set("tracestate", "dd=s:2;o:rum;p:000000003ade68b1;t.key1:value1;t.key2:value2"), Times.Once());

headers.Verify(h => h.Set("baggage", "key1=value1,key2=value2"), Times.Once());

headers.VerifyNoOtherCalls();
}

Expand Down Expand Up @@ -223,6 +238,8 @@ public void Inject_All_IHeadersCollection_128Bit_TraceId()
headers.Verify(h => h.Set("traceparent", "00-1234567890abcdef1122334455667788-0000000000000001-01"), Times.Once());
headers.Verify(h => h.Set("tracestate", "dd=s:2;o:rum;p:0000000000000001;t.key1:value1;t.key2:value2"), Times.Once());

headers.Verify(h => h.Set("baggage", "key1=value1,key2=value2"), Times.Once());

headers.VerifyNoOtherCalls();
}

Expand Down Expand Up @@ -264,6 +281,7 @@ public void Inject_All_CarrierAndDelegate()
headers.Verify(h => h.Set("traceparent", "00-000000000000000000000000075bcd15-000000003ade68b1-01"), Times.Once());
headers.Verify(h => h.Set("tracestate", "dd=s:2;o:rum;p:000000003ade68b1;t.key1:value1;t.key2:value2"), Times.Once());

headers.Verify(h => h.Set("baggage", "key1=value1,key2=value2"), Times.Once());
headers.VerifyNoOtherCalls();
}

Expand Down Expand Up @@ -309,6 +327,8 @@ public void Inject_All_CarrierAndDelegate_128Bit_TraceId()
headers.Verify(h => h.Set("traceparent", "00-1234567890abcdef1122334455667788-0000000000000001-01"), Times.Once());
headers.Verify(h => h.Set("tracestate", "dd=s:2;o:rum;p:0000000000000001;t.key1:value1;t.key2:value2"), Times.Once());

headers.Verify(h => h.Set("baggage", "key1=value1,key2=value2"), Times.Once());

headers.VerifyNoOtherCalls();
}

Expand Down Expand Up @@ -420,7 +440,7 @@ public void Extract_W3C_IHeadersCollection_traceparent()
[Fact]
public void Extract_W3C_IHeadersCollection_traceparent_tracestate()
{
var headers = new Mock<IHeadersCollection>(MockBehavior.Strict);
var headers = new Mock<IHeadersCollection>();

headers.Setup(h => h.GetValues("traceparent"))
.Returns(new[] { "00-000000000000000000000000075bcd15-000000003ade68b1-01" });
Expand All @@ -432,7 +452,7 @@ public void Extract_W3C_IHeadersCollection_traceparent_tracestate()

headers.Verify(h => h.GetValues("traceparent"), Times.Once());
headers.Verify(h => h.GetValues("tracestate"), Times.Once());
headers.VerifyNoOtherCalls();
headers.Verify(h => h.GetValues("baggage"), Times.Once());

result.SpanContext
.Should()
Expand Down Expand Up @@ -841,6 +861,8 @@ public void TraceContextPrecedence_ConsistentBehaviour_WithDifferentTraceIds(boo
.Returns(new[] { "00-11111111111111110000000000000005-000000003ade68b1-01" });
headers.Setup(h => h.GetValues("tracestate"))
.Returns(new[] { "foo=1" });
headers.Setup(h => h.GetValues("baggage"))
.Returns(new[] { "usr=customer" });
headers.Setup(h => h.GetValues("x-datadog-trace-id"))
.Returns(new[] { "3541" });
headers.Setup(h => h.GetValues("x-datadog-parent-id"))
Expand Down Expand Up @@ -881,6 +903,8 @@ public void TraceContextPrecedence_ConsistentBehaviour_WithDifferentTraceIds(boo
IsRemote = true,
LastParentId = w3CHeaderFirst ? ZeroLastParentId : null,
});

result.Baggage.Should().BeEquivalentTo(new Baggage([new KeyValuePair<string, string>("usr", "customer")]));
}

[Theory]
Expand Down
Loading