-
Notifications
You must be signed in to change notification settings - Fork 900
Fix bug preventing accurate reporting of dropped attribute count #7142
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
Fix bug preventing accurate reporting of dropped attribute count #7142
Conversation
@@ -47,10 +46,10 @@ public static AttributesMap create(long capacity, int lengthLimit) { | |||
/** Add the attribute key value pair, applying capacity and length limits. */ | |||
public <T> void put(AttributeKey<T> key, T value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because AttributeMap extends HashMap
, a caller was accidentally bypassing this method and calling Map#put(T, V)
directly, which was preventing the application of attribute limits.
We protect against this by delegating to HashMap
instead of extending.
@@ -495,7 +496,10 @@ public ReadWriteSpan recordException(Throwable exception, Attributes additionalA | |||
attributes.put(EXCEPTION_STACKTRACE, stackTrace); | |||
} | |||
|
|||
additionalAttributes.forEach(attributes::put); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the problematic call which was bypassing attribute limits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I suspect extending may have been intentional as a performance optimization to avoid the 4 bytes allocated to the delegate field)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7142 +/- ##
============================================
+ Coverage 89.85% 89.87% +0.02%
- Complexity 6614 6624 +10
============================================
Files 740 740
Lines 19991 20007 +16
Branches 1964 1968 +4
============================================
+ Hits 17962 17982 +20
+ Misses 1439 1438 -1
+ Partials 590 587 -3 ☔ View full report in Codecov by Sentry. |
The thought crossed my mind. We could keep extending, and override the implementation of all unsupported map methods with versions that throw exceptions. |
This doesn't really work. A bunch of stuff breaks when you override the base map methods with versions that throw. You very quickly get into territory of asking "why is this even a map", and the only answer is "performance". The choices are:
|
I pushed a commit which reverts to extending HashMap. I added some javadoc calling attention to the potential pitfalls, and adjusted the Given that its an internal class and changing to a delegation model would increase memory allocation, continuing to extend HashMap and fixing all internal callers seems to be the conservative approach. |
Fixes #7135