← Back to Cookbook

Send Vercel AI SDK telemetry to Sentry via OpenTelemetry

Keep your existing Vercel AI SDK and @vercel/otel setup, and export your LLM spans to Sentry over OTLP. Sentry still captures your errors and links them to the active trace.

SDKs
Category Monitoring
Time
15–20 minutes
Complexity
Intermediate
Steps
5 steps

Before you start

SDKs & packages
  • A project already using Vercel AI SDK 7 with @vercel/otel instrumentation
  • Sentry set up with @sentry/nextjs 11 or later, including sentry.server.config.ts and sentry.edge.config.ts. If Sentry isn't set up yet, follow the Next.js setup guide first
  • Node.js 22+ (required by AI SDK 7)
Accounts & access
Knowledge
  • Basic familiarity with OpenTelemetry concepts (spans, span processors, exporters)
  • Familiarity with the Vercel AI SDK generateText / streamText APIs

1
Install the OTLP exporter and AI SDK telemetry packages

Sentry receives OpenTelemetry spans over OTLP, so you need an OTLP exporter and a span processor. AI SDK 7 also moved its OpenTelemetry support into a separate @ai-sdk/otel package. Keep your existing @vercel/otel and ai packages. They don't change.

Use your own OpenTelemetry pipeline with Sentry
Install dependencies
npm install @ai-sdk/otel @opentelemetry/exporter-trace-otlp-http @opentelemetry/sdk-trace-base

2
Initialize Sentry without its own OpenTelemetry setup

With this setup, @vercel/otel owns tracing and Sentry owns errors. Set enableOpenTelemetrySetup: false so Sentry doesn't try to register a second tracer provider, and leave tracesSampleRate unset so Sentry doesn't create its own spans for the same requests. Then add openTelemetryIntegration() to link Sentry errors, logs, and metrics to the active OpenTelemetry span.

openTelemetryIntegration reference
sentry.server.config.ts
import * as Sentry from "@sentry/nextjs";

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  // @vercel/otel owns tracing, so leave tracesSampleRate unset
  enableOpenTelemetrySetup: false,
  integrations: [Sentry.openTelemetryIntegration()],
});

3
Export your spans to Sentry from registerOTel

Sentry.getOtlpTracesEndpoint() turns your DSN into the URL and auth headers of your project's OTLP endpoint. Pass it to an OTLPTraceExporter and add that exporter to spanProcessors. The "auto" entry keeps Vercel's default export, so your existing setup keeps working. You're adding Sentry as a destination, not replacing anything.

In the same register() function, call registerTelemetry(new OpenTelemetry()). In AI SDK 7, this is what makes the AI SDK emit OpenTelemetry spans. Register your OpenTelemetry provider before Sentry initializes, which is why the Sentry config is imported last.

Send OpenTelemetry spans to Sentry
instrumentation.ts
// instrumentation.ts
import { registerOTel } from "@vercel/otel";
import { registerTelemetry } from "ai";
import { OpenTelemetry } from "@ai-sdk/otel";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
import * as Sentry from "@sentry/nextjs";

export async function register() {
  // undefined when SENTRY_DSN is missing or invalid, for example in local dev
  const sentryOtlp = Sentry.getOtlpTracesEndpoint(process.env.SENTRY_DSN ?? "");

  registerOTel({
    serviceName: "vercel-ai-otel-sentry-demo",
    spanProcessors: [
      "auto",
      ...(sentryOtlp
        ? [new BatchSpanProcessor(new OTLPTraceExporter(sentryOtlp))]
        : []),
    ],
  });

  // AI SDK 7: send AI SDK telemetry to your OpenTelemetry provider
  registerTelemetry(new OpenTelemetry());

  // Initialize Sentry after the provider is registered
  if (process.env.NEXT_RUNTIME === "edge") {
    await import("./sentry.edge.config");
  } else {
    await import("./sentry.server.config");
  }
}

export const onRequestError = Sentry.captureRequestError;

4
Name your LLM calls with telemetry metadata

In AI SDK 7, telemetry is on by default once an integration is registered, and experimental_telemetry is now telemetry. You don't need isEnabled: true anymore. Add a stable functionId to each call so you can tell related runs apart in your traces.

The AI SDK records inputs and outputs by default, which is useful while debugging. Set recordInputs and recordOutputs to false if your prompts can contain sensitive data.

Vercel AI SDK telemetry docs
Example generateText call
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

const { text } = await generateText({
  model: openai("gpt-5-mini"),
  prompt,
  telemetry: {
    functionId: "summarize-article",
  },
});

5
Verify your AI spans in Sentry

Run your app and trigger an LLM call. Within a minute, open the Trace Explorer in Sentry and filter by your serviceName. Click into a trace to see the span waterfall. The AI SDK spans sit next to the HTTP, fetch, and custom spans from the rest of your app, with the model, token counts, latency, and (if you record them) the full prompt and completion.

Your AI spans also show up in Explore → Agents, where you can compare models, token usage, and cost across calls.

Agents documentation
Sentry trace view showing a gen_ai.invoke_agent span from the Vercel AI SDK with model, token counts, and latency attributes

That's it.

Your LLM calls are in Sentry.

Your OpenTelemetry pipeline is unchanged, Vercel AI SDK keeps emitting standard spans, and Sentry is now your observability backend for every model invocation.

  • Configured Sentry SDK v11 to run next to an existing @vercel/otel pipeline
  • Added Sentry's OTLP endpoint as a span exporter in registerOTel
  • Registered the AI SDK OpenTelemetry integration with registerTelemetry
  • Found your LLM spans in Sentry's Trace Explorer and Explore → Agents

Pro tips

  • 💡 Use a distinct functionId per AI task (summarize-article, classify-support-ticket) so related runs are easy to group and regressions are easy to spot.
  • 💡 Set a meaningful serviceName in registerOTel. It's the easiest way to filter spans by service in the Trace Explorer, which matters the moment you have more than one worker.
  • 💡 Sentry's tracesSampleRate doesn't control spans you export over OTLP. Keep the default of tracing every request while you set this up, then set traceSampler in registerOTel once you trust the pipeline.
  • 💡 Attach request-scoped context with runtimeContext (user ID, tenant, feature flag) and list the keys to send in telemetry.includeRuntimeContext, so you can filter traces by those attributes in Sentry. Keys you don't list stay out of your telemetry.

Common pitfalls

  • ⚠️ Setting tracesSampleRate while @vercel/otel owns tracing. Sentry then creates its own spans for the same requests, and you get two copies of every operation in two pipelines that never join up.
  • ⚠️ Leaving out "auto" from spanProcessors. That removes Vercel's default export, and your traces stop reaching any destination you already had.
  • ⚠️ Skipping registerTelemetry(new OpenTelemetry()) on AI SDK 7. The AI SDK no longer emits OpenTelemetry spans on its own, so your LLM calls quietly disappear from your traces.
  • ⚠️ Initializing Sentry before registerOTel. Register your OpenTelemetry provider first, then import your Sentry config, as shown in Step 3.
  • ⚠️ Expecting AI spans from the Edge runtime. The OTLP exporter in Step 3 only registers in the Node.js runtime, and Sentry's vercelAIIntegration is a no-op on Edge in SDK v11. Run your AI calls in Node.js route handlers.
  • ⚠️ Recording inputs in production can send user PII or secrets to Sentry as span attributes. Set recordInputs: false on calls that handle regulated data, or gate it behind an environment flag.

Frequently asked questions

No. @vercel/otel stays the owner of the OpenTelemetry pipeline. Sentry receives its spans through an extra OTLP exporter and handles errors on its own side. Your existing instrumentation keeps working.

Sentry JavaScript SDK v11 removed SentrySpanProcessor, SentrySampler, and SentryContextManager, and replaced skipOpenTelemetrySetup with enableOpenTelemetrySetup. If you followed an older version of this recipe, swap the Sentry components in registerOTel for the OTLP exporter in Step 3, and remove tracesSampleRate from Sentry.init().

If you don't need @vercel/otel, use Sentry's built-in vercelAIIntegration instead. It's enabled by default once Sentry tracing is on and needs less setup. The Monitor AI agent costs in Next.js recipe covers it. Use this recipe when OpenTelemetry already owns tracing in your app.

No. @vercel/otel and Sentry's OTLP endpoint work in any Node.js runtime. The registerOTel call is the same whether you're running Next.js, a standalone Node server, a worker, or a serverless function. Next.js just has a built-in instrumentation.ts entry point that makes the wiring convenient.

Use the SDK that matches your runtime: @sentry/nextjs for Next.js apps, @sentry/node for plain Node services, @sentry/bun, @sentry/aws-serverless, and so on. In SDK v11, every server SDK exports getOtlpTracesEndpoint() and openTelemetryIntegration(). On @sentry/nextjs, set enableOpenTelemetrySetup: false explicitly.

Yes. The OTLP exporter sits next to Vercel's "auto" processors, so every span your pipeline produces (HTTP, fetch, database, custom) reaches Sentry as part of the same trace.

Sentry bills tracing by span count, so recording inputs and outputs makes each span larger without adding spans to your quota. The bigger concern is privacy. If your prompts can contain user data, set recordInputs and recordOutputs to false in production, and control volume with traceSampler.

Fix it, don't observe it.

Get started with the only application monitoring platform that empowers developers to fix application problems without compromising on velocity.