LangChain
Adds instrumentation for LangChain.
This integration works in the Node.js, Cloudflare Workers, and Vercel Edge Functions runtimes. It requires SDK version 10.22.0 or higher.
Import name: Sentry.langChainIntegration
The langChainIntegration adds instrumentation for LangChain to capture spans by automatically wrapping LangChain operations and recording AI agent interactions with configurable input/output recording.
It is enabled by default and will automatically capture spans for LangChain operations including chat models, LLM invocations, chains, and tool executions. You can opt-in to capture inputs and outputs by setting recordInputs and recordOutputs in the integration config:
Sentry.init({
dsn: "____PUBLIC_DSN____",
tracesSampleRate: 1.0,
integrations: [
Sentry.langChainIntegration({
recordInputs: true,
recordOutputs: true,
}),
],
});
Type: boolean
Records inputs to LangChain operations (such as prompts and messages).
Defaults to true if sendDefaultPii is true.
Sentry.init({
integrations: [Sentry.langChainIntegration({ recordInputs: true })],
});
Type: boolean
Records outputs from LangChain operations (such as generated text and responses).
Defaults to true if sendDefaultPii is true.
Sentry.init({
integrations: [Sentry.langChainIntegration({ recordOutputs: true })],
});
By default this integration adds tracing support for LangChain operations including:
- Chat model invocations (
gen_ai.chat) - Captures spans for chat model calls - LLM invocations (
gen_ai.pipeline) - Captures spans for LLM pipeline executions - Chain executions (
gen_ai.invoke_agent) - Captures spans for chain invocations - Tool executions (
gen_ai.execute_tool) - Captures spans for tool calls
The integration automatically instruments the following LangChain runnable methods:
invoke()- Single executionstream()- Streaming executionbatch()- Batch execution
The automatic instrumentation supports the following LangChain provider packages:
@langchain/anthropic@langchain/openai@langchain/google-genai@langchain/mistralai@langchain/google-vertexai@langchain/groq
langchain:>=0.1.0 <1.0.0
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").