-
Notifications
You must be signed in to change notification settings - Fork 906
return resource in auto configured sdk #7639
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
base: main
Are you sure you want to change the base?
return resource in auto configured sdk #7639
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7639 +/- ##
=========================================
Coverage 90.13% 90.13%
- Complexity 7192 7197 +5
=========================================
Files 814 814
Lines 21713 21728 +15
Branches 2127 2127
=========================================
+ Hits 19570 19585 +15
Misses 1477 1477
Partials 666 666 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1b36c6e
to
5f388fb
Compare
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.
Just a couple of minor comments but I think this is a decent way to proceed.
Method create = | ||
declarativeConfiguration.getMethod( | ||
"create", openTelemetryConfiguration, ComponentLoader.class); | ||
"createAutoConfiguredSdk", openTelemetryConfiguration, ComponentLoader.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.
Let's keep calling this create
, which comes from the spec: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk.md#create
I think we have a good argument that the AutoConfiguredOpenTelemetrySdk
is just a composite of all the required SDK components.
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.
create
already exists with the same parameters - it returns ExtendedOpenTelemetrySdk
import java.lang.reflect.Method; | ||
import java.util.Objects; | ||
|
||
class AutoConfiguredOpenTelemetrySdkAccess { |
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 could also move this to an internal package in the autoconfigure module. I don't think it matters too much. Just a matter of perspective: is the autoconfigure module exposing experimental access for other components to call AutoConfiguredOpenTelemetrySdk#create
or is file config "breaking into" the autoconfigure module?
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.
Great idea - moving to incubating util also removes the createAutoConfiguredSdk
method, because that's now done using reflection
5f388fb
to
16e1492
Compare
@jack-berg please check again |
} | ||
|
||
Resource getResource() { | ||
// called via reflection from io.opentelemetry.sdk.autoconfigure.IncubatingUtil |
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.
Do you think this comment may be useful?
On one hand it explains why no one should remove this method, but on the other hand it will be easy to forget to update/remove it when declarative config stuff goes out of incubator.
Maybe instead of this comment it would be better to add a unit test in IncubatingUtilTest that verifies that getResource is actually called.
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 test is already there - but I get how it can get out of sync
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.
Solution works perfectly and I can access resource attributes in my BeforeAgentListener
implementations
|
||
Resource getResource() { | ||
// called via reflection from io.opentelemetry.sdk.autoconfigure.IncubatingUtil | ||
return resource; |
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.
Maybe throw an exception if getResource
is called before setResource
to make it easier to track down ordering issues.
Alternative to #7418 that
AutoConfiguredOpenTelemetrySdk
Fixes open-telemetry/opentelemetry-java-instrumentation#14325