Skip to content

Conversation

zeitlinger
Copy link
Member

@zeitlinger zeitlinger commented Sep 4, 2025

Alternative to #7418 that

  • does not expose resource more than it already is - as part of AutoConfiguredOpenTelemetrySdk
  • does not create resource twice

Fixes open-telemetry/opentelemetry-java-instrumentation#14325

@zeitlinger zeitlinger requested a review from a team as a code owner September 4, 2025 11:00
@zeitlinger zeitlinger self-assigned this Sep 4, 2025
Copy link

codecov bot commented Sep 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (89c7973) to head (84e061b).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@jack-berg jack-berg left a 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);
Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

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

@zeitlinger zeitlinger force-pushed the declarative-config-return-resource branch from 5f388fb to 16e1492 Compare September 25, 2025 12:15
@zeitlinger
Copy link
Member Author

@jack-berg please check again

}

Resource getResource() {
// called via reflection from io.opentelemetry.sdk.autoconfigure.IncubatingUtil
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

@robsunday robsunday left a 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;
Copy link
Member

@jack-berg jack-berg Sep 26, 2025

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.

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.

Declarative config: extract Resource correctly
3 participants