Skip to content

fix: use standard gen_ai.conversation.id instead of microsoft.sessiomid in LangChain tracer#152

Open
hectorhdzg wants to merge 2 commits into
microsoft:mainfrom
hectorhdzg:fix/langchain-otel-semconv
Open

fix: use standard gen_ai.conversation.id instead of microsoft.sessiomid in LangChain tracer#152
hectorhdzg wants to merge 2 commits into
microsoft:mainfrom
hectorhdzg:fix/langchain-otel-semconv

Conversation

@hectorhdzg
Copy link
Copy Markdown
Member

Replace the A365-specific 'microsoft.session.id' attribute with the standard OTel GenAI semantic convention 'gen_ai.conversation.id' in the generic LangChain tracer. This ensures Azure Monitor and OTLP users get standard attributes without any A365-specific coupling.

Changes:

  • _utils.py: metadata() and extract_session_info() now yield gen_ai.conversation.id instead of microsoft.session.id. Removed duplicate SESSION_ID_KEY constant and the redundant second yield in extract_session_info.
  • _span_enricher.py: New A365 span enricher for LangChain that maps gen_ai.conversation.id -> microsoft.session.id, and passes through input/output messages and tool args for invoke_agent/execute_tool spans.
  • _tracer_instrumentor.py: Registers the LangChain span enricher with the A365 enriching pipeline (same pattern as SemanticKernel and AgentFramework instrumentors).
  • Tests updated for the attribute key change plus 8 new enricher tests.

….id in LangChain tracer

Replace the A365-specific 'microsoft.session.id' attribute with the standard
OTel GenAI semantic convention 'gen_ai.conversation.id' in the generic
LangChain tracer. This ensures Azure Monitor and OTLP users get standard
attributes without any A365-specific coupling.

Changes:
- _utils.py: metadata() and extract_session_info() now yield
  gen_ai.conversation.id instead of microsoft.session.id. Removed
  duplicate SESSION_ID_KEY constant and the redundant second yield
  in extract_session_info.
- _span_enricher.py: New A365 span enricher for LangChain that maps
  gen_ai.conversation.id -> microsoft.session.id, and passes through
  input/output messages and tool args for invoke_agent/execute_tool spans.
- _tracer_instrumentor.py: Registers the LangChain span enricher with
  the A365 enriching pipeline (same pattern as SemanticKernel and
  AgentFramework instrumentors).
- Tests updated for the attribute key change plus 8 new enricher tests.
Copilot AI review requested due to automatic review settings May 19, 2026 20:08
Comment thread src/microsoft/opentelemetry/_genai/_langchain/_tracer_instrumentor.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR standardizes LangChain tracing attributes by emitting the OTel GenAI semantic convention gen_ai.conversation.id from the generic tracer, while adding an A365-specific span enricher to map that value back to microsoft.session.id when exporting through the A365 pipeline.

Changes:

  • Update LangChain utils to yield gen_ai.conversation.id (and remove duplicate/extra session-id yields).
  • Add and register an A365 LangChain span enricher that maps gen_ai.conversation.id → microsoft.session.id (and passes through select GenAI attributes).
  • Update tests for the attribute key change and add new enricher tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/langchain/test_utils.py Updates expectations to assert gen_ai.conversation.id instead of microsoft.session.id.
tests/langchain/test_span_enricher.py Adds unit tests for the new LangChain A365 span enricher behavior.
src/microsoft/opentelemetry/_genai/_langchain/_utils.py Emits GEN_AI_CONVERSATION_ID_KEY and removes the old SESSION_ID_KEY constant/duplicate yield.
src/microsoft/opentelemetry/_genai/_langchain/_tracer_instrumentor.py Registers/unregisters the LangChain A365 span enricher when the A365 pipeline is available.
src/microsoft/opentelemetry/_genai/_langchain/_span_enricher.py Introduces LangChain A365 span enricher mapping and selective attribute passthrough.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/langchain/test_span_enricher.py Outdated
Comment thread tests/langchain/test_span_enricher.py Outdated
Comment thread tests/langchain/test_span_enricher.py Outdated
Comment thread tests/langchain/test_span_enricher.py Outdated
Comment thread tests/langchain/test_span_enricher.py
Comment thread tests/langchain/test_span_enricher.py
Comment thread tests/langchain/test_span_enricher.py
Comment thread tests/langchain/test_span_enricher.py
Comment thread src/microsoft/opentelemetry/_genai/_langchain/_utils.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants