Skip to content

Conversation

@jaydeluca
Copy link
Member

@jaydeluca jaydeluca commented Oct 28, 2025

@jaydeluca jaydeluca requested a review from a team as a code owner October 28, 2025 21:03
@otelbot-docs otelbot-docs bot requested review from a team October 28, 2025 21:03
@jaydeluca
Copy link
Member Author

/fix:dict

@otelbot-docs
Copy link
Contributor

otelbot-docs bot commented Oct 28, 2025

fix:dict applied successfully in run 18889168162.

@@ -1,23 +1,41 @@
---
Copy link
Member Author

Choose a reason for hiding this comment

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

[For reviewers] I took the approach of including code examples instead of just linking to the example in the java agent repo because I personally don't like the user experience of having to jump around and reference multiple sources when reading documentation. It also didn't seem like the code would change frequently, so upkeep shouldn't be too bad (hopefully).

With that being said, If we think this is too verbose, I can remove the code example and any other sections and just link out to the example code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with you, having code examples directly into documentation without having to open a separate tab is definitely a better experience, one of the main downsides though is keeping this code relevant and maintained over time.

Maybe it's a dumb idea, but if we were able to put some markers in the example in instrumentation and then automatically extract and inline the relevant parts into this documentation it would be nice, but that sounds also quite brittle and could easily break over time.

Copy link
Member

Choose a reason for hiding this comment

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

we actually have this mechanism - but it's not documented and doesn't run on a regular basis

@svrnm is this something you're planning to do or are looking for help?


- _"I want to customize instrumentation without modifying the instrumentation"_:

The `InstrumenterCustomizerProvider` extension point allows you to customize
Copy link

Choose a reason for hiding this comment

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

is it worth mentioning that InstrumenterCustomizerProvider is an experimental api?


There are two ways to use extensions with the Java agent:

1. **Load at runtime** using the `-Dotel.javaagent.extensions` option (described
Copy link

Choose a reason for hiding this comment

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

Load at runtime is a bit weird, extensions added to agent are also loaded at runtime. Perhaps we shoudl use As a separate jar file or something like that.


### Basic Usage

Extensions can be loaded at runtime using the `otel.javaagent.extensions` system
Copy link

Choose a reason for hiding this comment

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

could mention that OTEL_JAVAAGENT_EXTENSIONS env var also work

Comment on lines +127 to +129
1. Creates an
[isolated class loader](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/javaagent-structure.md#extension-class-loader)
for each extension JAR to prevent conflicts between extensions
Copy link

Choose a reason for hiding this comment

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

This is an implementation detail. We could consider giving up on it and loading extensions together with the agent code. This would for example allow agent code that uses ServiceLoader.load without specifying a class loader to discover spis from extensions. Admittedly this is less of an issue now that the sdk seems to always use user specified class loader for looking up spis.

Comment on lines +132 to +134
3. Automatically applies shading to extension classes at runtime (extensions use
normal OpenTelemetry imports, and the agent handles compatibility
automatically)
Copy link

Choose a reason for hiding this comment

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

I think the shading is kind of an advanced topic, hopefully most of the extension users don't even realize that something is shaded. If we are going to mention it then I think the goal should be to reduce confusion for the ones who try to debug the extension and notice that things aren't quite as they'd expect.

#### Dependencies Provided by Agent (use `compileOnly`)
These APIs are available at runtime from the agent class loader:
Copy link

Choose a reason for hiding this comment

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

Not completely true, some of these are in boot loader. Could instead say that these apis are provided by the agent.

### Using @AutoService
The `@AutoService` annotation automatically generates the required
Copy link

Choose a reason for hiding this comment

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

for @AutoService to work you also need to configure the annotation processor

### AutoConfigurationCustomizerProvider
The main entry point for customizing SDK configuration. This allows you to:
Copy link

Choose a reason for hiding this comment

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

Do we have sdk documentation where we could link for this? Should it be mentioned that these won't work with the declarative configuration?

### Accessing the Current Span
In instrumentation advice classes, use `Java8BytecodeBridge` to access the
Copy link

Choose a reason for hiding this comment

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

Should we explain why and when one needs to use Java8BytecodeBridge instead of Span.current() or Context.current()?
Jumping to advice while skipping InstrumentationModule and TypeInstrumentation feels a bit confusing.

### Sharing Data via Context
Use the OpenTelemetry `Context` API to share data throughout the request
Copy link

Choose a reason for hiding this comment

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

Imo this is also confusing. Could start with introduction to instrumentation api, context customization is really one of the less used aspects there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Page feedback]: Adding extensions is poorly documented Add more detail to the Java Agent Extension docs

5 participants