Set Up Agent Tracing

Monitor agents with token usage, latency, tool execution, and error tracking.

With Sentry Agent Tracing, you can monitor and debug your AI systems with full-stack context. You'll be able to track key insights like token usage, latency, tool usage, and error rates — and group multi-turn chats in Conversations. Agent Tracing data is fully connected to your other Sentry data like logs, errors, and traces.

Agent-Assisted Setup
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up Sentry.
Your agent will set up Sentry automatically. Works with Cursor, Claude Code, Codex, and more.View docs ↗
Install the full plugin

Install the Sentry plugin to give your assistant every skill. See the installation docs for more details.

Copied
npx @sentry/ai install

Enable tracing and pass dataCollection so generative AI content follows the SDK defaults (including prompts and responses when left unconfigured).

dataCollection: {} also opts into other permissive defaults (bodies, cookies, user info, and more). Tighten via dataCollection.

Copied
import * as Sentry from "___SDK_PACKAGE___";

Sentry.init({
  dsn: "___PUBLIC_DSN___",
  tracesSampleRate: 1.0,
  dataCollection: {},
});

Pick your AI stack. Some libraries auto-instrument; others need a short setup — each page has the details.

Conversations groups multi-turn AI activity into a single replay of messages and tool calls. Use setConversationId() so every AI span in a chat session shares the same gen_ai.conversation.id.

Some integrations infer a conversation ID automatically. For everything else (including Workers AI), set it yourself at the start of every request or operation that makes AI calls, before those calls run. Reuse the same session ID across messages in the chat. The ID is applied to AI-related spans on the current isolation scope (which is typically request-scoped). Pass null to unset it.

Copied
Sentry.setConversationId("conv_abc123");

The Conversations view includes a User column. To populate it, call setUser once per request or session, before any AI calls:

Copied
Sentry.setUser({
  id: "user_123",
  email: "jane@example.com",
  username: "jane",
});

Any of id, email, or username is sufficient — the Conversations view displays whichever fields are present. See the setUser API reference for the full list of supported fields.

With dataCollection: {} (or any dataCollection config), generative AI inputs and outputs default to on. To turn them off:

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  dataCollection: {
    genAI: { inputs: false, outputs: false },
  },
});

You can also set recordInputs / recordOutputs on a specific AI integration. See each integration page for the API that applies on your platform.

From SDK 10.61.0, gen_ai spans are sent as standalone envelope items (avoids large-payload drops; required for Conversations).

Self-hosted Sentry users should set streamGenAiSpans: false if standalone gen_ai spans may not be ingested.

Copied
Sentry.init({
  dsn: "___PUBLIC_DSN___",
  streamGenAiSpans: false,
});

You can also instrument agent spans yourself. See manual instrumentation.

If you're using an AI framework with a Sentry exporter, you can send traces to Sentry:

If you're building MCP (Model Context Protocol) servers, Sentry can also track tool executions, prompt retrievals, and resource access. See Instrument MCP Servers for setup instructions.

Was this helpful?
Help improve this content
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").