Backend Observability
Purpose
Make the backend diagnosable and its failures visible: structured logs you can query, metrics that answer "is it healthy," alerts that fire on user-facing symptoms, and correlation from request to log line.
When to Use
- When establishing a backend foundation, before incidents — not after the first one.
- Not for client-side analytics or product metrics.
Inputs
- Deployment/runtime shape (where logs/metrics can go); async surfaces (
queues, scheduled-jobs).
- Critical user flows (what must alert when broken).
Discovery Questions
- Where do logs and metrics land (platform-provided vs chosen stack — a vendor decision)?
- Which flows are business-critical enough to page on?
- What volume/cost constraints bound log verbosity?
Responsibilities
- Structured logging: JSON logs with level, timestamp, request/correlation ID (generated at ingress, propagated through services, jobs, and outbound calls), route, actor ID (not PII), duration, outcome. Levels used consistently; debug off in production by config.
- PII/secret safety: denylist-by-design — no tokens, passwords, emails-in-clear, payload dumps; redaction at the logger, not by discipline (
backend-security audit events coordinate here).
- Metrics: RED per endpoint class (rate, error %, duration percentiles), plus queue depth/job failures (
queues), scheduled-job heartbeats (scheduled-jobs), external-call latency/error per provider (third-party-integrations), DB pool/query health (../../database/database-performance).
- Health checks: liveness (process up) vs readiness (dependencies reachable) — separate endpoints, used by the deploy target (
backend-deployment).
- Alerting on symptoms: error-rate and latency thresholds on critical flows, DLQ growth, missed schedule heartbeats — every alert actionable, with a route to logs via the correlation ID.
- Tracing: adopt distributed tracing when multiple services/queues make log-hopping painful — a justified addition, not a default.
Required Workflow
- Choose log/metric destinations (approval if new vendor/infra).
- Define the log schema + correlation-ID propagation (HTTP → jobs → outbound).
- Define the metric set per surface (endpoints, queues, schedules, providers, DB).
- Define liveness/readiness checks.
- Define alerts for critical symptoms, each with an owner and a runbook line.
- Verify redaction with a test (secret-shaped values never reach the sink).
Decision Rules
- Log events, not narration: one entry per request/job outcome beats step-by-step spam.
- Alert on user-visible symptoms (error rate, latency, backlog), not causes (CPU) — causes go on dashboards.
- Correlation ID crosses every async boundary or debugging stops at the queue.
- Sampling/retention are cost decisions — record them; don't discover them on the invoice.
Rules
- No PII/secrets in logs — enforced by redaction code, verified by test.
- Every alert has an owner and an action; unactionable alerts get deleted, not muted.
- Health checks are cheap and dependency-honest (readiness fails when the DB is gone).
Anti-Patterns
console.log prose scattered through services.
- Logging request/response bodies wholesale.
- One
/health returning 200 unconditionally.
- Alerts on every 5xx blip → pager fatigue → ignored pages.
- Request ID that dies at the queue boundary.
Validation Checklist
Definition of Done
A recorded observability design — structured correlated PII-safe logs, per-surface metrics, honest health checks, actionable symptom alerts, and an explicit tracing decision — wired into deploy and job surfaces.
Related Skills
backend-error-handling, backend-performance, backend-security, queues, scheduled-jobs, third-party-integrations, backend-deployment, ../../performance-review.
Related Knowledge
../../../knowledge/ (critical flows, cost constraints).
Related References
../../../references/backend/observability/ (schema/alert tables, when populated).
Context Loading Guidance
- Requires: runtime shape, critical-flow list, async surface inventory.
- Does not require: vendor documentation, dashboard cosmetics.
- May load:
backend-error-handling (log points), queues/scheduled-jobs (metrics).
- Stop when: schema, metrics, checks, and alerts are recorded.
Token Efficiency Guidance
Three tables carry the design: log schema fields, metric list per surface, alert list (symptom → threshold → owner).
1---2name: backend-observability3description: Use to plan backend observability — structured PII-safe logging with request correlation, metrics (rate/errors/duration, queues, jobs), health checks, alerting on symptoms, and tracing when the topology earns it.4---56# Backend Observability78## Purpose910Make the backend diagnosable and its failures visible: structured logs you can query, metrics that answer "is it healthy," alerts that fire on user-facing symptoms, and correlation from request to log line.1112## When to Use1314- When establishing a backend foundation, before incidents — not after the first one.15- **Not** for client-side analytics or product metrics.1617## Inputs1819- Deployment/runtime shape (where logs/metrics can go); async surfaces (`queues`, `scheduled-jobs`).20- Critical user flows (what must alert when broken).2122## Discovery Questions2324- Where do logs and metrics land (platform-provided vs chosen stack — a vendor decision)?25- Which flows are business-critical enough to page on?26- What volume/cost constraints bound log verbosity?2728## Responsibilities2930- **Structured logging**: JSON logs with level, timestamp, **request/correlation ID** (generated at ingress, propagated through services, jobs, and outbound calls), route, actor ID (not PII), duration, outcome. Levels used consistently; debug off in production by config.31- **PII/secret safety**: denylist-by-design — no tokens, passwords, emails-in-clear, payload dumps; redaction at the logger, not by discipline (`backend-security` audit events coordinate here).32- **Metrics**: RED per endpoint class (rate, error %, duration percentiles), plus queue depth/job failures (`queues`), scheduled-job heartbeats (`scheduled-jobs`), external-call latency/error per provider (`third-party-integrations`), DB pool/query health (`../../database/database-performance`).33- **Health checks**: liveness (process up) vs readiness (dependencies reachable) — separate endpoints, used by the deploy target (`backend-deployment`).34- **Alerting on symptoms**: error-rate and latency thresholds on critical flows, DLQ growth, missed schedule heartbeats — every alert actionable, with a route to logs via the correlation ID.35- **Tracing**: adopt distributed tracing when multiple services/queues make log-hopping painful — a justified addition, not a default.3637## Required Workflow38391. Choose log/metric destinations (approval if new vendor/infra).402. Define the log schema + correlation-ID propagation (HTTP → jobs → outbound).413. Define the metric set per surface (endpoints, queues, schedules, providers, DB).424. Define liveness/readiness checks.435. Define alerts for critical symptoms, each with an owner and a runbook line.446. Verify redaction with a test (secret-shaped values never reach the sink).4546## Decision Rules4748- Log events, not narration: one entry per request/job outcome beats step-by-step spam.49- Alert on user-visible symptoms (error rate, latency, backlog), not causes (CPU) — causes go on dashboards.50- Correlation ID crosses every async boundary or debugging stops at the queue.51- Sampling/retention are cost decisions — record them; don't discover them on the invoice.5253## Rules5455- No PII/secrets in logs — enforced by redaction code, verified by test.56- Every alert has an owner and an action; unactionable alerts get deleted, not muted.57- Health checks are cheap and dependency-honest (readiness fails when the DB is gone).5859## Anti-Patterns6061- `console.log` prose scattered through services.62- Logging request/response bodies wholesale.63- One `/health` returning 200 unconditionally.64- Alerts on every 5xx blip → pager fatigue → ignored pages.65- Request ID that dies at the queue boundary.6667## Validation Checklist6869- [ ] Log schema + levels + correlation propagation defined.70- [ ] Redaction wired and tested.71- [ ] Metrics per surface (RED, queues, schedules, providers, DB).72- [ ] Liveness/readiness split and wired to deploys.73- [ ] Symptom alerts with owners/runbooks.74- [ ] Tracing decision recorded (adopted or explicitly deferred).7576## Definition of Done7778A recorded observability design — structured correlated PII-safe logs, per-surface metrics, honest health checks, actionable symptom alerts, and an explicit tracing decision — wired into deploy and job surfaces.7980## Related Skills8182`backend-error-handling`, `backend-performance`, `backend-security`, `queues`, `scheduled-jobs`, `third-party-integrations`, `backend-deployment`, `../../performance-review`.8384## Related Knowledge8586`../../../knowledge/` (critical flows, cost constraints).8788## Related References8990`../../../references/backend/observability/` (schema/alert tables, when populated).9192## Context Loading Guidance9394- **Requires:** runtime shape, critical-flow list, async surface inventory.95- **Does not require:** vendor documentation, dashboard cosmetics.96- **May load:** `backend-error-handling` (log points), `queues`/`scheduled-jobs` (metrics).97- **Stop when:** schema, metrics, checks, and alerts are recorded.9899## Token Efficiency Guidance100101Three tables carry the design: log schema fields, metric list per surface, alert list (symptom → threshold → owner).