Observability
Logs, metrics and traces; the RED and USE methods; percentiles and histograms; distributed tracing with OpenTelemetry; SLIs, SLOs and alerting that doesn't burn people out.
Monitoring tells you that something is wrong; observability lets you ask why — including questions you didn't anticipate — from the outside, using the telemetry the system emits. In distributed systems, where a request touches dozens of components, it's not optional.
The three pillars
| Signal | What | Strength | Tools |
|---|---|---|---|
| Logs | Timestamped records of discrete events | Rich detail about one event | Loki, Elasticsearch, CloudWatch |
| Metrics | Numeric time series (counters, gauges, histograms) | Cheap, aggregatable, ideal for dashboards and alerts | Prometheus, Datadog, Grafana |
| Traces | The path of one request across services, as a tree of timed spans | Shows where latency and errors come from | Jaeger, Tempo, Honeycomb, X-Ray |
OpenTelemetry is the vendor-neutral standard for producing all three; instrument once, export anywhere.
Logs
- Structured (JSON), not free text: easy to filter and aggregate.
- Include context on every line: timestamp, level, service, trace ID, request ID, user/tenant ID.
- Log levels with discipline; don't log secrets or personal data.
- High volume is expensive: sample debug logs, set retention.
{"ts":"2025-03-01T10:15:02.114Z","level":"error","service":"checkout","trace_id":"4bf92f3577b34da6","msg":"payment declined","order_id":"ord_123","provider":"stripe","latency_ms":412}Metrics
Metric types: counter (only goes up: requests_total), gauge (current value: queue_depth), histogram (distribution: request_duration_seconds buckets).
Two checklists for what to measure:
| Method | For | Measure |
|---|---|---|
| RED | Services (request-driven) | Rate, Errors, Duration |
| USE | Resources (CPU, disk, pools) | Utilisation, Saturation, Errors |
| Golden signals (Google SRE) | Both | Latency, traffic, errors, saturation |
Beware high cardinality labels (user ID, URL with IDs) in metrics: each unique combination is a separate time series and can explode storage. Put such detail in logs and traces.
Distributed tracing
A trace is one request's journey; it's made of spans (one per operation), each with a start, duration, attributes and a parent. The trace context (traceparent header, W3C standard) is propagated on every outgoing call.
The waterfall immediately shows that the payment call dominates. Traces are usually sampled (e.g. 1%, or tail-based: keep all slow and failed traces) to control cost.
Span span = tracer.spanBuilder("charge-card").startSpan();
try (Scope s = span.makeCurrent()) {
span.setAttribute("order.id", orderId);
paymentClient.charge(orderId, amount); // context propagates automatically
} catch (Exception e) {
span.recordException(e);
span.setStatus(StatusCode.ERROR);
throw e;
} finally {
span.end();
}from opentelemetry import trace
tracer = trace.get_tracer("checkout")
with tracer.start_as_current_span("charge-card") as span:
span.set_attribute("order.id", order_id)
payment_client.charge(order_id, amount) # exceptions recorded automaticallyimport { trace, SpanStatusCode } from "@opentelemetry/api";
const tracer = trace.getTracer("checkout");
await tracer.startActiveSpan("charge-card", async (span) => {
try {
span.setAttribute("order.id", orderId);
await paymentClient.charge(orderId, amount);
} catch (e) {
span.recordException(e as Error);
span.setStatus({ code: SpanStatusCode.ERROR });
throw e;
} finally {
span.end();
}
});SLIs, SLOs and error budgets
- SLI (indicator): a measured ratio of good events — "fraction of requests served successfully in under 300 ms".
- SLO (objective): the target — "99.9% over 30 days".
- SLA (agreement): a contractual promise with penalties, usually looser than the SLO.
- Error budget: 100% − SLO. At 99.9%, you may "spend" 0.1% (about 43 minutes a month). If the budget is healthy, ship faster; if it's burned, prioritise reliability.
| Availability | Downtime per month |
|---|---|
| 99% | 7.3 hours |
| 99.9% | 43.8 minutes |
| 99.99% | 4.4 minutes |
| 99.999% | 26 seconds |
Alerting
- Alert on symptoms users feel (SLO burn rate, error rate, latency), not every cause (CPU at 80%).
- Every page must be actionable and urgent; everything else is a ticket or a dashboard.
- Use burn-rate alerts: page when the error budget is being consumed fast enough to run out in hours.
- Link alerts to runbooks; review noisy alerts after incidents.
- Logs (events), metrics (aggregates), traces (request paths) — correlated by trace ID; use OpenTelemetry.
- RED for services, USE for resources.
- Measure percentiles from histograms; avoid high-cardinality metric labels.
- Distributed tracing reveals where latency lives across services.
- Define SLOs and error budgets; alert on user-facing symptoms with runbooks.