SentryKyle TryonTutorial
Next.js already traces your requests. Here's how to export them with OpenTelemetry.
Summary
Next.js provides out-of-the-box tracing for incoming requests, fetch calls, middleware, and server-side rendering, but traces remain invisible without a configured exporter. Developers can use the @vercel/otel package inside an instrumentation file to initialize the OpenTelemetry SDK and transmit traces to any OTLP-compatible destination. While Next.js automatically creates spans for standard request lifecycles, developers can define custom active spans in the Node runtime to capture specific domain operations and contextual attributes. Exporting traces to backends like Sentry requires configuring standard OTLP endpoint and authentication environment variables. Choosing between direct OTLP export via @vercel/otel and the dedicated Sentry SDK depends on requirements, as direct export lacks browser tracing, error monitoring, and Edge custom spans.
Context
Next.js automatically captures traces across requests, server-side rendering, middleware, and fetch calls, but these traces are not visible unless an exporter is configured. Diagnosing slow pages without execution traces forces developers to guess bottlenecks from symptoms and reproduction attempts.
Approach / What changed
Configure the OpenTelemetry SDK using @vercel/otel in the project root instrumentation.ts file to export traces to an OTLP-compatible backend like Sentry. Set the standard OTEL_EXPORTER_OTLP_TRACES_ENDPOINT and OTEL_EXPORTER_OTLP_TRACES_HEADERS environment variables, and optionally enrich traces with custom spans in the Node runtime using @opentelemetry/api.
Takeaways
@vercel/otel configures the OpenTelemetry SDK across Node and Edge runtimes, automatically loaded through Next.js startup via the register function in instrumentation.ts.
Custom spans created via @opentelemetry/api allow developers to track domain logic and attach attributes, but @vercel/otel only supports custom spans in the Node runtime, not the Edge runtime.
Direct OTLP exporting via @vercel/otel avoids SDK overhead but omits browser tracing, error monitoring, session replay, and source-mapped stack traces provided by @sentry/nextjs.
Source and freshness
- Source
- blog.sentry.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.