Skip to content

Add langchain instrumentation - #26

Merged
Radhika Gupta (rads-1996) merged 32 commits into
microsoft:mainfrom
rads-1996:add-langchain-instrumentation
Apr 10, 2026
Merged

Radhika Gupta (rads-1996) merged 32 commits into
microsoft:mainfrom
rads-1996:add-langchain-instrumentation

Conversation

@rads-1996

Copy link
Copy Markdown
Member

No description provided.

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

Adds first-party LangChain instrumentation to the Microsoft OpenTelemetry Python distro by introducing a LangChain BaseTracer implementation, an OTel BaseInstrumentor entry point for auto-discovery, and accompanying unit tests + sample.

Changes:

  • Introduce genai._langchain module with attribute-extraction utilities, a LangChain tracer that emits OTel spans, and an instrumentor that hooks BaseCallbackManager.
  • Register langchain as a supported/preview instrumentation and add an opentelemetry_instrumentor entry point.
  • Add a LangChain sample and a dedicated tests/langchain/ test suite.

Reviewed changes

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

Show a summary per file
File Description
tests/langchain/test_utils.py Unit tests for LangChain → OTel attribute extraction helpers.
tests/langchain/test_tracer.py Unit tests for tracer span lifecycle, agent wrapper spans, and aggregation behavior.
tests/langchain/test_tracer_instrumentor.py Unit tests for instrumentor wiring and callback-manager hook behavior.
tests/langchain/init.py Marks tests.langchain as a package.
src/microsoft/opentelemetry/_constants.py Adds langchain to supported instrumented libraries list.
src/microsoft/opentelemetry/_azure_monitor/_constants.py Adds langchain to preview/opt-in instrumentations.
src/genai/_langchain/_utils.py Implements core extraction/normalization utilities and OTel GenAI attribute mapping.
src/genai/_langchain/_tracer.py Implements LangChainTracer that creates spans for runs and aggregates agent content.
src/genai/_langchain/_tracer_instrumentor.py Adds OTel BaseInstrumentor to attach tracer to LangChain callback managers + convenience APIs.
src/genai/_langchain/init.py Exposes LangChainInstrumentor.
src/genai/init.py Introduces genai package.
samples/langchain/sample_langchain_instrumentation.py Demonstrates enabling LangChain instrumentation and running LLM + agent flows.
pyproject.toml Adds dependencies + registers the langchain instrumentor entry point.

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

Comment thread src/genai/_langchain/_utils.py Outdated
Comment thread src/microsoft/genai/_langchain/_utils.py
Comment thread src/microsoft/genai/_langchain/_utils.py
Comment thread src/genai/_langchain/_tracer.py Outdated
Comment thread samples/langchain/sample_langchain_instrumentation.py Outdated
@rads-1996
Radhika Gupta (rads-1996) force-pushed the add-langchain-instrumentation branch from 26e10a7 to cd32b83 Compare April 9, 2026 23:38
Comment thread samples/langchain/sample_langchain_instrumentation.py
Comment thread src/microsoft/genai/_langchain/_tracer_instrumentor.py
Comment thread src/microsoft/genai/_langchain/_tracer_instrumentor.py
@rads-1996
Radhika Gupta (rads-1996) force-pushed the add-langchain-instrumentation branch from 9c9f829 to 4c9772c Compare April 10, 2026 17:45
@rads-1996
Radhika Gupta (rads-1996) merged commit d80e516 into microsoft:main Apr 10, 2026
7 checks passed
@rads-1996
Radhika Gupta (rads-1996) deleted the add-langchain-instrumentation branch April 10, 2026 19:23
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