Set Up Agent Tracing for Node.jsNEW
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.
Use curl to download, read and follow https://skills.sentry.dev/instrument to set up Sentry.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.
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.
Sentry.setConversationId("conv_abc123");
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:
Sentry.setUser({
id: "user_123",
email: "jane@example.com",
username: "jane",
});
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:
Sentry.init({
dsn: "___PUBLIC_DSN___",
dataCollection: {
genAI: { inputs: false, outputs: false },
},
});
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).
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.
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").