Module 6 · Reliability and infrastructureLesson 61 of 888 minIntermediate
Observability: logs, metrics, traces
Observability is being able to answer "what is my system doing and why?" from the outside, using logs, metrics and traces.
Make payment slow and watch which chart changes and how the orange trace shows the slow hop. Then make it fail and read the error logs.
Monitoring tells you that something is wrong. Observability lets you work out why, even for problems you never predicted. It rests on three kinds of signal.
Metrics
Numbers measured over time: requests per second, error rate, p95 latency, CPU, queue length.
- Cheap to store and fast to query.
- Perfect for dashboards and alerts.
- But they're aggregates; they can't tell you about one specific request.
A popular checklist is RED for services (Rate, Errors, Duration) and USE for resources (Utilization, Saturation, Errors).
Logs
Timestamped records of events: "payment failed for order 812: card declined".
- Rich detail, great for investigating.
- Expensive at volume. Use structured logs (JSON with fields like
user_id,order_id,trace_id) so they can be searched, and don't log everything at debug level in production.
Traces
A trace follows one request across every service it touches. Each step is a span with a start time and duration; spans nest to form a tree. A trace id passed in request headers ties them together.
- Shows where time went: "of 900 ms, 820 were in payment's call to the card provider".
- Usually sampled (keep, say, 1% of traces, plus all slow or failed ones) to control cost.
Using them together
- An alert on a metric fires: checkout p95 is up.
- A dashboard narrows it: only the payment service's latency rose.
- A trace of a slow request shows the slow span.
- Logs for that trace id show the exact error.
The glue is correlation: put the trace id in every log line, and link from metrics to example traces.