telemetry
Manages observability including error tracking, logging, metrics, and analytics. Covers instrumentation strategy, event definitions, and monitoring setup. Use when setting up monitoring, instrumenting events, or debugging production issues.
Telemetry & Observability
Three pillars: Errors (what broke), Metrics (how it's performing), Logs (what happened).
Error Tracking
Strategy
- Use a dedicated error tracking service (Sentry, Bugsnag, Rollbar, etc.)
- Capture unhandled exceptions automatically
- Add breadcrumbs at key application events for context
- Group errors by root cause, not by stack trace variation
Setup Pattern
1. Install SDK
2. Initialize early in application startup
3. Configure environment (dev/staging/production)
4. Set sample rate for performance tracing (10-20% is typical)
5. Upload source maps / debug symbols for readable stack traces
Breadcrumbs
Add context at key moments so error reports tell a story:
- User actions (navigation, form submissions, key interactions)
- State transitions (login, mode changes, configuration updates)
- External calls (API requests, DB queries)
Metrics
Key Metrics to Track
| Category | Metrics |
|---|---|
| Availability | Uptime, error rate, success rate |
| Performance | Response time (p50, p95, p99), throughput |
| Resources | CPU, memory, disk, connections |
| Business | Active users, key actions, conversion |
Alerting Rules
- Alert on symptoms, not causes (high error rate, not "disk at 80%")
- Set meaningful thresholds based on actual baselines
- Include runbook links in alerts
- Avoid alert fatigue - every alert should require action
Logging
Levels
| Level | When |
|---|---|
| ERROR | Something broke and needs attention |
| WARN | Something unexpected but handled |
| INFO | Significant application events |
| DEBUG | Detailed diagnostic info (dev/staging only) |
Rules
- Structured logging (JSON) in production for parseability
- Include correlation IDs for request tracing
- Never log secrets, PII, or full request bodies with sensitive data
- Keep log volume manageable - noisy logs get ignored
Analytics Events
Define events that answer business questions:
EVENT: [name]
WHEN: [trigger condition]
PAYLOAD: [relevant data fields]
QUESTION IT ANSWERS: [what you learn from this]
Offline-First Pattern
Queue events locally when offline. Flush on connectivity. Batch inserts for efficiency. Dedup on the server if needed.
Phase Rollout
- First: Error tracking (know when things break)
- Next: Key metrics (know how things perform)
- Then: Structured logging (know what happened)
- Finally: Analytics (know how users behave)