« All posts

Exporting Next.js Traces with OpenTelemetry

Next.js automatically traces requests, but you need an exporter to see them. Learn how @vercel/otel sends traces to Sentry or any OTLP backend.

Next.js already generates OpenTelemetry-compatible spans for incoming requests, fetch calls, middleware, and server-side rendering, but without a configured exporter those traces go nowhere. Vercel's @vercel/otel library lets you wire up an OpenTelemetry SDK in a single instrumentation.ts file, automatically handling Node vs Edge runtime differences, and just two environment variables are enough to ship traces to Sentry's direct OTLP endpoint.

Because the built-in spans are generic, real value comes from adding custom spans around business-critical operations like PDF generation, payment charges, or AI calls, using dotted naming conventions and low-cardinality attributes (plan tier, item counts, file sizes) to make traces searchable later. Custom spans, however, only work in the Node runtime — Edge support requires the @sentry/nextjs SDK instead.

The piece also weighs direct OTLP export against the full Sentry SDK: the OTLP route is a minimal, low-code way to get server-side traces, while browser tracing, error monitoring, session replay, and logs require the full SDK. For teams setting up tracing for the first time, especially on Next.js, the author recommends starting with the Sentry SDK.

» SourceSentry Blog