Error Monitoring

Full-stack error monitoring with Sentry. Client, server, and edge runtime coverage.

Add Sentry error monitoring in ~5 minutes using the official wizard. Captures client errors, server errors, edge runtime errors, performance traces, and session replay.

Setup

1

Install and run the Sentry wizard

pnpm add @sentry/nextjs
npx @sentry/wizard@latest -i nextjs

The wizard creates the Sentry config files and updates next.config.ts with the Sentry build plugin.

With Next.js 16+ and @sentry/nextjs v10+, the wizard may create instrumentation.ts and instrumentation-client.ts instead of the traditional sentry.client.config.ts files. Both patterns work.

2

Verify environment variables

The wizard adds these automatically — confirm they're in .env.local:

NEXT_PUBLIC_SENTRY_DSN="https://examplePublicKey@o0.ingest.sentry.io/0"
SENTRY_DSN="https://examplePublicKey@o0.ingest.sentry.io/0"
SENTRY_ORG="your-org"
SENTRY_PROJECT="your-project"
SENTRY_AUTH_TOKEN="your-auth-token"   # Required for source map uploads
3

Configure the client SDK

Edit sentry.client.config.ts (or instrumentation-client.ts if wizard used that):

import * as Sentry from "@sentry/nextjs"

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  tracesSampleRate: process.env.NODE_ENV === "production" ? 0.2 : 1.0,
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1.0,
  integrations: [
    Sentry.replayIntegration({ maskAllText: true, blockAllMedia: true }),
  ],
  enabled: process.env.NODE_ENV === "production",
})
4

Configure server and edge SDKs

// sentry.server.config.ts
import * as Sentry from "@sentry/nextjs"
Sentry.init({
  dsn: process.env.SENTRY_DSN,
  tracesSampleRate: 0.2,
  enabled: process.env.NODE_ENV === "production",
})

// sentry.edge.config.ts
import * as Sentry from "@sentry/nextjs"
Sentry.init({
  dsn: process.env.SENTRY_DSN,
  tracesSampleRate: 0.2,
  enabled: process.env.NODE_ENV === "production",
})
5

Add the global error boundary

Create app/global-error.tsx:

"use client"
import * as Sentry from "@sentry/nextjs"
import { useEffect } from "react"

export default function GlobalError({ error, reset }: { error: Error; reset: () => void }) {
  useEffect(() => { Sentry.captureException(error) }, [error])

  return (
    <html lang="en">
      <body>
        <div style={{ display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", minHeight: "100vh", gap: "1rem" }}>
          <h2>Something went wrong</h2>
          <p>Our team has been notified.</p>
          <button onClick={reset}>Try again</button>
        </div>
      </body>
    </html>
  )
}

Environment Variables

VariableRequiredDescription
NEXT_PUBLIC_SENTRY_DSNYesPublic DSN for client-side SDK
SENTRY_DSNYesDSN for server-side and edge SDKs
SENTRY_ORGYesSentry organization slug
SENTRY_PROJECTYesSentry project slug
SENTRY_AUTH_TOKENYesToken for source map uploads at build time

Verification

  1. Deploy to staging (Sentry is disabled in development by default via enabled: process.env.NODE_ENV === "production")
  2. Temporarily add throw new Error("Sentry test") to any page
  3. Check Sentry dashboard — error should appear within 30 seconds with source-mapped stack trace
  4. Remove the test error

Demo Mode — Explore freely. Some actions are restricted. demo@launchfst.dev / demo1234

Get LaunchFst →