Prompt
How do I track application errors in production?
Latest observation
To track application errors in production, use a mix of exception monitoring, structured logging, and alerting so you can detect issues quickly and diagnose them efficiently.
1) Capture exceptions centrally
Use an error-tracking service or centralized system such as:
- Sentry
- Datadog Error Tracking
- New Relic
- Rollbar
- Bugsnag
- Or your own stack with ELK/EFK, CloudWatch, Stackdriver/Cloud Logging, etc.
These tools automatically collect:
- Exception type and stack trace
- Error frequency
- Affected release version
- Environment (prod, staging)
- User/session context
- Request metadata
2) Use structured logging
Log errors in a consistent format, ideally JSON, including:
- Timestamp
- Severity
- Service/module name
- Request ID / trace ID
- User ID or tenant ID
- Endpoint / operation
- Error message and stack trace
- Deployment version
Example fields:
{
"level": "error",
"service": "checkout-api",
"trace_id": "abc123",
"user_id": "u42",
"endpoint": "/pay",
"error": "Payment gateway timeout"
}
3) Add context to every error
When an error occurs, include enough context to reproduce it:
- Which request triggered it
- What input data was involved
- Which feature flag or configuration was active
- Which external dependency failed
- Which release introduced it
Avoid logging secrets, passwords, tokens, or full credit card data.
4) Set up alerts for important signals
Create alerts for:
- Error rate spikes
- New exception types
- Deployment-related regressions
- Repeated failures on critical endpoints
- SLA/SLO breaches
Useful alert patterns:
5xx rate > threshold for 5 minutesnew error count > 0 after deploymenterror rate increased by 2x compared to baseline
5) Correlate errors with tracing and metrics
Combine:
- Logs for detail
- Metrics for trends
- Distributed tracing for request paths
This helps you answer:
- Is it one endpoint or many?
- Is the DB slow or unavailable?
- Is the issue only in one region?
- Did a specific deploy cause it?
6) Record breadcrumbs
Before the failure, record small events such as:
- User actions
- API calls
- DB queries
- Feature flag changes
This makes debugging much easier in production.
7) Monitor by release
Tag every error with:
- Release version / build number
- Commit hash
- Deployment time
Then compare error rates before and after a release to quickly identify regressions.
8) Protect user privacy
Be careful not to log:
- Passwords
- API keys
- Session tokens
- Personal data unless necessary and permitted
- Full payment details
Use redaction and data minimization.
9) Build a triage workflow
When an error occurs:
- Detect via alert/dashboard
- Check if it’s new or increasing
- Identify affected users/endpoints
- Review stack trace and context
- Roll back or hotfix if needed
- Postmortem and add prevention
10) Make it actionable
Tracking errors is only useful if you can act on them:
- Assign ownership to each service
- Define severity levels
- Create runbooks for common failures
- Track resolution time and recurrence
If you want, I can also give you:
- a production error-monitoring checklist
- a sample logging schema
- or code examples for Python, JavaScript, Java, or .NET.