Run @WithSpan instrumetnation after other instrumentations#18874
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes the javaagent ordering of annotation-based instrumentation modules so they run after other instrumentations, enabling them to observe and enrich spans that were started earlier by “automatic” instrumentations.
Changes:
- Updated the OpenTelemetry instrumentation-annotations module ordering from early to late execution.
- Added explicit late ordering for the OpenTelemetry extension-annotations and external-annotations modules.
- Updated the kotlinx-coroutines annotation instrumentation module ordering to run late as well.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-annotations-1.16/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/instrumentationannotations/v1_16/AnnotationInstrumentationModule.java | Changes module order to run after other instrumentations. |
| instrumentation/opentelemetry-extension-annotations-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/extensionannotations/v1_0/WithSpanInstrumentationModule.java | Adds module order override to run after other instrumentations. |
| instrumentation/kotlinx-coroutines/kotlinx-coroutines-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/v1_0/instrumentationannotations/AnnotationInstrumentationModule.java | Changes module order to run after other instrumentations. |
| instrumentation/external-annotations/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/external/annotations/ExternalAnnotationInstrumentationModule.java | Adds module order override to run after other instrumentations. |
jaydeluca
approved these changes
Jun 1, 2026
trask
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Run @WithSpan and other similar instrumetnation after other instrumentations. Based on the comments this seems to be the intended behavior. Running after other instrumentations allows for example adding attributes to the spans created by some other instrumentation.