-
Notifications
You must be signed in to change notification settings - Fork 858
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
Conversation
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.
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)) { |
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.
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.
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.
Cannot the same be achieved via controlling application classpath?
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.
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.
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.
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 :)
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.
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?
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.
Ok, fair enough.
- Should I do this in this very same PR?
- Should new config property go to
TraceConfig
?
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.
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.
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.
Added #1551
sdk/src/main/java/io/opentelemetry/sdk/resources/ResourceProvider.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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.
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)) { |
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.
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.
I will be happy if this gets merged today :) Then I can finish implementing this in instrumentation repo (European) tomorrow. |
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.
love it.
Partially addresses #1454