Skip to content

Commit

Permalink
assert that baggage is null in the trace context extraction tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspimentel committed Oct 21, 2024
1 parent c2e67f9 commit bf56863
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public void Extract_IHeadersCollection(
SamplingPriority = samplingPriority,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Theory]
Expand Down Expand Up @@ -234,6 +236,8 @@ public void Extract_CarrierAndDelegate(
SamplingPriority = samplingPriority,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand All @@ -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<IHeadersCollection>(MockBehavior.Strict);
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public void Extract_IHeadersCollection(string header, ulong traceIdUpper, ulong
SamplingPriority = samplingPriority,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Theory]
Expand Down Expand Up @@ -182,6 +184,8 @@ public void Extract_CarrierAndDelegate(string header, ulong traceIdUpper, ulong
SamplingPriority = samplingPriority,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand All @@ -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<IHeadersCollection>();
headersForInjection.Setup(h => h.Set("b3", expectedTraceParent));
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -250,6 +258,7 @@ public void Extract_EmptyStrings()

headers.Verify(h => h.GetValues("b3"), Times.Once());
result.SpanContext.Should().BeNull();
result.Baggage.Should().BeNull();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ public void Extract_IHeadersCollection()
PropagatedTags = PropagatedTagsCollection,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand Down Expand Up @@ -260,6 +262,8 @@ public void Extract_CarrierAndDelegate()
PropagatedTags = PropagatedTagsCollection,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand Down Expand Up @@ -296,6 +300,7 @@ public void Extract_EmptyHeadersReturnsNull()
var result = Propagator.Extract(headers.Object);

result.SpanContext.Should().BeNull();
result.Baggage.Should().BeNull();
}

[Fact]
Expand All @@ -321,6 +326,8 @@ public void Extract_TraceIdOnly()
PropagatedTags = EmptyPropagatedTags,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand All @@ -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]
Expand Down Expand Up @@ -389,6 +398,8 @@ public void Extract_InvalidSpanId(string spanId)
PropagatedTags = PropagatedTagsCollection,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Theory]
Expand Down Expand Up @@ -427,6 +438,8 @@ public void Extract_InvalidSamplingPriority(string samplingPriority, int? expect
PropagatedTags = PropagatedTagsCollection,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

private static Mock<IHeadersCollection> SetupMockHeadersCollection()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ public void Extract_B3_IHeadersCollection()
SamplingPriority = SamplingPriorityValues.AutoKeep,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand Down Expand Up @@ -378,6 +380,8 @@ public void Extract_B3SingleHeader_IHeadersCollection()
SamplingPriority = SamplingPriorityValues.AutoKeep,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand Down Expand Up @@ -411,6 +415,8 @@ public void Extract_W3C_IHeadersCollection_traceparent()
IsRemote = true,
LastParentId = ZeroLastParentId,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand Down Expand Up @@ -450,6 +456,8 @@ public void Extract_W3C_IHeadersCollection_traceparent_tracestate()
IsRemote = true,
LastParentId = ZeroLastParentId,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand Down Expand Up @@ -493,6 +501,8 @@ public void Extract_Datadog_IHeadersCollection()
PropagatedTags = PropagatedTagsCollection,
IsRemote = true,
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand All @@ -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<IHeadersCollection>();
headersForInjection.Setup(h => h.Set("traceparent", expectedTraceParent));
Expand Down Expand Up @@ -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<IHeadersCollection>();
headersForInjection.Setup(h => h.Set("x-b3-traceid", traceId));
Expand Down Expand Up @@ -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<IHeadersCollection>();
headersForInjection.Setup(h => h.Set("b3", expectedTraceParent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ public void Extract_CarrierAndDelegate()
ParentId = null,
LastParentId = ZeroLastParentId
});

result.Baggage.Should().BeNull();
}

[Fact]
Expand Down

0 comments on commit bf56863

Please sign in to comment.