Quick Start
Create Sentry Account
Sign up at sentry.io and create a new Next.js project. Copy your DSN from the project settings.
Configuration Files
Sentry is configured in three files for different Next.js runtime environments:| File | Environment | Purpose |
|---|---|---|
sentry.server.config.ts | Server | Node.js server-side errors |
sentry.edge.config.ts | Edge | Middleware and edge routes |
next.config.ts | Build | Webpack integration and source maps |
Server Configuration
sentry.server.config.ts
Edge Configuration
sentry.edge.config.ts
Both server and edge configurations use the same settings. The files are separate because they run in different runtime environments.
Next.js Integration
Sentry is integrated viawithSentryConfig in next.config.ts:
next.config.ts
Tunnel Route
Sentry uses a tunnel route (/monitoring) to bypass ad-blockers. This routes browser requests to Sentry through Next.js:
Sample Rates
Sentry uses different sample rates for development and production:- Development:
1.0(100% of traces) - Production:
0.2(20% of traces)
Privacy & PII
By default, Sentry does not send personally identifiable information (PII):Capturing Errors
Sentry automatically captures unhandled errors. You can also manually capture errors:Manual Error Capture
Custom Messages
Adding Context
Source Maps
Sentry automatically uploads source maps in production for readable stack traces:Source maps are only uploaded in CI environments where
process.env.CI is set.Vercel Cron Monitors
Sentry automatically instruments Vercel Cron jobs:Performance Monitoring
Sentry tracks performance metrics automatically. View transaction traces in the Sentry dashboard to identify slow routes and API calls. To add custom performance tracking:Environment Variables Reference
| Variable | Required | Description |
|---|---|---|
NEXT_PUBLIC_SENTRY_DSN | Yes | Your Sentry project DSN (from Sentry project settings) |
SENTRY_AUTH_TOKEN | No | Auth token for uploading source maps (set in CI only) |
Best Practices
Lower Sample Rates in Production
Lower Sample Rates in Production
Use a lower
tracesSampleRate (0.1-0.3) in production to reduce costs while maintaining visibility into critical errors.Avoid Sending PII by Default
Avoid Sending PII by Default
Keep
sendDefaultPii: false and only send user data when necessary for debugging specific issues.Use Tunnel Route
Use Tunnel Route
The tunnel route (
/monitoring) bypasses ad-blockers but increases server load. Monitor your hosting costs.Set Up Alerts
Set Up Alerts
Configure Sentry alerts to notify your team when error rates spike or critical issues occur.