Run openserch asyn callbacks with parent context#19027
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes the OpenSearch 3.0 async instrumentation to run user-attached callbacks with the parent context active, rather than the context of the OpenSearch span created for the operation. This aligns the behavior with other async instrumentations in the repository (e.g., Apache HTTP async client, Elasticsearch REST/transport, Vertx HTTP client) which all propagate the parent context to user callbacks.
Changes:
- Adds a
wrapFuturehelper that creates a newCompletableFuturewrapper ensuring the parent context is active when downstream callbacks execute. - Updates test assertions in both
AbstractOpenSearchTestandOpenSearchAwsSdk2TransportTestto expect the "callback" span to be parented to the root "client" span (index 0) instead of the OpenSearch operation span (index 1).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
instrumentation/opensearch/opensearch-java-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opensearch/v3_0/OpenSearchTransportInstrumentation.java |
Stores parentContext in AdviceScope, adds static wrapFuture method to wrap the returned future with parent context propagation |
instrumentation/opensearch/opensearch-java-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/opensearch/v3_0/AbstractOpenSearchTest.java |
Updates async test to assert callback span is parented to the root span (index 0) |
instrumentation/opensearch/opensearch-java-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/opensearch/v3_0/OpenSearchAwsSdk2TransportTest.java |
Same parent assertion fix for the AWS SDK transport variant |
jaydeluca
approved these changes
Jun 17, 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.
https://develocity.opentelemetry.io/s/252w7o5o7ozza/tests/task/:instrumentation:opensearch:opensearch-java-3.0:javaagent:test/details/io.opentelemetry.javaagent.instrumentation.opensearch.v3_0.OpenSearchApacheHttpClient5TransportTest/shouldGetStatusAsyncWithTraces()?expanded-stacktrace=WyIwIl0&top-execution=1
Our instrumentations run callbacks with parent context not the context of the span that was create for the operation that triggered the callback.