Overview
Curated: · Written: · Reviewed:
Monitoring, Logging & Tracing
In one line
Metrics show that something is broken and since when, logs show what one request did, and traces show where the time went across services. Reach for metrics for rates and alerts, logs for a single event, and traces for a causal path that crosses hops.
Key definitions
- Counter: a cumulative value that only increases and resets to 0 when the process restarts. Query it with
rate(). - Gauge: a current value that rises and falls, such as queue depth.
- Histogram: buckets that preserve a distribution, so percentiles can be computed from them. Never average precomputed percentiles across instances.
- Series cardinality: the number of unique label sets. Each one is a separate time series with its own memory and storage cost.
- Trace context: the trace ID and parent span ID carried in
traceparentacross HTTP and messaging boundaries. - Exemplar: a metric observation linked to a representative trace ID.
Formulas and complexity
Series count for bounded labels is the product of the label value counts:
For http_requests_total with method (4), route (18) and status (7), the upper bound is 4 × 18 × 7 = 504 series. Adding user_id with 60,000 values gives at most 504 × 60,000 = 30,240,000 series. At the sizing note's roughly 1 KB per active series, that is about 30 GB of head memory, against an 8 GB instance (hypothetical, assuming every combination occurs).
Burn rate, for a 99.9% SLO:
An observed 0.4% error rate is a burn of 4. A sustained burn of 14.4 for one hour consumes 14.4 × 1/720 ≈ 2% of a 30-day budget.
How it works
The SDK in each service emits metrics, logs and spans. The Collector routes each signal to its backend. Exemplars and trace IDs on log lines are the links between them.
- A metric answers that and since when, across an aggregate.
- A log line answers what this request did, but only if its
trace_idis on the line. - A span tree answers where the time went. Self time is a span's duration minus its children's durations.
- Traces created by a producer and consumed later link only if the trace context travels in the message headers.
When to use and when not to
| Question | Use | Avoid |
|---|---|---|
| Are users affected, since when? | Metrics: error ratio, latency histogram | Averages for skewed latency |
| Which tenant or endpoint? | Dimension on a bounded label, or a span attribute | user_id as a metric label |
| Why did this request fail? | Logs with trace ID, plus the full trace | Metrics, which have no per-request detail |
| Which hop is slow? | Trace with span attributes | Head sampling alone, which drops failures |
| Is the telemetry itself healthy? | Pipeline lag, drop counts, agent health | Treating an empty graph as zero |
Traps interviewers probe
- Putting
user_idorrequest_idin a metric label. Fix: keep metric labels to bounded enumerations. Put identity on the span and the log line. - Trusting the mean. Fix: use histogram percentiles. Take a window of 10,000 requests where 9,800 take 20 ms and 200 take 2,000 ms. The mean is 59.6 ms, under a 100 ms target, but 2% of requests at 2,000 ms means p99 is about 2,000 ms, breaching a 500 ms SLO.
- Assuming head sampling keeps the failures. Fix: use tail sampling that always keeps errors and slow traces. At 1% head sampling, the chance of missing all 40 failures out of 10,000 requests is 0.99^40 ≈ 0.67.
- Reading a green dashboard as healthy. Fix: alert on missing data and export drop counts, and make missing data visibly different from zero.
- Treating one complete-looking trace as proof. Fix: say it proves only the sampled path. Check the trace's span count and propagation before arguing that the latency is fully accounted for.
Interview tips
Open by naming the question the operator is trying to answer, then the signal that answers it and the way that signal fails. Use this order: detect with metrics, locate with traces, explain with logs.
Expect these follow-ups:
- How do you know your telemetry is complete? Answer with drop counts, pipeline lag and coverage checks.
- What pages and what does not? Answer with burn-rate alerts on user symptoms. Component metrics support diagnosis only.
- How do you keep the exporter from taking down production? Answer with bounded queues, export timeouts and a measured drop policy.
- How do you control cardinality? Answer with the decision rule: unbounded dimensions go to logs or span attributes.
30-second outline: "Metrics tell me that the 5xx ratio on checkout crossed the burn threshold and since when. I'd split it by bounded labels such as route and region. Traces show which downstream hop holds the time, and logs with the trace ID explain one failing request. I'd keep errors and slow traces through tail sampling, and alert on missing telemetry as well as on user symptoms."
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.