Chapter 11: Observability
Monitoring tells you when something is wrong. Observability tells you why. In a distributed system you cannot predict every failure mode in advance, so the useful property is not a wall of pre-built alerts but the ability to understand the system’s internal state from its external outputs: to ask arbitrary new questions, and debug problems you have never seen before, without deploying new code. This chapter builds that ability for a real system, the tracer and then the production serving platform, one signal at a time.
Concepts from other sections (18)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Service Level Objective (SLO): a target for a defined measure of service behavior over a specified window. Read more: Chapter 13: Engineering Acronyms in Software Engineering
- Control plane: the API server, etcd, scheduler, and controller manager, which store desired state and decide what should run where; worker nodes carry out those decisions. Read more: Chapter 10: Kubernetes Workloads and Deployment
- error budget: , the fraction of requests allowed to be bad. Read more: 11.4 SLOs and multi-window burn-rate alerts
- burn rate: the error ratio divided by the error budget; 1 spends the budget exactly over the period. Read more: 11.4 SLOs and multi-window burn-rate alerts
- Request id: a caller-chosen id that makes a signal idempotent; stored in run state rebuilt from history. Read more: 7.8 Signals, cancellation, and sagas
- SLI: the fraction of good requests over a window. Read more: 11.4 SLOs and multi-window burn-rate alerts
- Feature flag: a runtime switch that turns behavior on or off without a deploy, decoupling deploying code from releasing it. Read more: Chapter 9: Cloud Native Architecture
- Chaos engineering: deliberately injecting failures (killing a pod, adding latency, partitioning the network) to test the hypothesis that a system tolerates them; it starts with a small blast radius and a defined steady-state metric, and needs good observability to be safe. Read more: Chapter 3: The Testing Mentality in Software Engineering
- Blameless postmortem: the fixed-shape record of one incident that names system properties, not people. Read more: 12.1 First drill: the engine crashloops
- Game day: a scheduled exercise that injects a known fault into a running system so the team practises detection, mitigation, and runbooks before a real incident. Read more: Chapter 12: Incident Response and Recovery
- OTLP/HTTP JSON: the OpenTelemetry export format used here, one
ExportTraceServiceRequestPOSTed to/v1/traces. Read more: 23.8 Serving metrics and tracing in AI Engineering - capped label: a label that keeps its first 64 distinct values per process and folds later ones into
_other. Read more: 11.3 Metrics and log correlation - PodMonitor: a Prometheus Operator object that scrapes a named container port of matching pods. Read more: 11.3 Metrics and log correlation
- OpenTelemetry Collector: the service that receives OTLP, processes it, and exports traces and metrics to their backends. Read more: 11.3 Metrics and log correlation
- Drill profile: burn-rate windows compressed 12x (5 min and 25 s) so a short drill can page. Read more: 12.2 A decode worker dies mid-stream
- training step: one zero-grad, loss, finiteness check, backward, clip, and optimizer update on one batch. Read more: 6.6 Training loop and the autograd bigram in AI Engineering
- Dead letter: an activity whose retries are exhausted, parked in the DLQ with
ActivityDeadLettereduntil an operator redrives it. Read more: 7.5 Activities - schedule-to-start latency: the time a task waits in its queue before a worker picks it up. Read more: 11.6 Observability for the control plane
The arc is from one request to the whole fleet. It starts with a single trace that crosses the gateway and the engine, written by hand so that every id and timestamp is visible. It then generalizes tracing into a small kit every Go service shares, adds metrics and logs that join to traces by id, turns those metrics into SLOs and burn-rate alerts, and puts the answers on dashboards kept as code. It ends by applying the same rules to the durable control plane, where the last hop is a short-lived Python process. By the end, an on-call engineer paged at night can go from the alert to the dashboard to the one slow request’s trace and logs in a few minutes, which is exactly what the drills of the next chapter test.
Learning objectives
- Explain the difference between monitoring and observability, and why high-cardinality, high-dimensionality structured events matter.
- Propagate W3C trace context across HTTP, gRPC, durable workflows, and subprocesses, so one request or one training run is one trace.
- Serve contract metrics with bounded cardinality, scrape them with Prometheus, and correlate logs with traces by id.
- Define SLOs, compute error budgets and burn rates, and write multi-window burn-rate alerts that page when they should and only then.
- Keep dashboards as code that answer an incident’s first questions, including latency heatmaps that reveal a second mode.
Before you begin
Section titled “Before you begin”This chapter assumes some production experience and the material of Cloud Native: containers, Kubernetes, and Helm. The sections instrument a system built elsewhere, so it helps to have read Tracer deploy in this book, The tracer gateway in AI Engineering, and Your first endpoint in AI Engineering. The primary reference is Observability Engineering by Charity Majors, Liz Fong-Jones, and George Miranda (O’Reilly); the free Google SRE Book is the supplementary one.
Core ideas
Section titled “Core ideas”Observability versus monitoring. The three pillars, logs (events), metrics (aggregated numbers), and traces (request flow across services), are necessary but not sufficient. Two properties decide whether you can debug something new. High cardinality means many unique values, such as user ids and request ids; metrics cannot afford them, but events can. High dimensionality means many attributes per event, and structured events with rich context are what make ad-hoc queries possible. Observability is structured events plus ad-hoc queries; the ability to ask “what is different about the slow requests?” is the differentiator.
Instrumentation. OpenTelemetry is the vendor-neutral standard for traces, metrics, and logs: an SDK, a collector, and exporters. A span is a unit of work with a start time, duration, and attributes, and nested spans form traces. Context propagation carries the trace id across service boundaries in headers (W3C Trace Context). Instrument service boundaries, database calls, external API calls, queue publish and consume, and significant business logic. The practical rule is to instrument at the boundaries first and add internal instrumentation only when debugging requires it.
Debugging with observability. The core analysis loop is: notice a symptom, form a hypothesis, query to test it, then refine or pivot. Given slow requests, ask which dimensions differ from fast ones (perhaps all the slow ones hit shard 7). Heatmaps show the latency distribution over time and reveal bimodal distributions that a p99 line hides. Monitoring cannot alert on failure modes you never anticipated, the unknown unknowns; observability lets you explore them.
SLOs and reliability. An SLI (service level indicator) is a measured quantity, such as the fraction of requests under 200 ms. An SLO (objective) is the target for it, such as 99.9%. An SLA (agreement) is an SLO with business consequences: refunds or credits. The error budget is ; at 99.9% it is 0.1%, or about 8.7 hours a year. Burn-rate alerts fire when the budget is being consumed too fast, not when a single request fails. An error-budget policy says what happens when the budget is exhausted, typically a deployment freeze and a focus on reliability, which makes reliability a first-class engineering concern.
Observability in practice. Every deploy should be observed, and canary analysis compares the new version’s metrics with the baseline. Staging environments lie, so teams test in production with dark launches, feature flags, and traffic mirroring. Progressive delivery moves from canary to a percentage rollout to full rollout, with automatic rollback on SLO violation. Chaos engineering deliberately injects failures (Chaos Monkey, Litmus) to verify resilience, and is only safe with good observability already in place.
Organization and culture. Observability is a cultural practice, not just a tooling choice. Blameless postmortems focus on systems and processes rather than individuals: what can we change so this class of failure cannot happen again? Incident response uses structured roles (incident commander, communications lead, subject-matter experts) and is practised in game days. Observability-driven development instruments first and builds features second: if you cannot observe it, you cannot operate it. On-call needs a fair rotation, clear escalation paths, and runbooks, and alert fatigue is its enemy.
The practices above come with characteristic anti-patterns:
| Practice | When to use | Anti-pattern |
|---|---|---|
| Structured events | Always; replace unstructured logs | Unstructured log grep as primary debugging |
| SLOs | Every user-facing service | Alerting on every error instead of budget burn |
| Distributed tracing | Multi-service architectures | Tracing only within a single service |
| Canary deploys | Every production deployment | Big-bang deployments |
| Error budgets | Balancing reliability and velocity | “Always be more reliable” (no budget = no shipping) |
| Blameless postmortems | Every significant incident | Blame individuals, skip action items |
Different organizations emphasize different parts of this picture:
| Company | Approach | Focus |
|---|---|---|
| SRE (invented it), SLOs, error budgets | Reliability as engineering discipline | |
| Netflix | Chaos engineering (Chaos Monkey), progressive delivery | Resilience through failure injection |
| Anthropic | ML system observability, inference SLOs | GPU utilization, latency percentiles |
| Amazon | Well-Architected Framework, COE (Correction of Errors) | Operational excellence |
| Honeycomb | Observability 2.0 (structured events, BubbleUp) | Debugging novel problems |
In this chapter
Section titled “In this chapter”- One trace from gateway to engine: spans,
traceparentpropagation, and OTLP/HTTP JSON, built by hand into a gateway exporter that can never slow a request, with the result checked in Jaeger. - Tracing for the serving path: the
go/otelxkit that every Go service shares, with HTTP and gRPC propagation, CLIENT spans that cover streamed bodies,ParentBasedsampling, and batch export. - Metrics and log correlation: contract histograms with exact bounds, capped labels, PodMonitors, the OpenTelemetry Collector, and JSON logs that grep by trace id.
- SLOs and multi-window burn-rate alerts: error budgets, burn rates, two-window alerts in prod and drill profiles, rendered from one SLO file and tested with
promtool. - Dashboards as code for the serving path: a portable Grafana dashboard with one row per incident question, and heatmaps that show what a p95 line hides.
- Observability for the control plane: one trace from the CLI to a Python training step, and a queue dashboard for depth, dead letters, redeliveries, and schedule-to-start latency.
Key terms
Section titled “Key terms”- Three pillars of observability: logs (discrete events), metrics (aggregated numbers), and traces (request flow across services); necessary but not sufficient for debugging problems nobody anticipated.
- High cardinality: an attribute with many unique values, such as user or request ids; metrics cannot afford it, but structured events can, and it is what lets you isolate one user’s or one request’s behavior.
- High dimensionality: many attributes per event; rich structured events are what make arbitrary new queries possible.
- OpenTelemetry (OTel): the vendor-neutral standard for traces, metrics, and logs, made of an SDK, a collector, and exporters.
- Context propagation: carrying the trace id and span id across service boundaries, in headers such as W3C Trace Context’s
traceparent, so one request across many services forms one trace. - Service level agreement (SLA): an SLO with business consequences, such as refunds or credits when it is missed.
- Canary analysis: comparing a new version’s metrics against the baseline while it serves a small share of traffic, to decide whether to continue the rollout.
- Dark launch: deploying new code to production with its behavior hidden from users, so it can be exercised and observed before release.
- Traffic mirroring: copying live requests to a new version whose responses are discarded, to test it on real traffic with no user impact.
- Progressive delivery: releasing in stages from canary to a percentage rollout to full rollout, with automatic rollback when an SLO is violated.
- Observability-driven development: instrumenting a feature before or as it is built, on the rule that you cannot operate what you cannot observe.
- Alert fatigue: the desensitization that follows too many low-value pages, until on-call engineers miss or ignore the alerts that matter.
Further reading
Section titled “Further reading”- Charity Majors, Liz Fong-Jones, and George Miranda, Observability Engineering (O’Reilly)
- Google SRE Book (free) and The Site Reliability Workbook (free online)
- DORA metrics, for measuring delivery performance alongside reliability