Skip to main content
The Sentry Next.js SDK provides automatic error monitoring and performance tracking for Next.js applications with support for App Router, Pages Router, Server Components, and Edge Runtime.

Installation

1

Install with Wizard

The easiest way to set up Sentry in Next.js is using the Sentry Wizard:
The wizard will:
  • Install the @sentry/nextjs package
  • Create configuration files
  • Set up source maps upload
  • Configure build-time instrumentation
2

Manual Installation

Alternatively, install manually:

Version Compatibility

  • Next.js 13.2+: Fully supported (App Router & Pages Router)
  • Next.js 15+: Full support including Turbopack (beta)
  • Next.js 16+: Turbopack default bundler support

Basic Setup

Client Configuration

Create sentry.client.config.ts (or .js) in your project root:

Server Configuration

Create sentry.server.config.ts (or .js) in your project root:

Edge Runtime Configuration

Create sentry.edge.config.ts (or .js) for Edge runtime:

Next.js Configuration

Wrap your next.config.js with withSentryConfig:

App Router Features

Server Components

Sentry automatically instruments Server Components:

Route Handlers

Route handlers are automatically instrumented:

Server Actions

Wrap Server Actions for error tracking:

Pages Router Features

API Routes

Wrap API routes for automatic instrumentation:

Data Fetching Methods

Custom Error Page

Create a custom error page with Sentry:

Middleware Instrumentation

Environment Variables

Add these to your .env.local or deployment environment:

Performance Monitoring

Custom Transactions

Database Queries

Source Maps

Source maps are automatically uploaded during build when configured:

Turbopack Support

For Next.js 15+ with Turbopack:
Sentry automatically detects Turbopack and adjusts instrumentation accordingly. Note that build-time wrapping is limited in Turbopack mode.

Best Practices

Separate Configs

Use separate config files for client, server, and edge runtimes.

Source Maps

Always upload source maps for production builds.

Error Boundaries

Use React Error Boundaries in client components.

Environment Variables

Store sensitive data in environment variables.

Troubleshooting

If you encounter build errors with Turbopack:
  1. Ensure you’re using Next.js 15.6+
  2. Check that @sentry/nextjs is up to date
  3. Try disabling automatic instrumentation in next.config.js
Verify:
  1. SENTRY_AUTH_TOKEN is set
  2. org and project are correct in withSentryConfig
  3. silent: false to see upload logs

Next Steps

App Router

Deep dive into App Router features

Server Actions

Track Server Actions and mutations

Middleware

Instrument Next.js middleware

Source Maps

Advanced source map configuration