Capturing Errors
Automatic Error Capture
Sentry automatically captures unhandled errors and promise rejections:Manual Error Capture
Capture errors in try-catch blocks:Capturing Messages
For non-error events, usecaptureMessage:
Adding Context
User Context
Identify users to track who experiences errors:Tags
Add searchable key-value pairs:Extra Context
Add structured data to events:Fingerprinting
Control how errors are grouped:Breadcrumbs
Breadcrumbs provide a trail of events leading to an error:Scope Management
Isolation Scope
Use isolation scopes for request-level context in Node.js:Current Scope
Modify the current scope temporarily:Error Boundaries (React)
Use error boundaries to catch React component errors:Customizing Error Boundaries
Async Error Handling
Promises
Async/Await
Node.js Error Handling
Express Error Handler
Unhandled Rejections
Enriching Error Data
Stack Traces
Source Maps
Ensure source maps are uploaded for readable stack traces:Context Lines Integration
Handling Specific Error Types
Network Errors
Validation Errors
Best Practices
Always add context before capturing
Always add context before capturing
Context helps debug issues faster:
Use error levels appropriately
Use error levels appropriately
Set appropriate severity levels:
Don't swallow errors silently
Don't swallow errors silently
Always log or capture errors:
Use custom fingerprints for known errors
Use custom fingerprints for known errors
Group related errors together:
Monitor error rates, not just errors
Monitor error rates, not just errors
Use Sentry’s alerts to monitor error rate increases, which can indicate new issues.
Complete Example
Next Steps
Performance Monitoring
Monitor application performance
Source Maps
Configure source maps for readable errors