Skip to content

[opentelemetry-instrumentation-genai-langchain] Pass conversation id when starting invocations - #798

Open
sfc-gh-zeningchen wants to merge 2 commits into
open-telemetry:mainfrom
sfc-gh-zeningchen:fix/langchain-unnamed-agent-conversation-id
Open

sfc-gh-zeningchen wants to merge 2 commits into
open-telemetry:mainfrom
sfc-gh-zeningchen:fix/langchain-unnamed-agent-conversation-id

Conversation

@sfc-gh-zeningchen

@sfc-gh-zeningchen sfc-gh-zeningchen commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

The LangChain callback handler set conversation_id on 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_agent with no name) did not get a conversation id at all.

This PR passes conversation_id to the telemetry handler when each invocation starts.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

  • Added tests where the child chat call has no LangChain metadata, so it can only get the id from the OTel context. They cover workflows, named agents, and unnamed agents, and they fail without this change.
  • Updated the existing tests to check the conversation_id argument instead of setting the attribute afterwards.
  • Ran the LangChain test suite in the latest and oldest environments.

Checklist

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

…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.
Copilot AI lite review requested due to automatic review settings September 27, 2026 00:10
@sfc-gh-zeningchen
sfc-gh-zeningchen requested a review from a team as a code owner September 27, 2026 00:10
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-09-27 00:24 UTC

Investigate required status check failures.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants