Fix bug preventing accurate reporting of dropped attribute count#7142
Fix bug preventing accurate reporting of dropped attribute count#7142jack-berg merged 2 commits intoopen-telemetry:mainfrom
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.
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.
| attributes.put(EXCEPTION_STACKTRACE, stackTrace); | ||
| } | ||
|
|
||
| additionalAttributes.forEach(attributes::put); |
There was a problem hiding this comment.
This was the problematic call which was bypassing attribute limits.
trask
left a comment
There was a problem hiding this comment.
(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