Skip to content

Conversation

zeitlinger
Copy link
Member

Fixes #7495

jsuereth and others added 30 commits July 16, 2025 09:18
- Create Entity/EntityBuilder class in internal package
- Update serialization code

Need to discuss how to work with Resource going forward.
- Remove ResourceWithEntity, no way to keep bincompat that way
- Update toString tests to be a lot more forgiving, but preserve intent
- fix reflective method lookup
- also add unit test in the right project.
- Creates an API matching EntityProvider OTEP
- Updates EntityDetector to be ResourceDetector
- Creates synchronous "update resource with this entity" method.
- Adds wiring for incubating API + incubating SDK

Note: Still have some thoughts and ideas about a formal API, this may still change.
- Remove `Entity` and only expose `EntityBuilder` similar to how we do `LogRecord`s.
- Have methods on `Resource` which determine if you're attaching the entity, simplify "remove" or just ignore for now.
…OpenTelemetry API.

- Update shared state in SDK to use Supplier<Resource> instead of Resource
- Add helper utils to expose private methods to supply the supplier
- Create new ExtendedOpenTelemetry* API/SDK and end-to-end test.
…internal/otlp/EntityRefMarshaler.java

Co-authored-by: jack-berg <[email protected]>
- Hide more methods (no incubating methods in public APIs that are not internal)
- Update builder API to use attributes directly
- Use static instances in Noop API
…lemetrySdk.getOpenTelemetrySdk() to return the extended instance
Copy link

codecov bot commented Jul 16, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.03%. Comparing base (54e8209) to head (e2584f8).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
.../extension/incubator/ExtendedOpenTelemetrySdk.java 88.88% 2 Missing ⚠️
...telemetry/api/incubator/ExtendedOpenTelemetry.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7496      +/-   ##
============================================
+ Coverage     90.01%   90.03%   +0.02%     
- Complexity     7090     7101      +11     
============================================
  Files           803      805       +2     
  Lines         21444    21484      +40     
  Branches       2092     2093       +1     
============================================
+ Hits          19302    19343      +41     
+ Misses         1477     1475       -2     
- Partials        665      666       +1     

☔ 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.

@zeitlinger
Copy link
Member Author

Alternative is #7500

@zeitlinger zeitlinger marked this pull request as draft July 18, 2025 08:17
@zeitlinger zeitlinger self-assigned this Jul 18, 2025
import javax.annotation.concurrent.ThreadSafe;

/** A new interface for creating OpenTelemetrySdk that supports getting {@link ConfigProvider}. */
public class ExtendedOpenTelemetrySdk extends OpenTelemetrySdk
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, we could skip extending OpenTelemetrySdk and avoid awkwardness of trying to figure mesh together builder and constructors. OpenTelemetrySdk doesn't do much anyway so not much to repeat.

Maybe do something like have ExtendedOpenTelemetrySdk accept a delegate OpenTelemetrySdk instance during initialization and skip the builder pattern? Usage could be something like:

ExtendedOpenTelemetrySdk sdk = ExtendedOpenTelemetrySdk.create(OpenTelemetrySdk, SdkConfigProvider);

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 goal (IMO) is to have AutoConfiguredOpenTelemetrySdk.getOpenTelemetrySdk() return the instance that we can work with - so that library users don't have to jump through hoops to have the correct instance.

* @param configurator A callback fleshing out tracers.
* @return this
*/
public ExtendedOpenTelemetrySdkBuilder withTracerProvider(
Copy link
Member

Choose a reason for hiding this comment

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

What do we get from these withers?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is from the entity PR where it's actually needed

* @throws DeclarativeConfigException if unable to parse or interpret
*/
public static OpenTelemetrySdk parseAndCreate(InputStream inputStream) {
public static ExtendedOpenTelemetrySdk parseAndCreate(InputStream inputStream) {
Copy link
Member

Choose a reason for hiding this comment

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

This is cool - frees up callers from needing to worry about initializing SdkConfigProvider

.matches("OpenTelemetrySdk\\{tracerProvider=SdkTracerProvider\\{.*}.*}")
.matches("OpenTelemetrySdk\\{.*, meterProvider=SdkMeterProvider\\{.*}.*}")
.matches("OpenTelemetrySdk\\{.*, loggerProvider=SdkLoggerProvider\\{.*}.*}")
.matches("OpenTelemetrySdk\\{.*, propagators=DefaultContextPropagators\\{.*}}");
Copy link
Member

Choose a reason for hiding this comment

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

Meh yeah this is probably an overdue improvement 😉

@zeitlinger
Copy link
Member Author

@jack-berg please check if you like the alternative without API changes better: #7500

@jack-berg
Copy link
Member

Ok I pulled this down and started tweaking some things to see how they would work out, and eventually concluded that it would be better to commit / push my changes rather than leave a bunch of comments. I do like the overall direction of this.

Changes available for review here: https://github.com/open-telemetry/opentelemetry-java/compare/main...jack-berg:opentelemetry-java:jack-extended-opentelemetry?expand=1

Summary:

  • Get rid of ExtendedOpenTelemetrySdkBuilder
  • Introduce simple method for instantiating instances: ExtendedOpenTelemetry#create(OpenTelemetrySdk, SdkConfigProvider)
  • Make all methods of OpenTelemetrySdk final except shutdown, close, and toString
  • Adjust ExtendedOpenTelemetry#toString
  • Remove / cleanup other bits
  • Merge main and resolve conflicts

Let me know what you think. If you like it, consider merge my changes into your branch and mark ready for review.

@zeitlinger zeitlinger marked this pull request as ready for review September 12, 2025 10:07
@zeitlinger
Copy link
Member Author

@jack-berg great - I like it! I merged your changes 😄

The builder is from joshs PR where he needs it for the entities - but I guess we can tackle that in a later PR.

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.

@jkwatson take a look at the change to the public API when you have a chance

*** MODIFIED METHOD: PUBLIC FINAL (<- NON_FINAL) io.opentelemetry.sdk.logs.SdkLoggerProvider getSdkLoggerProvider()
*** MODIFIED METHOD: PUBLIC FINAL (<- NON_FINAL) io.opentelemetry.sdk.metrics.SdkMeterProvider getSdkMeterProvider()
*** MODIFIED METHOD: PUBLIC FINAL (<- NON_FINAL) io.opentelemetry.sdk.trace.SdkTracerProvider getSdkTracerProvider()
*** MODIFIED METHOD: PUBLIC FINAL (<- NON_FINAL) io.opentelemetry.api.trace.TracerProvider getTracerProvider()
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes are technically breaking changes, yeah? If someone had implemented their own extension to OpenTelemetrySdk? I don't know how likely that is to be the case, but I could imagine a vendor doing it. How concerned are we about making all of these methods (and the class) final breaking someone's custom implementation?

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 class was final before, so it was not possible to extend OpenTelemetrySdk before

Copy link
Member

Choose a reason for hiding this comment

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

the class itself was final previously

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't that top line in the api diff say it's being made final? Am I reading that wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh! it's the opposite. 🤦🏽

Copy link
Contributor

Choose a reason for hiding this comment

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

So, this, then, I guess, is the only thing that's possible a concern to think about...now people will be able to extend OpenTelemetrySdk, which could potentially cause future breaking changes, if we add methods and they collide with ones that have been added externally. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

That's true. But I believe we're already exposed to similar risk: Consider the OpenTelemetry interface: People can extend it, implement the extended methods, and later we could extend OpenTelemetry with conflicting methods.

@jkwatson
Copy link
Contributor

@jkwatson take a look at the change to the public API when you have a chance

👍🏽 Seems ok to me. :shipit:

@jkwatson jkwatson merged commit 1c5dd50 into open-telemetry:main Sep 16, 2025
29 checks passed
@zeitlinger zeitlinger deleted the extended-opentelemetry branch September 16, 2025 16:25
@zeitlinger
Copy link
Member Author

Thanks!

@trask
Copy link
Member

trask commented Sep 16, 2025

this is awesome, thanks all!

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.

Add ExtendedOpenTelemetry
5 participants