-
Notifications
You must be signed in to change notification settings - Fork 648
Make DistributedContextPropagator opt-in (keep OTel propagation backwards compatible until v11) #7825
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
Merged
Merged
Make DistributedContextPropagator opt-in (keep OTel propagation backwards compatible until v11) #7825
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
78237b6
✨ Make DistributedContextPropagator opt-in via AppContext switch
ramonsmits 7063661
Refactor: Replace `ObsoleteV11` with `LegacyContextPropagation`
ramonsmits fefa717
Add test to verify null baggage value does not throw in legacy propag…
ramonsmits 910b295
Added comments about preserve legacy baggage handling behavior when e…
ramonsmits 87bc6d7
Add test to verify that we are preserving whitespace in legacy propag…
ramonsmits 17dc6d4
add comments to clarify intent behind legacy propagator handling
tmasternak 869de24
update ContextPropagationCompatibilityTests to use correct LegacyCont…
tmasternak f144b26
rename ContextPropagationTests to LegacyContextPropagationTests and r…
tmasternak f2b6066
allow changing the propagator implementation at runtime
tmasternak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
72 changes: 72 additions & 0 deletions
72
src/NServiceBus.Core.Tests/OpenTelemetry/ContextPropagationDefaultBehaviorTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| namespace NServiceBus.Core.Tests.OpenTelemetry; | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using Extensibility; | ||
| using NUnit.Framework; | ||
|
|
||
| [TestFixture] | ||
| public class ContextPropagationDefaultBehaviorTests | ||
| { | ||
| // Without the opt-in switch, the endpoint default must remain the backwards-compatible | ||
| // legacy propagator (percent-encoded, comma-separated, whitespace preserved). | ||
| [SetUp] | ||
| public void EnsureDefault() | ||
| { | ||
| AppContext.SetSwitch(LegacyContextPropagation.UseDistributedContextPropagatorSwitchName, false); | ||
| LegacyContextPropagation.ResetUseDistributedContextPropagator(); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Default_uses_legacy_percent_encoded_baggage_format() | ||
| { | ||
| using var activity = new Activity(ActivityNames.OutgoingMessageActivityName); | ||
| activity.SetIdFormat(ActivityIdFormat.W3C); | ||
| activity.Start(); | ||
| activity.AddBaggage("serverNode", "DF 28"); | ||
|
|
||
| var headers = new Dictionary<string, string>(); | ||
| ContextPropagation.PropagateContextToHeaders(activity, headers, new ContextBag()); | ||
|
|
||
| Assert.That(headers[Headers.DiagnosticsBaggage], Is.EqualTo("serverNode=DF%2028")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Default_does_not_throw_when_baggage_value_is_null() | ||
| { | ||
| // Reproduces https://github.com/Particular/NServiceBus/issues/6983 on the legacy propagator. | ||
| // A null baggage value must not make the legacy propagator call Uri.EscapeDataString(null). | ||
| // Calls LegacyContextPropagation directly so the assertion is independent of the AppContext switch. | ||
| using var activity = new Activity(ActivityNames.OutgoingMessageActivityName); | ||
| activity.SetIdFormat(ActivityIdFormat.W3C); | ||
| activity.Start(); | ||
| activity.AddBaggage("test", null); | ||
|
|
||
| var headers = new Dictionary<string, string>(); | ||
|
|
||
| Assert.DoesNotThrow(() => LegacyContextPropagation.PropagateContextToHeaders(activity, headers, new ContextBag())); | ||
| Assert.That(headers[Headers.DiagnosticsBaggage], Is.EqualTo("test=")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Default_round_trip_preserves_value_whitespace() | ||
| { | ||
| using var outgoing = new Activity(ActivityNames.OutgoingMessageActivityName); | ||
| outgoing.SetIdFormat(ActivityIdFormat.W3C); | ||
| outgoing.Start(); | ||
| outgoing.AddBaggage("key1", " leading-and-trailing "); | ||
|
|
||
| var headers = new Dictionary<string, string>(); | ||
| ContextPropagation.PropagateContextToHeaders(outgoing, headers, new ContextBag()); | ||
|
|
||
| using var incoming = new Activity(ActivityNames.IncomingMessageActivityName); | ||
| incoming.SetIdFormat(ActivityIdFormat.W3C); | ||
| incoming.Start(); | ||
| ContextPropagation.PropagateContextFromHeaders(incoming, headers); | ||
|
|
||
| // Legacy propagation preserves leading/trailing whitespace via percent-encoding; | ||
| // the DistributedContextPropagator (opt-in) would trim it. | ||
| Assert.That(incoming.GetBaggageItem("key1"), Is.EqualTo(" leading-and-trailing ")); | ||
| } | ||
| } |
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
87 changes: 0 additions & 87 deletions
87
src/NServiceBus.Core.Tests/OpenTelemetry/LegacyContextPropagator.cs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.