OpenTelemetry for Next.js: Distributed Tracing, Custom Spans, and Structured Logging
console.log debugging is fine for local dev. In production, you need distributed tracing -- the ability to follow a request through every service, function call, and database query. OpenTelemetry (...

Source: DEV Community
console.log debugging is fine for local dev. In production, you need distributed tracing -- the ability to follow a request through every service, function call, and database query. OpenTelemetry (OTel) is the standard. Here's how to set it up in Next.js. What Distributed Tracing Gives You A trace shows the full lifecycle of one request: HTTP request arrives Middleware runs (auth check, rate limit) Route handler executes Database query (which query, how long) External API call (Stripe, OpenAI) Response sent When something is slow, you see exactly where the time went. When something fails, you see the exact stack trace in context. Setup: Vercel OTel (Simplest Path) npm install @vercel/otel // instrumentation.ts (at project root, next to package.json) export async function register() { if (process.env.NEXT_RUNTIME === 'nodejs') { const { registerOTel } = await import('@vercel/otel') registerOTel({ serviceName: 'my-app' }) } } Enable in next.config.js: /** @type {import('next').NextConfig