[OpenTelemetry] Handle duplicate sampler attributes - #7558
Merged
martincostello merged 2 commits intoJul 29, 2026
Merged
martincostello merged 2 commits into
martincostello merged 2 commits into
Conversation
Pull request dashboard statusMerged · refreshed 2026-07-29 06:33 UTC Status above doesn't look right?
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7558 +/- ##
==========================================
- Coverage 90.43% 90.39% -0.04%
==========================================
Files 290 290
Lines 15989 15989
==========================================
- Hits 14459 14453 -6
- Misses 1530 1536 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
|
martincostello
approved these changes
Jul 29, 2026
This was referenced Aug 21, 2026
Closed
This was referenced Sep 18, 2026
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.
Fixes Azure/azure-sdk-for-net#58948
Design discussion issue #
Changes
Replaced
ActivityTagsCollection.Addwith indexer assignment when applying sampler attributes during Activity creation.This prevents Activity creation from throwing when multiple matching
TracerProviderinstances return an attribute with the same key. The behavior now matches the existing legacy Activity path, which applies sampler attributes usingActivity.SetTagreplacement semantics.When multiple samplers return different values for the same key, the value from the last invoked listener is retained.
Added a regression test with two providers that return the same attribute key.
Motivation
OpenTelemetry supports multiple
TracerProviderinstances, and .NETActivitySourceinvokes every matchingActivityListenerwhile creating one Activity. These listeners contribute to the Activity's shared sampling-tag collection.Previously, the second provider failed while adding a duplicate key:
This exception prevents Activity creation and, in ASP.NET Core TestHost, may present as a request timeout.
Validation
Before the fix, the new regression test failed in
TracerProviderSdk.ComputeActivitySamplingResult.After the fix:
TracerProviderSdkDuplicateSamplerAttributesUseLastValuepassed.TracerProviderSdkTestsclass passed: 67 tests.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes[ ] Changes in public API reviewed (if applicable)