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

Add ResourceProvider SPI to allow for custom Resources #1548

Merged
merged 3 commits into from
Aug 18, 2020

Conversation

iNikem
Copy link
Contributor

@iNikem iNikem commented Aug 18, 2020

Partially addresses #1454

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Looks nice, thanks!

@@ -74,6 +75,14 @@ private static String readVersion() {
return properties.getProperty("sdk.version");
}

private static Resource readResourceFromProviders() {
Resource result = Resource.EMPTY;
for (ResourceProvider resourceProvider : ServiceLoader.load(ResourceProvider.class)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably add a property with a CSV list of implementation class name to exclude to allow users to disable resources they don't want to include automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cannot the same be achieved via controlling application classpath?

Copy link
Contributor

Choose a reason for hiding this comment

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

If every resource provider is in a separate artifact I think so but will that be the case? Not sure - but I sort of figured that SDK will have one extension artifact with a few providers so disabling one of them only by classpath manipulation could be tough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only use-case for this that I currently know of is for auto-instrumentation to provide telemetry.auto.version. Which, btw, I wouldn't want end-users to disable :)

Copy link
Contributor

Choose a reason for hiding this comment

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

There are many resources we haven't implemented in Java yet, like docker container ID or process. I figure they should also be implemented with this SPI

open-telemetry/opentelemetry-specification#811 (comment)

We'll probably have a lot of these providers for full data coverage but for startup time or possible privacy reasons presumably they should be disablable and classpath probably won't be enough. In agent we would probably bundle everything and need a property anyways I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, fair enough.

  • Should I do this in this very same PR?
  • Should new config property go to TraceConfig?

Copy link
Contributor

Choose a reason for hiding this comment

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

Think follow-up PR is fine.

Probably not TraceConfig - we'd have to stop using the static instance, and I guess this doesn't need to be programmatic (can just programmatically set Resource instead) so it's only for control from command line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added #1551

@codecov
Copy link

codecov bot commented Aug 18, 2020

Codecov Report

Merging #1548 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1548      +/-   ##
============================================
+ Coverage     91.45%   91.47%   +0.01%     
- Complexity      960      964       +4     
============================================
  Files           116      117       +1     
  Lines          3440     3448       +8     
  Branches        281      282       +1     
============================================
+ Hits           3146     3154       +8     
  Misses          205      205              
  Partials         89       89              
Impacted Files Coverage Δ Complexity Δ
.../java/io/opentelemetry/sdk/resources/Resource.java 92.30% <100.00%> (+1.00%) 14.00 <2.00> (+2.00)
.../opentelemetry/sdk/resources/ResourceProvider.java 100.00% <100.00%> (ø) 2.00 <2.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a08dd9f...cfd907f. Read the comment docs.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Thanks! Looking forward to add more providers :)

@@ -74,6 +75,14 @@ private static String readVersion() {
return properties.getProperty("sdk.version");
}

private static Resource readResourceFromProviders() {
Resource result = Resource.EMPTY;
for (ResourceProvider resourceProvider : ServiceLoader.load(ResourceProvider.class)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Think follow-up PR is fine.

Probably not TraceConfig - we'd have to stop using the static instance, and I guess this doesn't need to be programmatic (can just programmatically set Resource instead) so it's only for control from command line.

@iNikem
Copy link
Contributor Author

iNikem commented Aug 18, 2020

I will be happy if this gets merged today :) Then I can finish implementing this in instrumentation repo (European) tomorrow.

@iNikem
Copy link
Contributor Author

iNikem commented Aug 18, 2020

Copy link
Contributor

@jkwatson jkwatson left a comment

Choose a reason for hiding this comment

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

love it.

@jkwatson jkwatson merged commit 94eaef4 into open-telemetry:master Aug 18, 2020
@iNikem iNikem deleted the resource-provider branch August 19, 2020 05:10
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.

4 participants