How to Monitor and Fix Application Errors in Production: Complete Guide
Set up error tracking, alerting, and debugging workflows to catch and fix issues before users notice. Includes implementation examples for modern frameworks.
Why Production Monitoring Is Non-Negotiable
The moment your application goes live, you lose direct visibility into how it behaves. Users encounter errors they don't report—research shows only 1 in 26 unhappy customers actually complain. The rest simply leave. Without production monitoring, you're flying blind, learning about critical issues from angry tweets or, worse, from churned customers.
Error monitoring isn't just about catching bugs—it's about understanding your application's health in the real world. Production environments expose edge cases that development and staging can't replicate: slow network connections, browser extensions that interfere with JavaScript, race conditions under load, and the infinite creativity of users who use your product in unexpected ways.
Error Monitoring Tools Compared
Sentry: The Error Tracking Standard
Sentry has become the default choice for application error monitoring, used by over 4 million developers:
Core Capabilities:
Error Aggregation: Groups similar errors together, preventing alert fatigue while surfacing unique issues. A single release that breaks authentication will show as one issue with thousands of occurrences, not thousands of separate alerts.
Rich Context: Captures everything needed to reproduce issues:
- Full stack traces with source maps
- User information and session data
- Request details (headers, body, URL)
- Browser/device information
- Custom context you add
Release Tracking: Associates errors with specific deployments, enabling quick identification of which release introduced a bug.
Performance Monitoring: Transaction tracing, slow endpoint detection, and frontend vitals tracking.
Pricing:
- Free: 5,000 errors/month
- Team: $26/month for 50K errors
- Business: Custom pricing with advanced features
LogRocket: Session Replay Focus
LogRocket approaches monitoring differently—by recording user sessions:
Primary Value Proposition:
Session Replay: Watch exactly what users experienced, including:
- Mouse movements and clicks
- DOM changes and network requests
- Console logs and JavaScript errors
- Rage clicks and frustration signals
Use Case: When stack traces aren't enough. Seeing the user's actual interaction often reveals issues that error logs miss—confusing UI that leads to errors, broken layouts that make elements unclickable, or sequences of actions that create race conditions.
Pricing:
- Free: 1,000 sessions/month
- Team: $99/month for 10K sessions
- Professional: Custom pricing
Datadog: Full Observability Platform
Datadog provides comprehensive observability for larger organizations:
Suite of Products:
- Application Performance Monitoring (APM)
- Log Management
- Real User Monitoring (RUM)
- Infrastructure Monitoring
- Security Monitoring
When Datadog Makes Sense:
- Large engineering teams needing unified observability
- Complex distributed systems
- Strong infrastructure monitoring requirements
- Budget for enterprise tooling
Pricing: Consumption-based, typically starting at several hundred dollars/month
Implementation Guide: Sentry with Next.js
Step 1: Installation
npx @sentry/wizard@latest -i nextjs
The wizard automatically:
- Installs necessary packages
- Creates configuration files
- Sets up source maps upload
- Configures error boundaries
Step 2: Manual Configuration (if needed)
// sentry.client.config.js
import * as Sentry from "@sentry/nextjs";
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
// Performance Monitoring
tracesSampleRate: 0.1, // 10% of transactions
// Release tracking
release: process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA,
environment: process.env.NODE_ENV,
// Replay configuration
replaysSessionSampleRate: 0.1, // 10% of sessions
replaysOnErrorSampleRate: 1.0, // 100% of errors
integrations: [
new Sentry.Replay({
maskAllText: false,
blockAllMedia: false,
}),
],
// Ignore known non-errors
ignoreErrors: [
'ResizeObserver loop limit exceeded',
'Network request failed',
'Load failed',
],
beforeSend(event, hint) {
// Filter or modify events before sending
if (event.exception?.values?.[0]?.value?.includes('Canceled')) {
return null; // Don't send user-cancelled requests
}
return event;
},
});
Step 3: Add User Context
// When user logs in
import * as Sentry from "@sentry/nextjs";
function setUserContext(user) {
Sentry.setUser({
id: user.id,
email: user.email,
username: user.name,
subscription: user.plan,
});
}
// When user logs out
function clearUserContext() {
Sentry.setUser(null);
}
Step 4: Add Custom Context
// Add breadcrumbs for debugging
Sentry.addBreadcrumb({
category: 'user-action',
message: 'Clicked export button',
level: 'info',
data: {
format: 'csv',
recordCount: 150,
},
});
// Add custom tags for filtering
Sentry.setTag('feature', 'export');
Sentry.setTag('team', user.team.id);
// Add extra context
Sentry.setContext('export-details', {
fileSize: 1024000,
duration: 3500,
});
Step 5: Capture Custom Events
// Capture handled exceptions
try {
await riskyOperation();
} catch (error) {
Sentry.captureException(error, {
tags: { operation: 'risky-operation' },
extra: { attemptNumber: attempt },
});
// Handle gracefully
}
// Capture messages for non-exception issues
if (response.data.items.length === 0 && shouldHaveItems) {
Sentry.captureMessage('Unexpected empty response', {
level: 'warning',
contexts: {
response: {
status: response.status,
endpoint: '/api/items',
},
},
});
}
Alerting Best Practices
Effective alerting balances awareness with noise:
Alert Hierarchy
| Level | Trigger | Action | Notification |
|---|---|---|---|
| Critical | Core flow broken | Immediate | PagerDuty/Phone |
| High | New error spike | Within 1 hour | Slack + Email |
| Medium | Known issue increase | Same day | Slack |
| Low | First occurrence | Weekly review | Dashboard only |
Alert Configuration in Sentry
Alert when:
- New issue is seen
- Issue frequency exceeds threshold (e.g., 10x normal)
- Error rate exceeds percentage (e.g., >5% of sessions)
- Specific error types (e.g., PaymentError, AuthError)
Avoiding Alert Fatigue
- Group similar errors: Don't alert on each occurrence
- Set meaningful thresholds: Not every error needs immediate attention
- Time-based alerts: Only alert during business hours for non-critical issues
- Owner assignment: Route to the right team automatically
- Snooze capability: Temporarily silence known issues being worked on
Debugging Workflow: From Alert to Fix
Step 1: Triage
- Check error frequency and trend
- Identify affected users (volume, type)
- Determine if it's new or recurring
Step 2: Investigate
- Review stack trace and source context
- Check user context and session data
- Watch session replay (if available)
- Review related breadcrumbs
Step 3: Reproduce
- Create minimal reproduction case
- Use captured data to set up conditions
- Verify the exact failure path
Step 4: Fix
- Implement fix with regression test
- Deploy to staging for verification
- Deploy to production
Step 5: Verify
- Monitor error frequency post-deploy
- Confirm fix resolves the specific issue
- Mark issue as resolved in Sentry
Metrics Dashboard
Track these key metrics:
| Metric | Target | Action if Exceeded |
|---|---|---|
| Error rate | < 0.5% | Investigate top errors |
| Crash-free sessions | > 99.5% | Priority bug fixes |
| P95 latency | < 500ms | Performance investigation |
| Error trend | Decreasing | Review release quality |
Effective error monitoring transforms reactive firefighting into proactive quality improvement, catching issues before they impact business metrics.
Tools Mentioned in This Guide
Browse all toolsRelated Comparisons
View all comparisonsRelated Guides
View all guidesThe Complete Developer Tools Stack: From IDE to Production
Build the optimal developer experience with the right tools. Complete guide to IDEs, version control, CI/CD, testing, monitoring, and collaboration tools for engineering teams.
Read guide 18 min readThe Complete Guide to SaaS Metrics Benchmarking: How to Measure What Matters
Learn how to benchmark your SaaS metrics against industry standards. Discover key performance indicators, benchmarking methodologies, and actionable insights for improvement.
Read guideNeed Help Building Your Stack?
Use our Stack Builder to get personalized recommendations
Build Your Stack