Skip to content

Observability and SLOs

Phase 5 · Shipping and operating · 14 min read · 5 Atlas cases linked

What you'll be able to do

  • Choose logs, metrics, and traces to investigate a slow or failing request.
  • Define a request SLO, calculate its error budget, and interpret a burn rate.
  • Design an actionable alert and use incident evidence to improve the service.

From monitoring to observability

Monitoring checks known failures: is the process alive, is CPU full, are requests failing? Observability collects evidence to ask new questions, such as “Which dependency made one model version slow?” Instrument request paths, then test hypotheses.

The three signals have different jobs. Metrics summarize events cheaply. Logs record events with context. Traces connect work across services. A dashboard shows a latency spike; a trace identifies the slow step; a log explains a failure. Detail costs storage and processing, so retain and sample deliberately.

A log line should be one JSON event with a timestamp, level, message, and stable fields. Use request_id to connect one request's events and trace_id across services. Hash or pseudonymize user IDs when appropriate; hashes remain linkable data requiring privacy controls. Never log secrets, raw private prompts, or unnecessary personal information.

Python's logging has loggers (where code emits events), levels (DEBUG, INFO, WARNING, ERROR), handlers (where events go), and formatters (how they appear). extra adds searchable fields:

import logging

logger = logging.getLogger("checkout")
handler = logging.StreamHandler()
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.info("payment timed out", extra={"request_id": "r-42", "attempt": 2})

The default formatter omits those extra fields; configure a JSON formatter. Avoid logger.info(f"request {request_id} failed"): free text is harder to group and may expose private input. Set retention limits and sample repetitive success or debug logs. Sampling can omit individual events; use metrics for totals.

Use a counter for accumulating events (requests, errors), a gauge for a current value (in-flight requests), and a histogram for a distribution (latency). Histograms count observations in fixed ranges and estimate percentiles. If 99 requests take 100 ms and one takes 10 seconds, the mean is (99 × 100 + 10,000) / 100 = 199 ms; one user still waited 10 seconds. Track latency distribution alongside volume.

For services, RED asks about request rate, errors, and duration. For resources, USE asks about utilization, saturation (queued work), and errors. Start dashboards with the “golden signals”: latency, traffic, errors, and saturation. Break them down by useful dimensions such as route or status class, not vanity panels.

Metric labels multiply series. If route has 20 values and status_class has 5, that is up to 20 × 5 = 100 series for one metric. Adding a distinct request_id for every request makes the number grow without bound. Keep request IDs in logs and traces, never metric labels. A Prometheus-style pull model is one example: a collector periodically fetches metrics exposed by a service. The data model matters more here than the collector choice.

Traces: follow one request

A trace is a tree of spans. Each records an operation's start and end; child spans represent work inside a parent. An API, retrieval service, and model server can share a trace ID if each propagates context to the next. A waterfall reveals overlapping work, serial waits, and the slow dependency. Metrics show how often it happens. Trace storage is costly, so sample. To keep slow and failed traces, decide after the request finishes (tail sampling), or collect those outcomes separately; sampling decided at the start of a request can miss them.

A trace: the api span contains retrieve and model spans; the longest child sets the request time.

Turn symptoms into an SLO

An SLI is a measured indicator of service behavior. An SLO sets its desired level over a window. An SLA is a customer agreement that may attach consequences to a missed commitment. Choose an SLI from what the user experiences, not from an internal component's uptime.

Suppose a request is good only when it is non-5xx and finishes under 300 ms. Set an SLO of 99.9% good requests over a rolling 30-day window. If there are 1,000,000 eligible requests, the budget is (1 − 0.999) × 1,000,000 = 1,000 bad requests. A slow 200 response spends budget, as does a fast 5xx. Define which requests count (for example, health checks and client cancellations) before measuring.

The equivalent time fraction is 0.1% × 30 × 24 × 60 = 43.2 minutes. That is a useful intuition for continuous availability, not a conversion of this request-based SLO into guaranteed downtime: a busy minute can consume many more bad requests than a quiet minute. A separate time-based availability SLO, which classifies each minute as available or unavailable, does allow (1 − target) × window minutes of unavailable time. An SLO of 100% leaves no budget for change or inevitable failures. Pick a target that reflects user needs, then revisit it with observed data.

Burn rate is the current bad-request ratio divided by the allowed ratio. With a 99.9% target, the allowed bad ratio is 0.1%. If 1% of requests are bad, burn rate is 1% / 0.1% = 10: at this error ratio, bad requests occur at 10 times the allowed share of eligible requests. How many budget requests that consumes per minute still depends on traffic. A multi-window alert can require both a short and a longer window to burn quickly, so one brief blip does not page everyone.

Alerts and incidents

Page the on-call responder for sustained user symptoms needing action now, such as fast budget burn; acknowledge, mitigate, and escalate if needed. Ticket slower capacity trends. “CPU above 80%” is a weak page: high CPU may be harmless. Each page should name the service and SLI, link evidence, and point to a runbook with safe checks and mitigation. Unactionable pages cause alert fatigue.

During an incident, follow evidence rather than a favorite explanation. A brief “five whys” chain might be: users saw 5xx because requests timed out; they timed out because workers queued; workers queued because downstream calls retried together; retries synchronized because a deploy shortened a timeout without backoff; the change escaped because the load test did not cover retries. Verify each link with metrics, traces, deploy history, and logs. After recovery, write a blameless postmortem: timeline, impact, contributing conditions, what detection and response worked, and concrete changes with owners. The point is to improve the system and its safeguards, not to find someone to blame.

For AI engineers

For AI engineers

A model-serving request has more than one latency: time to first token affects perceived responsiveness, while total time affects completion. Record token counts and estimated cost per request, error, timeout and refusal rates, cache hit rate, and retrieval quality signals. Put model and prompt versions on each event so a regression can be tied to a rollout. Watch input distribution drift, but treat it as evidence to investigate, not proof of harm. Full prompts and outputs may be useful for debugging; sample them only with privacy controls and a clear retention policy.

A training script that logs only loss can miss data-loading stalls, checkpoint failures, and a silent change in input distribution. A serving system can return successful HTTP responses while answer quality deteriorates. Quality SLOs are harder to define than latency SLOs: use carefully chosen proxies and offline evaluations, and inspect sampled outputs under privacy controls. A 200 response is not an assertion that the answer was good.

Common mistakes

  • Logging unstructured f-strings or private inputs: use stable fields and redact secrets and personal data.
  • Paging on CPU alone: page on user symptoms, then use CPU to diagnose their cause.
  • Reporting only mean latency: add a distribution and request count so tail delays are visible.
  • Putting user or request IDs in metric labels: unbounded values explode series count.
  • Omitting request and trace IDs: related events become difficult to connect.
  • Making an unread dashboard or a 100% SLO: neither gives a useful operating decision.

Check yourself

A dashboard shows a p95 latency spike after a deploy. Which signals help you find the slow operation and then its error message?

Use traces to find the span that dominates a slow request, then correlated structured logs for that request or trace ID to read its error and context. Metrics show how widespread the spike is.

Your service has a 99.9% good-request SLO. Over 100,000 requests, 40 are 5xx and 80 more return 200 after 300 ms. How much budget remains?

The budget is 0.1% of 100,000, or 100 bad requests. There are 120 bad requests because either failure condition counts, so the budget is overspent by 20 requests.

The bad-request ratio is 0.6% for five minutes and 0.2% for the hour. Would a rule requiring both windows above 4× burn page?

No. The allowed ratio is 0.1%; the short window burns at 6×, but the hour burns at 2×. The rule requires both to be at least 4×.

A metric uses request_id as a label. What breaks, and where should that ID go instead?

Each new ID creates another time series, so storage and query cost grow with traffic. Keep request IDs in structured logs and trace context.

Lab

Build a small observability toolkit in code/observability-slo/. Format structured log events with safe redaction and an injected timestamp. Count latency histogram buckets and estimate a percentile from bucket bounds. Calculate request and time budgets, burn rate, and a two-window page decision. Connect timed parent and child spans and identify the slowest direct child. Run cd code/observability-slo && PYTHONPATH=starter python -m pytest tests -q.

Go deeper

See it in the wild

Open these real architectures and find the idea in the diagram. Predict how it is used before you read the analysis.