Sentry captures unhandled exceptions, groups identical errors from different users into a single issue, and provides the breadcrumbs, context, and session replay you need to reproduce and fix bugs without asking users what they did. It is the most widely used error tracking tool for production web applications, and it works.
Sentry Error Tracking Guide: From Setup to Production Insights
Sentry groups errors, captures breadcrumbs, and records session replays. Here is how to set it up in Next.js and use it to actually fix bugs faster.
Mahmudul Haque Qudrati
CEO & ML Engineer
One AI engineering post, weekly
LLM benchmarks, prompt techniques, and token-cost breakdowns — not another AI news roundup.
The problem with console.log and log aggregators (Datadog Logs, Papertrail, Logtail) is that they give you raw text. When an error happens 1,000 times from 1,000 different users, you get 1,000 log lines. Finding the unique errors, understanding which users are affected, and reproducing the conditions requires manual work.
Sentry solves this with automatic error grouping. When the same exception (same stack trace, same error message) occurs 1,000 times, Sentry shows you one issue with a count of 1,000 occurrences. You see the error once, fix it once, and mark it resolved.
Beyond grouping, Sentry captures:
Breadcrumbs: automatic log of what happened before the error. Sentry automatically captures console logs, HTTP requests, navigation events, user interactions, and database queries that occurred in the 30 seconds before the error. When you look at an issue, you see a timeline of exactly what the user did and what your app called before it crashed.
Context: browser, OS, screen resolution, user identity, and any custom context you set. Knowing that an error only happens on Safari 17 on iOS 16 changes your debugging approach entirely.
Session replay (Sentry Replay): optional video-like recording of the user's screen session before the error. Watch exactly what the user did, including clicks, scrolls, and input events, in a privacy-respecting way (sensitive data is masked by default). This is the most powerful debugging tool Sentry offers: often you can watch a 30-second replay and immediately understand what caused the error.
Setting Up Sentry in Next.js
Install the Sentry Next.js SDK:
pnpm add @sentry/nextjs
Run the Sentry wizard for automatic setup:
npx @sentry/wizard@latest -i nextjs
The wizard creates sentry.client.config.ts, sentry.server.config.ts, and sentry.edge.config.ts, and updates next.config.ts to enable source map upload during builds.
Minimal configuration:
// sentry.client.config.ts
import * as Sentry from '@sentry/nextjs'
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
tracesSampleRate: 0.1, // capture 10% of transactions for performance monitoring
replaysSessionSampleRate: 0.01, // capture 1% of sessions
replaysOnErrorSampleRate: 1.0, // always capture replay when an error occurs
integrations: [Sentry.replayIntegration()],
})
Set the DSN in your environment:
NEXT_PUBLIC_SENTRY_DSN=https://...@sentry.io/...
SENTRY_AUTH_TOKEN=... # for source map upload during build
Team workspace
Ship faster with chat, meetings, and projects in one place — Zlyqor.
Source Maps: Making Stack Traces Readable
Without source maps, Sentry shows you minified JavaScript stack traces: at t (main.js:1:234567). With source maps, you see the original TypeScript: at handlePayment (src/lib/payments/stripe.ts:42:8). This is the difference between being able to debug in 5 minutes versus spending an hour.
The Sentry Next.js wizard configures source map upload automatically using the SENTRY_AUTH_TOKEN. During next build, source maps are uploaded to Sentry and then deleted from the production bundle (so your source code is not exposed to users).
Error Boundaries for React
React errors inside components do not propagate to the global error handler by default. They crash the component tree silently. Add Sentry error boundaries to catch React rendering errors:
import * as Sentry from '@sentry/nextjs'
export default function RootLayout({ children }) {
return (
<html>
<body>
<Sentry.ErrorBoundary fallback={<p>Something went wrong.</p>}>
{children}
</Sentry.ErrorBoundary>
</body>
</html>
)
}
Identifying Users in Errors
When an error occurs, you want to know which user was affected. Set the user context after authentication:
Sentry.setUser({ id: user.id, email: user.email, name: user.name })
Call this after the user logs in. Now every error captured includes the user's identity, and you can search Sentry issues by affected user or see how many unique users are affected by a given bug.
Performance Monitoring
Sentry Performance tracks frontend and backend transaction traces: how long individual pages, API routes, and database queries take. This is separate from error tracking but uses the same SDK.
When performance monitoring is enabled, Sentry shows you:
- Slow transactions: which pages and API routes are slowest
- Database query performance: slow queries (requires SDK integration with your ORM or database driver)
- N+1 detection: Sentry identifies when your code makes the same query many times in a loop
The tracesSampleRate controls what percentage of requests are traced. Start with 0.1 (10%) in production to manage volume.
Sentry vs Alternatives
Bugsnag: similar feature set to Sentry, slightly different pricing model (by MAU rather than event volume). Better for mobile app error tracking.
Rollbar: older Sentry competitor, less commonly used in new projects, has a solid feature set.
LogRocket: focused on session replay rather than error tracking. Better replay quality than Sentry Replay, but error tracking is secondary. Use LogRocket if session replay is your primary need.
Self-hosted Sentry: Sentry is open source and can be self-hosted. The self-hosted version lags behind Sentry SaaS on features but is free beyond server costs. Suitable for organizations with data residency requirements.
Pricing
The free tier includes 5,000 errors per month, 10,000 performance transactions, 50 session replays, and 1 team member. For side projects and small apps, this is often enough.
The Team plan ($26/month for a team of 5) is the first paid tier: 50,000 errors, 100,000 performance transactions, unlimited replays. For most production applications, this is the right tier. It is worth it when you start getting real users: the time saved debugging a single production incident pays for months of Sentry.
Best Practices for Production
- Set up alerts for new issues: Sentry can send email or Slack notifications when a new issue appears. Configure this in the project settings.
- Use release tracking: Tag errors with the release version so you can see which deploy introduced a bug. Sentry automatically detects releases if you set
releasein the SDK config or use the wizard. - Ignore expected errors: Use inbound filters to ignore errors you don't care about (e.g., browser extensions, known bots). This keeps your issue list clean.
- Sample performance traces carefully: Start with 0.1 and adjust based on volume. Too high a sample rate can overwhelm your quota.
- Regularly review and resolve: Mark issues as resolved when fixed. Sentry will reopen if the error reappears, helping you track regressions.
Keep Reading
- Grafana and Prometheus Monitoring Guide - metrics monitoring that complements Sentry's error tracking
- GitHub Actions Guide for Developers - automating Sentry release tracking in your CI pipeline
- We Replaced 6 SaaS Tools With One: What Happened - evaluating which tools are worth the cost
Pristren builds AI-powered software for teams. Zlyqor is our all-in-one workspace - chat, projects, time tracking, AI meeting summaries, and invoicing - in one tool. Try it free.
Frequently Asked Questions
What is Sentry error tracking?
Sentry is an error tracking and performance monitoring platform that captures exceptions, groups identical errors, and provides context like breadcrumbs, user data, and session replays. It helps developers identify, reproduce, and fix bugs in production applications.
How does Sentry error tracking work?
Sentry works by integrating an SDK into your application. When an error occurs, the SDK captures the stack trace, environment context, breadcrumbs (user actions, network requests), and optionally a session replay. This data is sent to Sentry's servers, where it is grouped by fingerprint (error message + stack trace) into issues. You can then view the issue, see affected users, and watch replays to understand the root cause.
What are the best practices for Sentry error tracking?
Best practices include: setting up source maps for readable stack traces, using error boundaries in React to catch rendering errors, identifying users via Sentry.setUser, configuring release tracking to correlate errors with deploys, setting alerts for new issues, ignoring expected errors with inbound filters, and sampling performance traces appropriately (e.g., 0.1 in production).
How much does Sentry error tracking cost?
Sentry offers a free tier with 5,000 errors/month, 10,000 performance transactions, 50 session replays, and 1 team member. The Team plan ($26/month for 5 members) includes 50,000 errors, 100,000 transactions, and unlimited replays. For larger needs, Business and Enterprise plans are available. Self-hosting is free but lacks some SaaS features.
Is Sentry error tracking worth it in 2026?
Yes, Sentry remains the industry standard for error tracking. Its automatic grouping, breadcrumbs, and session replay save significant debugging time. For most production apps, the Team plan pays for itself after fixing a single critical bug. Alternatives like Bugsnag or LogRocket may be better for specific use cases (mobile or replay-focused), but Sentry offers the best all-around value.
How do I set up Sentry in Next.js?
Install @sentry/nextjs via pnpm, then run npx @sentry/wizard@latest -i nextjs to auto-configure. This creates config files and updates next.config.ts for source map upload. Set your DSN and auth token in environment variables. Optionally add Sentry.ErrorBoundary to catch React errors and configure performance and replay sampling rates.
What is the difference between Sentry and LogRocket?
Sentry is primarily an error tracking tool with session replay as a feature, while LogRocket focuses on high-quality session replay with error tracking as secondary. LogRocket's replay quality is generally better, but Sentry offers superior error grouping, performance monitoring, and broader integrations. Choose Sentry for comprehensive observability, LogRocket if replay is your top priority.
Mahmudul Haque Qudrati
CEO & ML Engineer
Visionary leader with extensive experience in machine learning and software development. Drives strategic innovation and business growth.
More from Mahmudul
Related Articles
How to Use Claude to Make Videos Like Vox and Others
Claude can help you make Vox-style videos by generating scripts, editing with code, and automating animation. Here's a practical guide with real workflows and costs.
OpenAI Ends Cursor Model Access on Nov 12, 2026: What Developers Need to Know
OpenAI will terminate Cursor's access to its models on November 12, 2026, following SpaceX's acquisition. This guide explains the timeline, why it happened, and practical steps to migrate your workflow.
Ox Alpha That Became GLM 5.3 Flash: From Mystery to Preview, Everything We Know
Ox Alpha, the anonymous AI model that topped coding benchmarks, turned out to be GLM-5.3-Flash from Zhipu. Here's the full story, from mystery to official preview, with evidence and practical details.
// discussion
Comments