Skip to content

Add langchain instrumentation - #10

Merged
Hector Hernandez (hectorhdzg) merged 3 commits into
microsoft:mainfrom
hectorhdzg:hectorhdzg/langchain
Apr 10, 2026
Merged

Hector Hernandez (hectorhdzg) merged 3 commits into
microsoft:mainfrom
hectorhdzg:hectorhdzg/langchain

Conversation

@hectorhdzg

Copy link
Copy Markdown
Member

No description provided.

@rads-1996

Radhika Gupta (rads-1996) commented Apr 9, 2026 •

Copy link
Copy Markdown
Member

Could you add a sample app for langchain instrumentation as well, so the usage with the distro can be demonstrated? Or are you planning to add it in another PR?

@rads-1996

Copy link
Copy Markdown
Member

LGTM, having a langchain sample would be quite useful.

@rads-1996 Radhika Gupta (rads-1996) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A change log entry should be added

Copilot AI review requested due to automatic review settings April 10, 2026 16:16

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 a LangChain/LangGraph → OpenTelemetry tracing bridge under src/genai/, emitting spans annotated with GenAI semantic convention attributes and providing a CallbackManager patching instrumentor.

Changes:

  • Introduces GenAI semantic convention constants and LangChain instrumentation implementation (tracer, utils, instrumentor).
  • Adds extensive unit + functional tests validating span naming, attributes, filtering, parent/child relationships, and content-recording gating.
  • Adds @langchain/core to dev dependencies (and lockfile updates).

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
test/internal/unit/genai/langchain/utils.test.ts Unit tests for LangChain utils attribute extraction/mapping.
test/internal/unit/genai/langchain/tracer.test.ts Unit tests for tracer lifecycle, filtering, parent/child, and caps.
test/internal/unit/genai/langchain/langchainTraceInstrumentor.test.ts Unit tests for CallbackManager patching and handler injection behavior.
test/internal/functional/langchain.test.ts End-to-end functional test using InMemorySpanExporter.
src/genai/utils.ts Adds attribute-value truncation helper (currently unused by LangChain code).
src/genai/semconv.ts Adds GenAI semconv constants used by instrumentation/tests.
src/genai/instrumentations/langchain/utils.ts Extracts operation/model/provider/messages/tool/session/token attributes from LangChain runs.
src/genai/instrumentations/langchain/tracer.ts Implements BaseTracer bridge to create/end OTel spans per LangChain run.
src/genai/instrumentations/langchain/langchainTraceInstrumentor.ts Implements an OTel InstrumentationBase wrapper that patches LangChain CallbackManager handlers.
src/genai/instrumentations/langchain/index.ts Re-exports LangChain tracer/instrumentor.
src/genai/index.ts Re-exports GenAI semconv constants.
package.json Adds @langchain/core devDependency.
package-lock.json Lockfile updates including @langchain/core and related packages.

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

Comment thread src/genai/instrumentations/langchain/tracer.ts
Comment thread src/genai/instrumentations/langchain/utils.ts
Comment thread src/genai/instrumentations/langchain/utils.ts
Comment thread src/genai/instrumentations/langchain/utils.ts
Comment thread src/genai/instrumentations/langchain/utils.ts
Comment thread src/genai/utils.ts
Comment thread src/genai/instrumentations/langchain/index.ts
Comment thread src/genai/instrumentations/langchain/index.ts
Comment thread package.json
Comment thread src/genai/index.ts
@hectorhdzg
Hector Hernandez (hectorhdzg) merged commit a29a246 into microsoft:main Apr 10, 2026
5 checks passed
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