Setting up Sentry
Learn how to configure Sentry for error monitoring and performance tracking in your Makerkit application.
Sentry is a full-featured error tracking and performance monitoring platform. Makerkit includes built-in support for Sentry with automatic configuration for both client and server environments.
Sentry Setup
Configure Sentry in your application
Install the Sentry SDK
Install the Sentry Next.js SDK in your web application:
pnpm add @sentry/nextjs --filter webConfigure Environment Variables
Add these environment variables:
.env.local
NEXT_PUBLIC_MONITORING_PROVIDER=sentryNEXT_PUBLIC_SENTRY_DSN=https://your-dsn@sentry.io/project-idYou can find your DSN in the Sentry dashboard:
- Go to Settings → Projects → Select your project
- Click Client Keys (DSN)
- Copy the DSN value
Optional Environment Variables
.env.local
# Environment name (defaults to VERCEL_ENV if on Vercel)NEXT_PUBLIC_SENTRY_ENVIRONMENT=production# Release version for source maps (set in CI)SENTRY_RELEASE=1.0.0# Auth token for uploading source maps (set in CI)SENTRY_AUTH_TOKEN=your-auth-tokenUpdate Next.js Configuration
Wrap your Next.js configuration with the Sentry configuration:
next.config.ts
import { withSentryConfig } from '@sentry/nextjs';const nextConfig = { // Your existing Next.js config};export default withSentryConfig(nextConfig);This enables Sentry's build-time instrumentation and source map uploading.
Upload Source Maps
Source maps help Sentry display readable stack traces instead of minified code. Configure source map uploading for production builds:
next.config.ts
import { withSentryConfig } from '@sentry/nextjs';const IS_PRODUCTION = process.env.NODE_ENV === 'production';const nextConfig = { // Your existing config};export default withSentryConfig(nextConfig, { org: 'your-sentry-org', project: 'your-sentry-project', // Auth token for uploading source maps authToken: process.env.SENTRY_AUTH_TOKEN, // Suppress logs in development silent: !IS_PRODUCTION, // Recommended settings widenClientFileUpload: true, autoInstrumentServerFunctions: false,});Add SENTRY_AUTH_TOKEN to your CI environment variables. Generate a token in Sentry:
- Go to Settings → Auth Tokens
- Click Create New Token
- Select scopes:
project:releases,org:read - Copy the token to your CI secrets
Performance Monitoring
Sentry captures performance data automatically. The default configuration includes:
Default performance settings
{ // Capture 100% of transactions (adjust in production) tracesSampleRate: 1.0, // Capture session replay for 10% of sessions replaysSessionSampleRate: 0.1, // Capture session replay for 100% of error sessions replaysOnErrorSampleRate: 1.0,}For high-traffic applications, reduce tracesSampleRate:
Production-ready sampling
{ // Capture 10% of transactions in production tracesSampleRate: process.env.NODE_ENV === 'production' ? 0.1 : 1.0,}How It Works
When Sentry is configured, Makerkit's monitoring system:
- Initializes Sentry automatically on the client and server
- Captures exceptions through the
onRequestErrorinstrumentation hook - Associates errors with users when
identifyUseris called - Uploads source maps during production builds
The SentryMonitoringService handles environment detection and initializes the appropriate Sentry client:
How Sentry initializes
// Browser environmentif (typeof document !== 'undefined') { initializeSentryBrowserClient({ environment });}// Server environmentelse { initializeSentryServerClient({ environment });}Verifying Your Setup
After configuring Sentry:
- Trigger a test error - Add a button that throws an error
- Check the Sentry dashboard - The error should appear within seconds
- Verify source maps - Stack traces should show readable code
Test error component
'use client';export function TestErrorButton() { return ( <button onClick={() => { throw new Error('Test Sentry error'); }} > Throw Test Error </button> );}Troubleshooting
Errors Not Appearing
- Verify
NEXT_PUBLIC_SENTRY_DSNis set and correct - Check the browser console for Sentry initialization errors
- Ensure your Sentry project has available quota
Source Maps Not Working
- Verify
SENTRY_AUTH_TOKENis set in your CI environment - Check the build logs for source map upload errors
- Ensure
organdprojectmatch your Sentry dashboard
Performance Data Missing
- Check
tracesSampleRateis greater than 0 - Verify Sentry's performance monitoring is enabled for your project
- Wait a few minutes for data to appear in the dashboard
Frequently Asked Questions
What's the difference between SENTRY_DSN and NEXT_PUBLIC_SENTRY_DSN?
Should I use Sentry in development?
How do I associate errors with users?
Next: Manual Error Capturing →