Skip to main content
Observability is crucial for understanding the behavior and performance of your Next.js application. Next.js has built-in OpenTelemetry support—framework internals are already instrumented with spans. OpenTelemetry is platform-agnostic: you can switch observability providers without changing your code.

Getting started

The quickest way to add OpenTelemetry is with the @vercel/otel package.

Using @vercel/otel

1

Install packages

2

Create instrumentation.ts

Create an instrumentation.ts file in the root of your project (or in /src if you use that layout):
The instrumentation file must be in the project root, not inside app/ or pages/.

Manual configuration

For full control over the OpenTelemetry SDK, configure it manually. Because NodeSDK is not compatible with the Edge runtime, conditionally import it:

Testing your instrumentation

Use the OpenTelemetry dev environment to test traces locally. When working correctly, you should see a root span labeled GET /requested/pathname with all other spans from that trace nested under it. To see additional spans:

Custom spans

Add custom spans using the OpenTelemetry API:

Default spans

Next.js automatically instruments the following spans: Span attributes follow OpenTelemetry semantic conventions plus custom next.* attributes:
  • next.span_name — Duplicates the span name
  • next.span_type — Unique identifier for the span type
  • next.route — Route pattern (e.g., /[param]/user)
  • next.rsc — Whether the request is an RSC prefetch request
  • next.page — Internal path to a special file (e.g., page.ts, layout.ts)
Set NEXT_OTEL_FETCH_DISABLED=1 to disable automatic instrumentation of fetch calls if you use a custom fetch instrumentation library.

Deployment

Vercel

OpenTelemetry works out of the box on Vercel. Follow the Vercel observability quickstart to connect to an observability provider.

Self-hosted

Spin up an OpenTelemetry Collector to receive and process telemetry from your Next.js app, then configure @vercel/otel or a custom exporter to send data to the collector.