Skip to content

Make DistributedContextPropagator opt-in (keep OTel propagation backwards compatible until v11)#7825

Merged
tmasternak merged 9 commits into
otelfrom
otel-propagator-opt-in
Jun 19, 2026
Merged

Make DistributedContextPropagator opt-in (keep OTel propagation backwards compatible until v11)#7825
tmasternak merged 9 commits into
otelfrom
otel-propagator-opt-in

Conversation

@ramonsmits

@ramonsmits ramonsmits commented Jun 17, 2026

Copy link
Copy Markdown
Member

Stacks on #7798 (otel). Keeps the new DistributedContextPropagator-based OpenTelemetry context propagation opt-in so 10.3 stays backwards compatible, with the new behavior becoming the default in v11.

Why

otel (commit bba80f7) replaced the hand-written baggage propagator with System.Diagnostics.DistributedContextPropagator. The HTTP header names are unchanged (traceparent/tracestate/baggage were already W3C), but the baggage value encoding changes:

Legacy (≤10.2) New (DistributedContextPropagator)
Wire format key1=value1,key2=value2 key1 = value1, key2 = value2 (W3C OWS)
Value encoding Uri.EscapeDataString whole value W3C baggage encoding
Value whitespace preserved (percent-encoded) trimmed

ContextPropagationIncompatibilityTests documents the breakage: new→legacy gains a leading space, and new round-trips strip value whitespace. That's breaking on rolling upgrades, so it can't ship default-on in a minor.

What

  • Default = legacy (backwards compatible). New propagator is opt-in via AppContext switch NServiceBus.Core.OpenTelemetry.UseDistributedContextPropagator, mirroring the existing AppContextSwitches.UseV2DeterministicGuid / [PreObsolete] pattern (flip default in v11, remove the switch + legacy code in v11).
  • All temporary code in obsolete_v11.cs — the switch plumbing plus a byte-for-byte revert of the pre-10.3 propagator. v11 cleanup = delete that one file + remove the two if (!ObsoleteV11.UseDistributedContextPropagator) delegation blocks in ContextPropagation.cs.
  • ContextPropagation.cs keeps the new DistributedContextPropagator implementation as the permanent/future path.
  • Span naming (UseMessageDestinationInSpanNames via the public Tracing() API) is already opt-in/non-breaking — left untouched.

Enabling the switch:

AppContext.SetSwitch("NServiceBus.Core.OpenTelemetry.UseDistributedContextPropagator", true);
// or <RuntimeHostConfigurationOption Include="NServiceBus.Core.OpenTelemetry.UseDistributedContextPropagator" Value="true" />
// or env (.NET 9+): DOTNET_NServiceBus_Core_OpenTelemetry_UseDistributedContextPropagator=true

Comment thread src/NServiceBus.Core/OpenTelemetry/Tracing/obsolete_v11.cs Outdated
ramonsmits and others added 9 commits June 19, 2026 13:55
The switch to System.Diagnostics.DistributedContextPropagator changes the
OpenTelemetry baggage wire format (W3C OWS encoding + whitespace trimming),
which is breaking on rolling upgrades. Keep the legacy percent-encoded
propagator as the default and gate the new propagator behind the
NServiceBus.Core.OpenTelemetry.UseDistributedContextPropagator AppContext
switch (default in v11).

All temporary code (switch plumbing + legacy propagator) lives in
obsolete_v11.cs so v11 cleanup is a single file deletion plus removing the two
delegation blocks in ContextPropagation.cs. Follows the existing
AppContextSwitches.UseV2DeterministicGuid / PreObsolete pattern.

- ContextPropagation: delegate to the legacy propagator unless the switch is on
- obsolete_v11.cs: switch + byte-for-byte revert of the pre-10.3 propagator
- Tests asserting the new W3C format enable the switch per-fixture
- New ContextPropagationDefaultBehaviorTests locks in legacy default behavior
- Acceptance baggage assertion reverted to the legacy default wire format

Span naming (UseMessageDestinationInSpanNames) is already opt-in and unchanged.
@tmasternak tmasternak force-pushed the otel-propagator-opt-in branch from 5ca5b34 to f2b6066 Compare June 19, 2026 11:56
@tmasternak tmasternak marked this pull request as ready for review June 19, 2026 12:05
@tmasternak tmasternak merged commit a33484e into otel Jun 19, 2026
4 checks passed
@tmasternak tmasternak deleted the otel-propagator-opt-in branch June 19, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants