Skip to content

Update langchain instrumentation (update to latest semantic conventions, bug fixes, update semantic conventions version, etc.)#129

Open
rads-1996 wants to merge 7 commits into
open-telemetry:mainfrom
rads-1996:update-langchain-latest-semantics
Open

Update langchain instrumentation (update to latest semantic conventions, bug fixes, update semantic conventions version, etc.)#129
rads-1996 wants to merge 7 commits into
open-telemetry:mainfrom
rads-1996:update-langchain-latest-semantics

Conversation

@rads-1996

Copy link
Copy Markdown

Description

Update LangChain instrumentation to latest GenAI semantic conventions

  • Added provider value mapping to match semantic conventions
  • Normalized roles (human→user, ai→assistant, function→tool)
  • Dropped [ChatOpenAI]/[ChatBedrock] allowlist; added ["model"] lookup so Gemini, Vertex, Anthropic, etc. emit spans
  • Fixed [max_tokens] fallback for non-OpenAI providers
  • Dropped fabricated "unknown"/"stop" finish reasons;
  • Lowered tool calls/responses and reasoning blocks into spec message parts
  • Bumped util-genai semconv pin to ~= 0.63b1; replaced magic strings with codegenned constants
  • Deleted unused span_manager.py

Follow-up PR

  • Missing inference attributes already exposed by LangChain: top_k, choice.count, stream, output.type, tool.definitions, system_instructions, server.address/port, cache & reasoning token counts, conversation.id

Fixes part of #126

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

See CONTRIBUTING.md
for the style guide, changelog guidance, and more.

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

@rads-1996 rads-1996 requested a review from a team as a code owner June 11, 2026 16:34
Copilot AI review requested due to automatic review settings June 11, 2026 16:34

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.

Pull request overview

Note

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

Updates GenAI semantic convention usage and improves LangChain GenAI instrumentation to emit spec-conformant provider/role/message attributes (including Gemini and tool/function message handling).

Changes:

  • Replaced hard-coded GenAI attribute keys with opentelemetry-semantic-conventions constants and bumped the semconv dependency.
  • Added robust message conversion utilities (role normalization, tool calls/results, reasoning parts) and provider normalization.
  • Updated LangChain callback handler and tests to reflect spec role/provider names and new span emission behavior (Gemini, finish reasons).

Reviewed changes

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

Show a summary per file
File Description
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_inference_invocation.py Switch reasoning token attribute to semconv constant.
util/opentelemetry-util-genai/src/opentelemetry/util/genai/_agent_invocation.py Switch agent/version + cache token attributes to semconv constants.
util/opentelemetry-util-genai/pyproject.toml Bump semantic conventions dependency to access GenAI constants.
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/utils.py Introduce provider normalization + structured message conversion for roles/tool calls/reasoning.
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/callback_handler.py Use new conversion utilities; expand model/provider support; improve finish_reason extraction.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_llm_call.py Update assertions for spec roles/providers; add Gemini + FunctionMessage mapping test.
instrumentation/opentelemetry-instrumentation-genai-langchain/tests/test_callback_handler.py Add tests for finish_reason defaults and propagation in output conversion.
instrumentation/opentelemetry-instrumentation-genai-langchain/src/opentelemetry/instrumentation/genai/langchain/span_manager.py Remove legacy span manager implementation.

@rads-1996 rads-1996 force-pushed the update-langchain-latest-semantics branch 2 times, most recently from e9122f0 to 6252165 Compare June 15, 2026 15:28
# Mapping from LangChain ``ls_provider`` metadata values to the well-known
# ``gen_ai.provider.name`` values defined by the GenAI semantic conventions.
_PROVIDER_NAME_OVERRIDES: dict[str, str] = {
"amazon_bedrock": GenAIAttributes.GenAiProviderNameValues.AWS_BEDROCK.value,

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.

Curious as to where you got this list from?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

I think we either want to use the well-known values in sem conv or what's actually available from langchain

@rads-1996 rads-1996 changed the title Update langchain instrumentation to latest semantic conventions Update langchain instrumentation (update to latest semantic conventions, bug fixes, genai-utils (version pinning)) Jun 15, 2026
@rads-1996 rads-1996 changed the title Update langchain instrumentation (update to latest semantic conventions, bug fixes, genai-utils (version pinning)) Update langchain instrumentation (update to latest semantic conventions, bug fixes, update semantic conventions version, etc.) Jun 15, 2026
@rads-1996 rads-1996 force-pushed the update-langchain-latest-semantics branch from 26fd2ff to aaa3a08 Compare June 15, 2026 17:15
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.

5 participants