Observability
Purpose
Make production behavior explainable from telemetry instead of guesswork. The skill
defines the three pillars concretely: structured logs with stable attributes, RED/USE
metrics wired to SLOs, and trace propagation across every hop — plus the redaction
rules that keep telemetry safe.
When to Use / When NOT to Use
Use when:
- Adding or reviewing logging, metrics, or tracing in a service.
- Debugging requires correlating events across services ("we can't tell what
happened to this request").
- Defining dashboards, SLOs, or alert rules for a new service.
Do NOT use when:
- An incident is active — use
incident-response; instrument later with a
postmortem action item.
- The question is local performance measurement — use
performance (profiling
owns that).
Prerequisites & Assumptions
- Go services log via
log/slog (JSON handler); Java via SLF4J+Logback JSON
encoder; Python via logging with JSON formatting.
- OpenTelemetry SDK for metrics/traces; a collector backend exists (Prometheus/
Grafana, Jaeger/Tempo or equivalent).
- Every service owns an SLO for its critical request path (availability or latency).
Step-by-Step Workflow
- Log with structure — one logger per component (injected, not global);
constant keys (
order_id, user_id, attempt), values as typed attributes;
Info for state changes, Warn for degraded-but-handled, Error for
operator-visible failures with err attribute.
- Propagate context — pass
context.Context (Go) / current span context
through every layer; log with the context variant so trace/log IDs correlate.
- Instrument metrics — RED for services (rate, errors, duration of requests),
USE for resources (utilization, saturation, errors of DB pools, queues);
standard attributes:
service, route, method, status.
- Trace critical paths — spans at service and dependency boundaries (HTTP
server, DB call, queue publish); client spans inherit context; sample at 1–10%
head-based or tail-based for errors.
- Define SLOs and burn alerts — per critical path: target (e.g. 99.9% of
requests < 300 ms), error budget, burn-rate alerts (fast + slow windows).
- Review quarterly — delete unused metrics (cardinality audit), confirm
redaction rules still hold, verify dashboards map to SLOs.
Enterprise Rules & Standards (MUST / MUST NOT)
- MUST use structured logging with constant, snake_case keys; no string-mangled
messages, no
fmt.Println/print.
- MUST redact secrets, tokens, and PII at the logging layer (redaction
middleware or typed field wrappers); a token never appears even at DEBUG.
- MUST include the correlation keys (
trace_id, request_id, user_id where
lawful) in error logs.
- MUST propagate trace context across every process and queue boundary.
- MUST attach the underlying error to error logs (
slog.Any("err", err) /
exception field), never log-and-continue silently.
- SHOULD log state transitions ("order cancelled"), not method entries; entry/
exit logs double volume for no insight.
- SHOULD bound metric cardinality: no unbounded labels (user IDs, URLs with
IDs) — normalize routes.
- MUST NOT log at ERROR for expected business outcomes (validation failures
are WARN/INFO with counters).
- MUST NOT create metrics with user-specific label values.
Examples
Good — structured, correlated, redacted (Go, compiles):
logger.InfoContext(ctx, "order cancelled",
slog.String("order_id", id),
slog.String("trace_id", trace.TraceIDFromContext(ctx)),
slog.Int("item_count", len(order.Items)),
) // no customer name, no raw email, no token
Bad — the log line that leaks and explains nothing:
log.Printf("user %s did something with order %v, err: %v", user, order, err)
Why it fails: unstructured (unqueryable), leaks user identity, vague action text,
and the error is printed but the operation continues as if nothing happened.
Metric naming (good):
http_server_request_duration_seconds{service="orders",route="/v1/orders/:id",method="GET"}
Checklist
Common Pitfalls
- Debug-by-printf in prod — unstructured strings that no query can join;
structure from day one.
- Cardinality explosion — a label per user/URL ID melts the metrics backend;
normalize and bound.
- Log-and-swallow — logging an error and returning success; decide: handle, or
propagate, never both-neither.
- Dashboard sprawl — 40 charts nobody reads; dashboards mirror the SLO and its
dependencies only.
References
1---2name: observability3description: 'Instruments services with structured logging (slog), metrics (RED/USE), and distributed tracing via OpenTelemetry — with PII redaction and SLO wiring. Trigger with "add logging", "we can not debug this in prod", or "set up tracing/metrics".'4metadata:5 source: https://skillmd.com/skills/pnguyen215/observability6---78# Observability910## Purpose1112Make production behavior explainable from telemetry instead of guesswork. The skill13defines the three pillars concretely: structured logs with stable attributes, RED/USE14metrics wired to SLOs, and trace propagation across every hop — plus the redaction15rules that keep telemetry safe.1617## When to Use / When NOT to Use1819Use when:2021- Adding or reviewing logging, metrics, or tracing in a service.22- Debugging requires correlating events across services ("we can't tell what23 happened to this request").24- Defining dashboards, SLOs, or alert rules for a new service.2526Do NOT use when:2728- An incident is active — use `incident-response`; instrument later with a29 postmortem action item.30- The question is local performance measurement — use `performance` (profiling31 owns that).3233## Prerequisites & Assumptions3435- Go services log via `log/slog` (JSON handler); Java via SLF4J+Logback JSON36 encoder; Python via `logging` with JSON formatting.37- OpenTelemetry SDK for metrics/traces; a collector backend exists (Prometheus/38 Grafana, Jaeger/Tempo or equivalent).39- Every service owns an SLO for its critical request path (availability or latency).4041## Step-by-Step Workflow42431. **Log with structure** — one logger per component (injected, not global);44 constant keys (`order_id`, `user_id`, `attempt`), values as typed attributes;45 `Info` for state changes, `Warn` for degraded-but-handled, `Error` for46 operator-visible failures with `err` attribute.472. **Propagate context** — pass `context.Context` (Go) / current span context48 through every layer; log with the context variant so trace/log IDs correlate.493. **Instrument metrics** — RED for services (rate, errors, duration of requests),50 USE for resources (utilization, saturation, errors of DB pools, queues);51 standard attributes: `service`, `route`, `method`, `status`.524. **Trace critical paths** — spans at service and dependency boundaries (HTTP53 server, DB call, queue publish); client spans inherit context; sample at 1–10%54 head-based or tail-based for errors.555. **Define SLOs and burn alerts** — per critical path: target (e.g. 99.9% of56 requests < 300 ms), error budget, burn-rate alerts (fast + slow windows).576. **Review quarterly** — delete unused metrics (cardinality audit), confirm58 redaction rules still hold, verify dashboards map to SLOs.5960## Enterprise Rules & Standards (MUST / MUST NOT)6162- **MUST** use structured logging with constant, snake_case keys; no string-mangled63 messages, no `fmt.Println`/`print`.64- **MUST** redact secrets, tokens, and PII at the logging layer (redaction65 middleware or typed field wrappers); a token never appears even at DEBUG.66- **MUST** include the correlation keys (`trace_id`, `request_id`, `user_id` where67 lawful) in error logs.68- **MUST** propagate trace context across every process and queue boundary.69- **MUST** attach the underlying error to error logs (`slog.Any("err", err)` /70 exception field), never log-and-continue silently.71- **SHOULD** log state transitions ("order cancelled"), not method entries; entry/72 exit logs double volume for no insight.73- **SHOULD** bound metric cardinality: no unbounded labels (user IDs, URLs with74 IDs) — normalize routes.75- **MUST NOT** log at ERROR for expected business outcomes (validation failures76 are WARN/INFO with counters).77- **MUST NOT** create metrics with user-specific label values.7879## Examples8081Good — structured, correlated, redacted (Go, compiles):8283```go84logger.InfoContext(ctx, "order cancelled",85 slog.String("order_id", id),86 slog.String("trace_id", trace.TraceIDFromContext(ctx)),87 slog.Int("item_count", len(order.Items)),88) // no customer name, no raw email, no token89```9091Bad — the log line that leaks and explains nothing:9293```go94log.Printf("user %s did something with order %v, err: %v", user, order, err)95```9697Why it fails: unstructured (unqueryable), leaks user identity, vague action text,98and the error is printed but the operation continues as if nothing happened.99100Metric naming (good):101102```text103http_server_request_duration_seconds{service="orders",route="/v1/orders/:id",method="GET"}104```105106## Checklist107108- [ ] Logs are JSON with constant keys; no PII/secrets (redaction test exists).109- [ ] Every error log carries the error object and correlation IDs.110- [ ] RED metrics exist for every endpoint; USE metrics for DB pools/queues.111- [ ] Trace context propagates through HTTP clients, DB calls, and queues.112- [ ] SLO defined for the critical path with burn-rate alerts wired.113- [ ] Cardinality audit done: no unbounded label values.114- [ ] Log levels used correctly (no ERROR spam for expected outcomes).115116## Common Pitfalls117118- **Debug-by-printf in prod** — unstructured strings that no query can join;119 structure from day one.120- **Cardinality explosion** — a label per user/URL ID melts the metrics backend;121 normalize and bound.122- **Log-and-swallow** — logging an error and returning success; decide: handle, or123 propagate, never both-neither.124- **Dashboard sprawl** — 40 charts nobody reads; dashboards mirror the SLO and its125 dependencies only.126127## References128129- log/slog (Go): https://pkg.go.dev/log/slog130- OpenTelemetry concepts: https://opentelemetry.io/docs/concepts/131- RED method (Weave): https://www.weave.works/blog/the-red-method-key-metrics-for-microservices-architecture/132- Google SRE — implementing SLOs: https://sre.google/workbook/implementing-slos/