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

optimize resource detection #6222

Conversation

zeitlinger
Copy link
Member

@zeitlinger zeitlinger commented Feb 12, 2024

optimize resource detection by skipping providers that would add no new keys

Most of the functionality is already working with the following pattern: give the lower priority detector a higher order, so that it runs later an can check if it should be skipped

However, the environment resource provider runs last - so if the user adds the service name using service.name - the jar service name provider would still be run in vain.

@zeitlinger zeitlinger force-pushed the optimized-resource-detection branch from 2ba1bb0 to a8b30ea Compare February 13, 2024 14:04
Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (48d41d3) 91.05% compared to head (a8b30ea) 91.05%.

Files Patch % Lines
.../java/io/opentelemetry/sdk/resources/Resource.java 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #6222      +/-   ##
============================================
- Coverage     91.05%   91.05%   -0.01%     
+ Complexity     5687     5685       -2     
============================================
  Files           621      622       +1     
  Lines         16642    16660      +18     
  Branches       1703     1706       +3     
============================================
+ Hits          15153    15169      +16     
  Misses          998      998              
- Partials        491      493       +2     

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

@jack-berg
Copy link
Member

so if the user adds the service name using service.name - the jar service name provider would still be run in vain.

Can the jar service name provider check for the presence of service.name in config properties and achieve the same affect?

@zeitlinger
Copy link
Member Author

so if the user adds the service name using service.name - the jar service name provider would still be run in vain.

Can the jar service name provider check for the presence of service.name in config properties and achieve the same affect?

After re-reading the shouldApply - yes, this will work. I didn't realize the trick to look both into the "existing" and "config" parameters.
So I guess this PR is making it easier to get resource providers right.

@jack-berg
Copy link
Member

So I guess this PR is making it easier to get resource providers right.

Maybe, but I'd argue that its making them more confusing. The behavior of ResourceProvider#supportedKeys() is not intuitive: If all of supportedKeys() have been previously provided, skip the resource provider. It interacts with the priority of the resource provider in an unexpected way. An implementer would think they're just providing the set of attribute keys for optimization, but in doing so end up accidentally having their attributes ignored when they were supposed have been higher priority.

@zeitlinger
Copy link
Member Author

would think they're just providing the set of attribute keys for optimization, but in doing so end up accidentally having their attributes ignored when they were supposed have been higher priority.

that was not the idea - not providing supportedKeys should only result in some wasted CPU cycles.

@zeitlinger
Copy link
Member Author

Thinking about it, an abstract superclass can probably achieve a similar level of disability for authors.

@zeitlinger
Copy link
Member Author

Thinking about it, an abstract superclass can probably achieve a similar level of disability for authors.

I tried this approach out: open-telemetry/opentelemetry-java-instrumentation#10540

@zeitlinger
Copy link
Member Author

Closing in favor of #6250

@zeitlinger zeitlinger closed this Feb 26, 2024
@zeitlinger zeitlinger deleted the optimized-resource-detection branch February 26, 2024 11:23
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.

2 participants