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.

Intermediate 3 min readLesson 14 of 20

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

SignalWhatStrengthTools
LogsTimestamped records of discrete eventsRich detail about one eventLoki, Elasticsearch, CloudWatch
MetricsNumeric time series (counters, gauges, histograms)Cheap, aggregatable, ideal for dashboards and alertsPrometheus, Datadog, Grafana
TracesThe path of one request across services, as a tree of timed spansShows where latency and errors come fromJaeger, 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.
JSON
{"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:

MethodForMeasure
REDServices (request-driven)Rate, Errors, Duration
USEResources (CPU, disk, pools)Utilisation, Saturation, Errors
Golden signals (Google SRE)BothLatency, 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.

GET /checkoutauthcart svcpayment svcrender0141112

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.

OpenTelemetry spans
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();
}

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.
AvailabilityDowntime 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.
Key takeaways
  • 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.