Conversation
Pull request dashboard statusWaiting on the author · refreshed 2026-09-21 19:21 UTC Respond to 1 review item (e.g. link a commit, explain why not, ask a follow-up):
Status above doesn't look right?
|
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical and moderate findings remain unresolved in async callback handling and cross-context detach safety.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (3)
What changed in this PR
Adds explicit parent-context propagation for GenAI invocations and LangChain callback spans, with async-context handling improvements.
Changes:
- Adds
contextandattach_to_contextsupport across invocation APIs. - Propagates parent contexts through LangChain run hierarchies.
- Adds tests, documentation, and changelog entries.
| File | Summary |
|---|---|
util/opentelemetry-util-genai/tests/test_utils.py |
Tests utility context behavior. |
util/opentelemetry-util-genai/tests/test_toolcall.py |
Tests detached tool invocations. |
util/opentelemetry-util-genai/tests/test_handler_workflow.py |
Tests workflow context propagation. |
util/opentelemetry-util-genai/tests/test_handler_retrieval.py |
Tests retrieval context propagation. |
util/opentelemetry-util-genai/tests/test_handler_fetch_response.py |
Tests fetch-response context propagation. |
util/opentelemetry-util-genai/tests/test_handler_agent.py |
Tests agent context behavior. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py |
Exposes context controls. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_workflow_invocation.py |
Supports workflow context propagation. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_tool_invocation.py |
Supports tool context propagation. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_retrieval_invocation.py |
Supports retrieval context propagation. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_invocation.py |
Implements context attachment and lifecycle handling. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py |
Supports inference context propagation. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_fetch_response_invocation.py |
Supports fetch-response context propagation. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_embedding_invocation.py |
Supports embedding context propagation. |
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_agent_invocation.py |
Supports agent context propagation. |
util/opentelemetry-util-genai/.changelog/758.added |
Documents the utility API addition. |
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_tools.py |
Tests LangChain tool span parenting. |
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py |
Tests callback context propagation. |
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_agent_classification_corpus.py |
Tests nested async spans. |
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/invocation_manager.py |
Resolves ancestor invocation contexts. |
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/callback_handler.py |
Applies parent contexts to callback spans. |
instrumentation/opentelemetry-instrumentation-genai-langchain/README.rst |
Documents async propagation limitations. |
instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/758.fixed |
Documents the LangChain fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+188
to
+192
| def _should_attach_to_context() -> bool: | ||
| try: | ||
| asyncio.get_running_loop() | ||
| return False | ||
| except RuntimeError: |
lmolkova
force-pushed
the
fix-async-context-propagation-513
branch
from
September 21, 2026 18:10
9d06a45 to
7735877
Compare
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.



What does this change do?
Fixes #513 by adding optional
contextandattach_to_contextparameters toTelemetryHandlerand passing parent context down in the LangChain callback handler. In async event loops, ambient context attachment is disabled to avoid cross-context detach errors.Any known gaps or concerns
Context propagation to nested calls (such as auto-instrumented HTTP clients or database queries within tools) is not supported when using LangChain async API.