Update langchain instrumentation (update to latest semantic conventions, bug fixes, update semantic conventions version, etc.)#129
Conversation
There was a problem hiding this comment.
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-conventionsconstants 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. |
e9122f0 to
6252165
Compare
26fd2ff to
aaa3a08
Compare
a5a4104 to
c31fa6a
Compare
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
Description
Update LangChain instrumentation to latest GenAI semantic conventions
Follow-up PR
Fixes part of #126
Type of change
Please delete options that are not relevant.
Checklist
See CONTRIBUTING.md
for the style guide, changelog guidance, and more.