[opentelemetry-instrumentation-genai-langchain] Pass conversation id when starting invocations - #798
Open
sfc-gh-zeningchen wants to merge 2 commits into
Conversation
…d when starting invocations Workflow, agent, and chat invocations set `conversation_id` only after they were created. The shared util reads it at creation time to put it into the OTel context, so child spans (for example, from another instrumentation) never inherited it. An agent created without a name did not get a conversation id at all. Pass the id to the telemetry handler when starting each invocation.
Pull request dashboard statusWaiting on the author · refreshed 2026-09-27 00:24 UTC Investigate required status check failures. Status above doesn't look right?
|
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved issues were identified that would block approval.
Review effort: Lite
Findings: None
What changed in this PR
Fixes LangChain conversation ID propagation by supplying IDs when invocations are created, enabling inheritance by child spans.
Changes:
- Pass conversation IDs to workflow, agent, and chat telemetry factories.
- Support unnamed agents.
- Add context-inheritance tests and update call assertions.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_conversation_id.py | Updated as part of this pull request. |
| instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py | Updated as part of this pull request. |
| instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_agent_classification_corpus.py | Updated as part of this pull request. |
| instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/callback_handler.py | Updated as part of this pull request. |
| instrumentation/opentelemetry-instrumentation-genai-langchain/.changelog/798.fixed | Updated as part of this pull request. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
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.
Description
The LangChain callback handler set
conversation_idon workflow, agent, and chat invocations only after creating them. The shared util reads the id at creation time and stores it in the OTel context, so child spans, including spans from other instrumentations, never inherited it. An agent created without a name (for example,create_agentwith noname) did not get a conversation id at all.This PR passes
conversation_idto the telemetry handler when each invocation starts.Type of change
How has this been tested?
conversation_idargument instead of setting the attribute afterwards.latestandoldestenvironments.Checklist