LangGraph
Adds instrumentation for LangGraph.
This integration works in the Node.js, Cloudflare Workers, Vercel Edge Functions, and browser runtimes. It requires SDK version 10.25.0 or higher.
Import name: Sentry.langGraphIntegration
LangGraph is instrumented via the langGraphIntegration, which automatically captures spans for LangGraph operations including agent invocations, graph executions, and node operations.
It is enabled by default and will automatically capture spans for LangGraph operations. 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.langGraphIntegration({
recordInputs: true,
recordOutputs: true,
}),
],
});
import { ChatOpenAI } from "@langchain/openai";
import {
StateGraph,
MessagesAnnotation,
START,
END,
} from "@langchain/langgraph";
// Create LLM call
const llm = new ChatOpenAI({
modelName: "gpt-4o",
apiKey: process.env.OPENAI_API_KEY,
});
async function callLLM(state) {
const response = await llm.invoke(state.messages);
return {
messages: [...state.messages, response],
};
}
// Create the agent
const agent = new StateGraph(MessagesAnnotation)
.addNode("agent", callLLM)
.addEdge(START, "agent")
.addEdge("agent", END);
const compiledAgent = agent.compile({ name: "my_agent" });
// Invoke the agent - automatically instrumented
const result = await compiledAgent.invoke({
messages: [
new SystemMessage("You are a helpful assistant."),
new HumanMessage("Hello!"),
],
});
Type: boolean
Records inputs to LangGraph operations (such as messages and state data passed to the graph).
Defaults to true if sendDefaultPii is true.
Sentry.init({
integrations: [Sentry.langGraphIntegration({ recordInputs: true })],
});
Type: boolean
Records outputs from LangGraph operations (such as generated responses, agent outputs, and final state).
Defaults to true if sendDefaultPii is true.
Sentry.init({
integrations: [Sentry.langGraphIntegration({ recordOutputs: true })],
});
By default this integration adds tracing support for LangGraph operations including:
- Agent Creation (
gen_ai.create_agent) - Captures spans when compiling a StateGraph into an executable agent - Agent Invocation (
gen_ai.invoke_agent) - Captures spans for agent execution viainvoke()
@langchain/langgraph:>=0.2.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").