Skip to content

Latest commit

 

History

History
214 lines (145 loc) · 6.86 KB

File metadata and controls

214 lines (145 loc) · 6.86 KB
title LangGraph
description Adds instrumentation for the LangGraph SDK.
supported
javascript.node
javascript.aws-lambda
javascript.azure-functions
javascript.connect
javascript.express
javascript.fastify
javascript.gcp-functions
javascript.hapi
javascript.hono
javascript.koa
javascript.nestjs
javascript.electron
javascript.nextjs
javascript.nuxt
javascript.solidstart
javascript.sveltekit
javascript.react-router
javascript.remix
javascript.astro
javascript.bun
javascript.tanstackstart-react
javascript.cloudflare
javascript
javascript.react
javascript.angular
javascript.vue
javascript.svelte
javascript.solid
javascript.ember
javascript.gatsby

<PlatformSection notSupported={["javascript", "javascript.react", "javascript.angular", "javascript.vue", "javascript.svelte", "javascript.solid", "javascript.ember", "javascript.gatsby"]}>

Server-Side Usage

<PlatformSection supported={["javascript.nextjs", "javascript.nuxt", "javascript.solidstart", "javascript.sveltekit", "javascript.react-router", "javascript.remix", "javascript.astro", "javascript.tanstackstart-react"]}>

For meta-framework applications using all runtimes, you need to manually wrap your graph before compiling with instrumentLangGraph. See instructions in the Browser-Side Usage section.

<PlatformSection notSupported={["javascript.nextjs", "javascript.nuxt", "javascript.solidstart", "javascript.sveltekit", "javascript.react-router", "javascript.remix", "javascript.astro", "javascript.tanstackstart-react"]}>

Import name: Sentry.langGraphIntegration

The langGraphIntegration adds instrumentation for @langchain/langgraph to capture spans by automatically wrapping LangGraph operations and recording AI agent interactions including agent invocations, graph executions, and node operations.

<PlatformSection notSupported={["javascript.bun", "javascript.cloudflare"]}>

Enabled by default and automatically captures spans for LangGraph SDK calls. Requires Sentry SDK version 10.28.0 or higher.

<PlatformSection supported={["javascript.bun", "javascript.cloudflare"]}>

Enabled by default and automatically captures spans for LangGraph SDK calls. Requires Sentry SDK version 10.28.0 or higher.

For other runtimes, like the Browser, the instrumentation needs to be manually enabled. See the setup instructions below.

To customize what data is captured (such as inputs and outputs), see the Options in the Configuration section.

<PlatformSection supported={["javascript", "javascript.react", "javascript.angular", "javascript.vue", "javascript.svelte", "javascript.solid", "javascript.ember", "javascript.gatsby", "javascript.nextjs", "javascript.nuxt", "javascript.solidstart", "javascript.sveltekit", "javascript.react-router", "javascript.remix", "javascript.astro", "javascript.tanstackstart-react", "javascript.electron", "javascript.cloudflare"]}>

Browser-Side Usage

Import name: Sentry.instrumentLangGraph

<PlatformSection supported={["javascript.cloudflare"]}>

For Cloudflare Workers, manual instrumentation is required using instrumentLangGraph.

The instrumentLangGraph helper adds instrumentation for @langchain/langgraph to capture spans by wrapping a StateGraph before compilation and recording AI agent interactions with configurable input/output recording. You need to call this helper on the graph before calling .compile(). See example below:

import { ChatOpenAI } from "@langchain/openai";
import { StateGraph, MessagesAnnotation, START, END } from '@langchain/langgraph';
import { SystemMessage, HumanMessage } from '@langchain/core/messages';

// Create LLM call
const llm = new ChatOpenAI({
  modelName: "gpt-4o",
  apiKey: "your-api-key", // Warning: API key will be exposed in browser!
});

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);

// Instrument the graph before compiling
Sentry.instrumentLangGraph(agent, {
  recordInputs: true,
  recordOutputs: true,
});

const graph = agent.compile({ name: 'my_agent' });

// Invoke the agent
const result = await graph.invoke({
  messages: [
    new SystemMessage("You are a helpful assistant."),
    new HumanMessage("Hello!"),
  ],
});

To customize what data is captured (such as inputs and outputs), see the Options in the Configuration section.

Configuration

Options

The following options control what data is captured from LangGraph operations:

recordInputs

Type: boolean (optional)

Records inputs to LangGraph operations (such as messages and state data passed to the graph).

Defaults to true if sendDefaultPii is true.

recordOutputs

Type: boolean (optional)

Records outputs from LangGraph operations (such as generated responses, agent outputs, and final state).

Defaults to true if sendDefaultPii is true.

Usage

<PlatformSection notSupported={["javascript", "javascript.react", "javascript.angular", "javascript.vue", "javascript.svelte", "javascript.solid", "javascript.ember", "javascript.gatsby"]}>

Using the langGraphIntegration integration:

Sentry.init({
  dsn: "____PUBLIC_DSN____",
  // Tracing must be enabled for agent monitoring to work
  tracesSampleRate: 1.0,
  integrations: [
    Sentry.langGraphIntegration({
      // your options here
    }),
  ],
});

<PlatformSection supported={["javascript", "javascript.react", "javascript.angular", "javascript.vue", "javascript.svelte", "javascript.solid", "javascript.ember", "javascript.gatsby", "javascript.nextjs", "javascript.nuxt", "javascript.solidstart", "javascript.sveltekit", "javascript.react-router", "javascript.remix", "javascript.astro", "javascript.tanstackstart-react", "javascript.electron", "javascript.cloudflare"]}>

Using the instrumentLangGraph helper:

Sentry.instrumentLangGraph(graph, {
  // your options here
});

Supported Operations

By default, tracing support is added to the following LangGraph SDK calls:

  • 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 via invoke()

Supported Versions

  • @langchain/langgraph: >=0.2.0 <2.0.0