fix: enforce last-value-wins in AttributesMap for duplicate keys of different types#8420
Open
kyyril wants to merge 2 commits into
Open
fix: enforce last-value-wins in AttributesMap for duplicate keys of different types#8420kyyril wants to merge 2 commits into
kyyril wants to merge 2 commits into
Conversation
…ifferent types Fixes open-telemetry#7897
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8420 +/- ##
============================================
- Coverage 91.14% 91.14% -0.01%
- Complexity 7761 7766 +5
============================================
Files 881 881
Lines 23409 23421 +12
Branches 2331 2334 +3
============================================
+ Hits 21337 21346 +9
- Misses 1377 1378 +1
- Partials 695 697 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
psx95
reviewed
May 21, 2026
Contributor
psx95
left a comment
There was a problem hiding this comment.
Based on the the previous discussion around this issue in this comment, I would recommend running benchmark tests to ensure that this implementation is at least as performant as existing code.
Additionally, it looks like this issue warranted a larger change about replacing extends HashMap with a custom implementation that uses a custom map that stores attributes by raw string key.
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.
Resolves #7897
Changes
Fixes inconsistent last-value-wins behavior in
AttributesMap.Previously,
AttributesMapstored attributes directly in aHashMap<AttributeKey<?>, Object>. SinceAttributeKeyequals/hashCode includes the type, adding two attributes with the same raw string name but different types would result in both being kept, violating the OpenTelemetry specification requirement that setting the same key SHOULD overwrite the existing value.This PR modifies
AttributesMap.putto search for any existing key with the same string representation and remove it before inserting the new key/value. It also overridesputAllto ensure all entries are processed throughputto correctly deduplicate and respect the capacity limits.Checklist
AttributesMapTest