Repository navigation
Add otel langchain instrumentation - #20
Radhika Gupta (rads-1996) wants to merge 20 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new opentelemetry-instrumentation-langchain package that instruments LangChain chat model executions (notably ChatOpenAI / ChatBedrock) using OpenTelemetry GenAI semantic conventions, along with a test suite that validates spans, metrics, and logs via VCR cassettes.
Changes:
- Added a LangChain instrumentor that injects an OpenTelemetry callback handler into LangChain’s callback manager.
- Implemented an invocation-state manager and callback handler logic to start/stop/fail LLM invocations and populate GenAI attributes.
- Added pytest coverage (including VCR cassettes) to assert emitted spans/metrics/logs for success and error scenarios.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 19 comments.
Show a summary per file
| File | Description |
|---|---|
| src/_langchain/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/init.py | Defines LangChainInstrumentor and wrap/unwrap wiring for callback manager injection |
| src/_langchain/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py | Implements LangChain callback handler to build GenAI invocation objects and stop/fail them |
| src/_langchain/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/invocation_manager.py | Stores invocation state keyed by run_id with basic parent/child tracking |
| src/_langchain/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/span_manager.py | Adds a span manager abstraction for run_id-based span lifecycle management |
| src/_langchain/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/package.py | Declares instrumentation dependency metadata |
| src/_langchain/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/version.py | Adds package version definition |
| src/_langchain/opentelemetry-instrumentation-langchain/tests/conftest.py | Test fixtures for OTel SDK in-memory exporters + VCR configuration/scrubbing |
| src/_langchain/opentelemetry-instrumentation-langchain/tests/test_llm_call.py | End-to-end assertions for spans/metrics/logs for ChatOpenAI invoke success/error |
| src/_langchain/opentelemetry-instrumentation-langchain/tests/test_invocation_manager.py | Unit tests for _InvocationManager behavior |
| src/_langchain/opentelemetry-instrumentation-langchain/tests/cassettes/test_chat_openai_gpt_3_5_turbo_model_llm_call.yaml | Recorded success response cassette |
| src/_langchain/opentelemetry-instrumentation-langchain/tests/cassettes/test_chat_openai_gpt_3_5_turbo_model_llm_call_with_error.yaml | Recorded auth error response cassette |
| src/_langchain/opentelemetry-instrumentation-langchain/pyproject.toml | Hatch-based packaging config for the new instrumentation package |
| src/_langchain/opentelemetry-instrumentation-langchain/dev_requirements.txt | Dev/test requirements for the new package |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f014441 to
664eb55
Compare
…onftest.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
bad068e to
f20a9f5
Compare
| @@ -0,0 +1,122 @@ | |||
| # Copyright The OpenTelemetry Authors | |||
There was a problem hiding this comment.
Do we need to copy the code over or can we take a reference to OTel instrumentation
There was a problem hiding this comment.
This instrumentation package in otel is not published yet, therefore we need to copy the code till the upstream package is released and in a good state. Until then we will maintain this internally in the distro.
No description provided.