Apply incoming trace state and baggage only with NServiceBus trace context - #7954
Merged
Merged
Conversation
ramonsmits
force-pushed
the
otel-ambient-baggage
branch
from
October 1, 2026 20:19
2d8b15b to
28a4ec7
Compare
ramonsmits
marked this pull request as ready for review
October 2, 2026 13:08
irinascurtu
approved these changes
Oct 5, 2026
This was referenced Oct 5, 2026
Merged
…ontext Trace state and baggage headers are only meaningful together with a trace parent. Apply them only when the message has NServiceBus trace context. Without it, NServiceBus has nothing to propagate. The incoming span then inherits what an ambient activity has through the parent chain. Baggage from the headers is always applied, also when a transport SDK receive span is the parent. None of the supported SDKs (Azure Service Bus, RabbitMQ, SQS) propagate baggage yet. For when they do, a key the adopted parent already has is skipped. Activity.Baggage reads through the parent chain, so adding it again would double the baggage on every hop. Trace state from the headers is not applied when the message starts a new trace. It describes the trace of the sender, which the new trace is detached from. Start the incoming activity before the headers are read. Activity.Start() sets Activity.Parent, so the skip can read the parent chain of the runtime instead of tracking the adopted parent separately. The id format is still set to W3C before the start. Split ContextPropagation.PropagateContextFromHeaders into a trace-state part and a baggage part on both propagator paths. The combined method stays for callers that need both.
The switch selects the parent Activity of the incoming span. Rename it and update all references, tests and comments to the Activity terminology.
ramonsmits
force-pushed
the
otel-ambient-baggage
branch
from
October 5, 2026 14:12
30798ae to
86cc2b3
Compare
Records why NServiceBus applies trace state and baggage from the message headers on receive only when its own trace context is present, also under an ambient transport SDK span, and why keys the adopted parent already has are skipped. Captures the verified SDK behavior and the Activity.Parent mechanics the decision rests on, and the alternatives that were rejected.
ramonsmits
force-pushed
the
otel-ambient-baggage
branch
from
October 5, 2026 14:39
86cc2b3 to
522c367
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
NServiceBus now propagates
tracestateandbaggagefrom the message headers only when the message has NServiceBus trace context. NServiceBus trace context is aNServiceBus.TraceParentortraceparentheader. Without it, the incoming span adoptsActivity.Currentas parent. The span then inherits the trace state and baggage of that activity.Changes
NServiceBus.StartNewTrace). The trace state describes the trace of the sender. The new trace has no relation to that trace.ActivityFactorynow starts the incoming activity before it reads the headers.Activity.Start()setsActivity.Parent, so the skip can read the parent chain of the runtime.ActivityFactorystill sets the W3C id format before the start.ContextPropagation.PropagateContextFromHeadersis now two methods: one for trace state and one for baggage. Each branch calls the method it needs.Rationale
The architecture decision record (ADR) records the verified SDK behavior and the
Activity.Parentbehavior. This change depends on both:docs/decisions/2026-10-01-receive-side-trace-state-and-baggage-propagation.md.Docs