Skip to main content
The LangChain integration automatically instruments LangChain applications by injecting Sentry callback handlers into all runnable instances.

Installation

The integration is enabled by default in Node.js:

Basic Usage

Just use LangChain normally:

Configuration

Default Behavior

By default, inputs and outputs are not captured:

Capture Inputs and Outputs

Enable for all AI integrations:

Integration Options

boolean
default:"sendDefaultPii"
Capture input messages and prompts
boolean
default:"sendDefaultPii"
Capture responses and outputs

Automatic Instrumentation

The integration automatically instruments:

LLM and Chat Models

Chains

Tools

Captured Events

The integration captures these LangChain lifecycle events:
1

LLM/Chat Start

When a language model call begins
2

LLM/Chat End

When a language model call completes
3

LLM/Chat Error

When a language model call fails
4

Chain Start

When a chain execution begins
5

Chain End

When a chain execution completes
6

Chain Error

When a chain execution fails
7

Tool Start

When a tool is invoked
8

Tool End

When a tool execution completes
9

Tool Error

When a tool execution fails

Manual Callback Handler

You can also manually add the Sentry callback handler:

Practical Examples

Question Answering Chain

RAG (Retrieval-Augmented Generation)

Agent with Tools

Streaming Responses

Provider Integration

LangChain automatically disables OpenAI, Anthropic, and Google GenAI integrations to prevent duplicate spans.
When using LangChain, provider integrations are skipped:
Direct SDK usage still creates provider spans:

Viewing LangChain Data

LangChain operations appear as spans in traces:

Performance Monitoring

  • Chain Execution Time: Track complex workflow performance
  • LLM Latency: Monitor model response times
  • Tool Performance: Identify slow tool executions
  • Error Rates: Track failures in chains and tools

Source Code

The LangChain integration is implemented in: packages/node/src/integrations/tracing/langchain/index.ts:11

Privacy Best Practices

Use recordInputs and recordOutputs selectively based on data sensitivity.

Filter Sensitive Prompts

Troubleshooting

Spans Not Appearing

Ensure tracing is enabled:

Duplicate Spans

If you see duplicate spans, ensure you’re not manually instrumenting providers that LangChain already handles.

Custom Callbacks

To use custom callbacks alongside Sentry: