← Back to Cookbook

Route your existing OpenTelemetry traces to Sentry with Next.js

Keep your vendor-neutral OpenTelemetry instrumentation and start seeing your Next.js traces in Sentry. No SDK migration required.

Features
SDKs
Category Workflow
Time
15–20 minutes
Difficulty
Beginner
Steps
4 steps

Before you start

SDKs & packages
  • A Next.js app (v13.4+) with OpenTelemetry instrumentation already set up
  • Node.js 18+
Accounts & access
Knowledge
  • Basic familiarity with Next.js
  • Basic understanding of what OpenTelemetry traces are

1
Get your Sentry OTLP credentials

Sentry exposes a standard OTLP endpoint for each project. Open your project in Sentry, go to Settings > Client Keys (DSN) and switch to the OpenTelemetry tab. Copy both values below and paste them into your environment variables in Step 2:

  • The Traces endpoint URL, which looks like https://o{ORG_ID}.ingest.us.sentry.io/api/{PROJECT_ID}/integration/otlp/v1/traces
  • Your public key, the value after sentry_key= in the DSN
Sentry OTLP concepts

2
Set your environment variables

Add these three variables to your .env.local. Substitute the endpoint URL and public key you copied in Step 1. The OTEL_EXPORTER_OTLP_TRACES_HEADERS value is a full header string. The key is x-sentry-auth and the value is sentry sentry_key=. Most OTLP exporters parse this format automatically.

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://o{ORG_ID}.ingest.us.sentry.io/api/{PROJECT_ID}/integration/otlp/v1/traces
OTEL_EXPORTER_OTLP_TRACES_HEADERS=x-sentry-auth=sentry sentry_key={YOUR_PUBLIC_KEY}
OTEL_SERVICE_NAME=my-nextjs-app

3
Enable the instrumentation hook

In Next.js 15+, the instrumentation.ts file is picked up automatically. If you're on Next.js 13 or 14, add the instrumentationHook experimental flag to your config to opt in.

/** @type {import('next').NextConfig} */
const nextConfig = {
  experimental: {
    instrumentationHook: true,
  },
}

module.exports = nextConfig

4
Verify your traces in Sentry

Start your dev server and trigger a few requests (page loads, API routes, or server actions). Within 30–60 seconds, your traces should appear in Sentry. Open the Trace Explorer and filter by your service name (my-nextjs-app or whatever you set in OTEL_SERVICE_NAME). You'll see a waterfall view of your spans: Next.js routes, fetch calls, database queries, and anything else your auto-instrumentation captures.

Sentry Trace Explorer documentation

That's it.

Your traces are in Sentry.

Two environment variables is all it took. Your OpenTelemetry instrumentation is still vendor-neutral, and Sentry is now your observability backend.

  • Located your Sentry OTLP credentials
  • Pointed your existing OTel traces at Sentry using environment variables
  • Verified spans flowing into the Sentry Trace Explorer

Pro tips

  • πŸ’‘ Set OTEL_SERVICE_NAME to something distinct per service. It's how Sentry groups spans in the Trace Explorer and makes multi-service traces readable at a glance.
  • πŸ’‘ If you're using @vercel/otel, add NEXT_OTEL_VERBOSE=1 during development to log every span to the console and confirm your instrumentation is working before checking Sentry.
  • πŸ’‘ If you're already exporting to another observability backend, you can run a second exporter in parallel using the manual NodeSDK setup. No need to pick one or the other.

Common pitfalls

  • ⚠️ If your instrumentation.ts file isn't being picked up, check that it's in the project root or src/ folder. Next.js won't load it from inside app/ or pages/.
  • ⚠️ The @opentelemetry/sdk-node package (and @vercel/otel) doesn't run in the Edge Runtime. If your app uses edge routes, guard with if (process.env.NEXT_RUNTIME === 'nodejs') before registering the SDK.
  • ⚠️ A wrong authentication header format is the most common cause of 401 errors from the Sentry OTLP endpoint. The full header value must be sentry sentry_key={YOUR_KEY}, not just the key alone.

Frequently asked questions

No. The OTLP endpoint is completely separate from the Sentry SDK. You can send traces purely through the OpenTelemetry exporter without installing any @sentry/* package. That said, pairing OTLP traces with the Sentry SDK gives you error monitoring, session replay, and richer context on your traces.
Yes. If you already have instrumentation.ts and an OTLP exporter configured, all you need to do is update OTEL_EXPORTER_OTLP_TRACES_ENDPOINT and OTEL_EXPORTER_OTLP_TRACES_HEADERS to point at Sentry. No code changes required.
Yes, it's available on all Sentry plans including the free Developer tier. Traces count toward your transaction quota, so check your plan limits if you're on a paid plan with high volume.
Yes. Using the manual NodeSDK setup (instead of @vercel/otel), you can add multiple span processors with different exporters: one pointing at Sentry and one at your existing backend. This is a low-risk way to evaluate Sentry without committing to a full migration.
Yes. The instrumentation.ts file and OTLP configuration work with both routing strategies. Next.js auto-instruments server components, API routes, and server actions regardless of which router you use.

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.