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

CategoryMetrics
AvailabilityUptime, error rate, success rate
PerformanceResponse time (p50, p95, p99), throughput
ResourcesCPU, memory, disk, connections
BusinessActive 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

LevelWhen
ERRORSomething broke and needs attention
WARNSomething unexpected but handled
INFOSignificant application events
DEBUGDetailed 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

  1. First: Error tracking (know when things break)
  2. Next: Key metrics (know how things perform)
  3. Then: Structured logging (know what happened)
  4. Finally: Analytics (know how users behave)