Monitoring & Observability

Set up production monitoring for Next.js — Core Web Vitals, error tracking, logging, performance monitoring, and the observability stack used in enterprise applications.

Last reviewed: January 2025

·Next.js 13Next.js 14Next.js 15
✅
Quick Understanding: Production monitoring for Next.js covers three areas: Core Web Vitals (user experience metrics), error tracking (Sentry for exceptions), and server-side observability (logs, traces, metrics). Set up all three before going live.

🔍 What Is It?

Production monitoring for Next.js has three layers:

  1. Core Web Vitals — LCP, CLS, INP, FID measured on real user devices

- Vercel Analytics (built-in), Google Search Console, Lighthouse CI

  1. Error tracking — catch and alert on exceptions in real-time

- Sentry (most popular), Datadog, Bugsnag

  1. Server observability — logs, traces, metrics for Route Handlers and SSR

- Vercel Logs, Datadog APM, OpenTelemetry

🎯 Why Do We Need It?

Without monitoring:

  • →You learn about errors from users, not dashboards
  • →Performance regressions go unnoticed until users complain
  • →Debugging production issues is guesswork

With monitoring:

  • →Errors are caught and alerted within seconds
  • →Performance regressions are detected before users notice
  • →Production debugging uses real data, not assumptions

🏗️ What Happens in Real Projects?

Monitoring stack for a production SaaS:

  • →Vercel Analytics — Core Web Vitals, page views, geography
  • →Sentry — JavaScript errors, server errors, performance traces
  • →Datadog — infrastructure metrics, custom business metrics
  • →Axiom — structured log search and dashboards
  • →Checkly — synthetic monitoring (run Playwright tests every 5 minutes)

⚙️ How It Works

Core Web Vitals measurement:

Next.js exposes a reportWebVitals function in the root layout or via the useReportWebVitals hook. It receives real user measurements and you send them to your analytics platform.

Error tracking with Sentry:

  • →Sentry SDK wraps Server Components, Route Handlers, and Client Components
  • →Unhandled errors are captured with full stack trace and context
  • →Errors are grouped by similarity and assigned to team members

💻 Example

Sentry and Web Vitals Setup — Production monitoring setup for a Next.js application.

ts
// sentry.client.config.ts
import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  environment: process.env.NODE_ENV,
  // Only capture errors in production
  enabled: process.env.NODE_ENV === 'production',
  // Sample rate: capture 10% of transactions for performance
  tracesSampleRate: 0.1,
  // Capture 100% of errors
  sampleRate: 1.0,
  // Ignore common noise
  ignoreErrors: [
    'ResizeObserver loop limit exceeded',
    'Network request failed',
  ],
});

// sentry.server.config.ts
import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  environment: process.env.NODE_ENV,
  enabled: process.env.NODE_ENV === 'production',
  tracesSampleRate: 0.1,
});

🤔 Common Confusions

❓ Is Vercel Analytics enough or do I need Sentry too?

They serve different purposes. Vercel Analytics measures user experience (Core Web Vitals, page views). Sentry catches and alerts on errors. You need both. Vercel Analytics tells you your LCP is slow; Sentry tells you your checkout is throwing a 500 error for 5% of users.

❓ How do I monitor Server Component errors?

Sentry's Next.js SDK automatically captures Server Component errors. Add error.tsx boundaries at each route level — Sentry captures the error before the boundary handles it. Also configure Sentry in sentry.server.config.ts for server-side error capture.

❓ What is the difference between LCP and FCP?

FCP (First Contentful Paint) is when any content first appears. LCP (Largest Contentful Paint) is when the main content (usually the hero image or heading) appears. LCP is the more important metric — it measures when users can see the primary content. Google's threshold: LCP < 2.5s is good.

🚨 Common Production Issues

Sentry capturing too many errors — noisy alerts cause alert fatigue. Configure ignoreErrors for known browser quirks and network errors. Set sampleRate: 0.1 for performance transactions to reduce costs.

Web Vitals not improving despite optimisations — Lab metrics (Lighthouse) and field metrics (real user data) can differ significantly. Always measure field metrics (Vercel Analytics, CrUX) — they reflect real user experience on real devices.

Missing source maps in Sentry — without source maps, Sentry shows minified stack traces that are impossible to debug. Configure Sentry's Webpack plugin to upload source maps during builds.

✅ Best Practices

Set up Sentry before going to production — not after the first incident

Upload source maps to Sentry — minified stack traces are useless

Set up alerts for error rate spikes, not just individual errors

Monitor Core Web Vitals after every production deployment

Use structured logging (JSON) for server logs — enables log search and dashboards

🏛️ Architect's Note

Senior Architect's Perspective

Observability is not optional for production systems. The minimum viable monitoring stack for a Next.js app: Sentry (errors) + Vercel Analytics (Web Vitals) + structured logging. Add APM (Datadog, Datadog) when you need to trace slow requests across multiple services.

💬 Frequently Asked Questions

How do I set up OpenTelemetry with Next.js?

Next.js has built-in OpenTelemetry support. Create instrumentation.ts at the project root and export a register() function. Install @vercel/otel or @opentelemetry/sdk-node. This gives you distributed tracing across Server Components, Route Handlers, and external services.

How do I add custom metrics to Vercel Analytics?

Use the @vercel/analytics package's track() function: import { track } from "@vercel/analytics"; track("checkout_completed", { value: cart.total }). Custom events appear in the Vercel Analytics dashboard alongside Web Vitals.

How do I debug a production performance issue?

Start with Vercel Analytics to identify which pages have poor LCP/CLS. Use Sentry performance traces to find slow server operations. Use Chrome DevTools with a production build to profile client-side rendering. Check server logs for slow DB queries.

🎯 Key Takeaways

1Three monitoring layers: Core Web Vitals + error tracking + server observability
2Set up Sentry before going to production — not after the first incident
3Upload source maps to Sentry for readable stack traces
4Vercel Analytics for Web Vitals; Sentry for errors — you need both
5Monitor Web Vitals after every production deployment to catch regressions
6Use structured JSON logging for server logs — enables search and dashboards

🎯 Practice this topic in interviews

↗ Where this topic fits

Sources

Sources / References

Use these Next.js references to verify the concept in official docs and continue into the most relevant SplashRide pages.

Related SplashRide pages

SplashRide Next.js learning path

Browse the full Next.js topic collection and learning order on SplashRide.

Next.js Interview Prep

Practice Next.js interview questions and scenario-based answers.

Frontend Engineer Career Path

A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.

Full Stack Java Developer Career Path

A guided route through frontend foundations, Java backend engineering, delivery workflows, and interview readiness.

Vercel Deployment

Deploy Next.js to Vercel — zero-config deployments, preview environments, edge functions, analytics, and the production configuration patterns used in enterprise.

CI/CD Pipelines

Set up production-grade CI/CD for Next.js — GitHub Actions, automated testing, type checking, preview deployments, and zero-downtime production releases.