Prompt
How do I debug app errors without reproducing locally?
Latest observation
You can debug a lot of app errors remotely if you treat production like a source of evidence and set up good observability. Here’s a practical playbook.
1) Capture the error with enough context
Make sure every exception/event includes:
- Error message and stack trace
- User/session ID (or anonymous request ID)
- Request details: route, method, query params, headers, body size
- App state: feature flags, release version, environment, device/browser
- Timing: timestamp, latency, timeouts
- Correlation ID / trace ID to link logs, traces, and metrics
Use an error-reporting tool like:
- Sentry
- Rollbar
- Bugsnag
- Datadog Error Tracking
2) Centralize logs and search by request/error ID
Use structured logs, not plain text. Log fields like:
request_iduser_idtrace_idendpointstatus_codeerror_coderelease
Then you can:
- Search the exact failure
- Reconstruct the sequence of events
- Compare successful vs failed requests
3) Use distributed tracing
If the bug crosses services, traces are often the fastest way to find it.
Add/propagate:
trace_idspan_id- service name
- dependency calls
- DB queries and external API calls
Look for:
- A slow or failing span
- Retries
- Timeouts
- Unexpected downstream status codes
4) Compare failed vs successful cases
When you can’t reproduce, compare:
- Same endpoint, different users
- Same user, different device/browser
- Same code version, before vs after deploy
- Failed requests vs nearby successful ones
Common differences:
- Missing auth token
- Bad data shape
- Locale/timezone edge case
- Race condition
- Feature flag mismatch
- Stale cache / bad session
- External API failure
5) Add “breadcrumbs” before the crash
Breadcrumbs are lightweight event logs leading up to the error:
- Navigation events
- API calls
- State transitions
- Form submissions
- Button clicks
- Cache hits/misses
These are extremely useful for frontend/mobile issues.
6) Record minimal request/replay data carefully
For hard-to-reproduce bugs, capture:
- Sanitized request payloads
- Response status
- Relevant state snapshot
- UI event sequence
Be careful with:
- Secrets
- PII
- Passwords/tokens
- Full payment data
Use redaction and sampling.
7) Use feature flags and kill switches
If the issue is tied to a rollout:
- Disable the feature for affected users
- Roll back the release
- Narrow blast radius with gradual rollout
Feature flags also help isolate whether a new code path is causing the issue.
8) Check infra and dependencies
Errors that “only happen in production” are often due to:
- Network issues
- Rate limits
- Bad secrets/config
- Load balancer/CDN behavior
- DB connection exhaustion
- Third-party API outages
- Timeouts under real load
Check:
- Metrics dashboards
- Status pages
- Error budgets
- Queue depth
- CPU/memory saturation
- GC pressure
- Thread pool exhaustion
9) Add targeted diagnostics
Once you suspect a class of bug, add temporary logging around:
- Input validation
- Serialization/deserialization
- Branch decisions
- DB queries
- Retry logic
- Permission checks
Keep it:
- Short-lived
- Sampled
- Redacted
- Behind a flag if possible
10) Use logs to build a hypothesis, then verify with safe experiments
If you can’t reproduce locally:
- Form a hypothesis from telemetry
- Deploy a small debug change to a staging-like environment
- Use a canary release or targeted logging
- Validate with production traffic patterns if possible
11) Common tooling stack
A solid setup usually includes:
- Errors: Sentry / Rollbar / Bugsnag
- Logs: ELK / OpenSearch / Datadog Logs / Loki
- Metrics: Prometheus / Grafana / Datadog
- Tracing: OpenTelemetry + Jaeger / Tempo / Datadog APM
- Feature flags: LaunchDarkly / Unleash / ConfigCat
12) A simple debugging workflow
- Find the error event
- Get the request/trace ID
- Pull correlated logs
- Inspect the trace and downstream calls
- Compare with a successful request
- Identify the differing input/state
- Add targeted instrumentation or a safe fix
- Verify on a canary or by monitoring
If you want the shortest answer
The key is: log enough context, correlate logs/traces/errors with IDs, compare failed vs successful requests, and use targeted instrumentation instead of local reproduction.
If you tell me your stack (web/mobile/backend, language, and error-tracking tools), I can suggest a concrete setup and what fields to log.