Skip to content
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

Avoid allocations when advice doesn't remove any attributes #6629

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

jack-berg
Copy link
Member

Related to #6601.

Copy link

codecov bot commented Aug 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.22%. Comparing base (5be177d) to head (e41a9df).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6629      +/-   ##
============================================
+ Coverage     90.19%   90.22%   +0.02%     
- Complexity     6281     6286       +5     
============================================
  Files           697      697              
  Lines         18903    18911       +8     
  Branches       1852     1852              
============================================
+ Hits          17050    17062      +12     
+ Misses         1281     1280       -1     
+ Partials        572      569       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

AttributesBuilder builder = incoming.toBuilder();
builder.removeIf(key -> !attributeKeys.contains(key));
return builder.build();
}

/** Returns true if {@code attributes} has keys not contained in {@link #attributeKeys}. */
private boolean hasExtraKeys(Attributes attributes) {
boolean[] result = {false};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This little trick allows you to update state from inside a lambda without an atomic variable.

@jack-berg jack-berg merged commit d16ba00 into open-telemetry:main Aug 8, 2024
18 checks passed
breedx-splk pushed a commit to breedx-splk/opentelemetry-java that referenced this pull request Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants