Set Up Agent Tracing for CloudflareNEW

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/agent-plugin install

As of SDK version 11.0.0, Sentry auto-instruments the most popular AI SDKs and frameworks out of the box — no manual setup is required. Just enable tracing, then pick your AI stack below. Each integration page has the details.

A Cloudflare AI application can need three independent layers. Inspect the host, every model client it calls, and its conversation IDs instead of stopping after the first integration:

  1. Instrument the host. Use the Vite plugin, which wraps your Worker and your Agents SDK classes at build time. If you deploy with wrangler directly, wrap them yourself as shown in the Wrangler setup.
  2. Instrument each model client. Workers AI (env.AI) is automatic when the Sentry host wrapper supplies the instrumented env. For bundled provider SDKs, use Vite build-time instrumentation or the provider's manual wrapper. Follow the matching integration page for Vercel AI, LangChain, LangGraph, or another library.
  3. Group the conversation. The Agents SDK can infer a conversation ID. For other chat applications, including Workers AI without the Agents SDK, set one before the model or tool calls. See Tracking Conversations.

For example, an Agents SDK class that calls env.AI.run() needs the Agents SDK host setup and Workers AI model instrumentation. The host wrapper supplies the instrumented binding, so do not add another provider wrapper around the same env.AI call.

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 tab displays whichever fields are present. See the setUser API reference for the full list of supported fields.

The SDK records generative AI inputs and outputs by default. To turn them off:

src/instrument.server.ts
Copied
import { defineCloudflareOptions } from "@sentry/cloudflare";

export default defineCloudflareOptions((env) => ({
  dsn: "___PUBLIC_DSN___",
  tracesSampleRate: 1.0,
  dataCollection: {
    genAI: { inputs: false, outputs: false },
  },
}));

On Cloudflare, control Vercel AI I/O with integration-level record* options or with experimental_telemetry per call. See each integration page.

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

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

If you're building MCP (Model Context Protocol) servers, Sentry can also track tool executions, prompt retrievals, and resource access. See MCP Monitoring 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").