open-telemetry / opentelemetry-java

OpenTelemetry Java SDK
https://opentelemetry.io
Apache License 2.0
1.96k stars 810 forks source link

Decide / document advice for native instrumentations #6604

Open jack-berg opened 1 month ago

jack-berg commented 1 month ago

Discussed in the 7/11/24 Java SIG and later in this slack thread. Opening an issue to track and bring more visibility to the conversation.

We want libraries and frameworks to adopt the OpenTelemetry API for native instrumentation. The idea is that distributing instrumentation is more scalable than a centralized approach. Additionally, native instrumentations cast a wider net of possible users, since although native instrumentation should be compatible with a java agent, it shouldn't require a java agent.

We should document the patterns which are idiomatic for library authors to follow. This will reduce the cognitive load of adopting OpenTelemetry APIs for instrumentation (there's a lot of concepts and more we can do to simplify the better) and promote consistency.

There are a few key questions we need to discuss before documenting:

Should instrumentations default to GlobalOpenTelemetry.get() or OpenTelemetry.noop()?

Supposing we recommend defaulting to GlobalOpenTelemetry.get()...

Supposing we recommend defaulting to OpenTelemetry.noop()...

Should instrumentations prefer the higher order instrumentation API or the lower level trace, metrics, log bridge API?

Args in favor of the instrumentation API...

Args in favor of the trace, metrics, log bridge API...

jack-berg commented 1 month ago

cc @open-telemetry/java-instrumentation-approvers

zeitlinger commented 1 month ago

explicitly install an opentelemetry instance via something like .install(OpenTelemetry), and do nothing until a user installs it

The agent could install the otel instance automatically if the instrumentation somehow signals it, e.g. by implementing an interface