Sentry
Sentry helps you monitor errors, traces, latency, and
token usage for AI applications. Sentry's Next.js and Node.js SDKs instrument
AI SDK v7 through the native Node.js telemetry channel, so you do not need
@ai-sdk/otel
or registerTelemetry to send AI SDK traces to Sentry.
Sentry captures spans for generateText, streamText, model calls, tool calls,
embeddings, reranking, token usage, and errors. Add a functionId with the AI
SDK telemetry option to make traces easier to find and group in Sentry.
AI SDK v7 support requires @sentry/node, @sentry/nextjs, or another Sentry
server SDK version 10.62.0 or later. The native telemetry channel is
available in the Node.js runtime; use a Node.js route or server process for
these traces.
Setup
If Sentry is already configured in your application, skip to Usage. Otherwise, install and initialize the Sentry SDK for your runtime before running AI SDK calls.
Next.js
The Sentry wizard can create the full Next.js setup for you. The snippets below show the server-side pieces relevant to AI SDK traces:
Create or update your Sentry server config and enable tracing with
tracesSampleRate or tracesSampler:
If you are setting up Sentry manually in Next.js, make sure your
instrumentation.ts loads the server config for the Node.js runtime:
Node.js
Initialize Sentry at the start of your server entry point and enable tracing with
tracesSampleRate or tracesSampler:
The Vercel AI integration is enabled by default in Sentry server SDKs. If you have disabled default integrations, add it back explicitly:
Usage
Use the AI SDK normally. No registerTelemetry(new OpenTelemetry()) call and no
telemetry.isEnabled: true flag are required for Sentry.
For a standalone Node.js script, wrap the AI SDK call in a Sentry span so the AI spans have a parent trace, then flush before the process exits:
After the request runs, open Sentry and look for gen_ai.invoke_agent,
gen_ai.generate_content, and gen_ai.execute_tool spans in your traces.
Recording prompts and responses
By default, Sentry records metadata such as model, provider, latency, token usage, and errors. Prompt and response content are only sent if you opt in.
Enable content capture globally with Sentry's dataCollection.genAI options:
Or enable it for one AI SDK call with the telemetry option:
To opt out of Sentry AI telemetry for a sensitive call, set telemetry.isEnabled
to false.