SproutStackSproutStack home

Observability: Logs, Metrics, Traces

6 min readBeginner-friendlyFree to read

Before this, it helps to know: Load Balancing Intro.

Read a little, play a little. No scary maths, and no rush.

Share:

The 3am question

Somebody pages you: "checkout is broken for users in Germany." You cannot debug that with a hunch. You need three answers, in this order: is it broken, where is it broken, and why. Three tools, three jobs. Confusing them is why on-call nights go badly.

Metrics: the number on the wall

A metric is an aggregate over time — requests per second, p99 latency, error rate, queue depth, CPU. Cheap to store, cheap to graph, and the right thing to alert on because one number can page a human. Nobody wants an alert that says "log line count changed". A good alert fires on a symptom users feel ("1% of checkouts failing"), not a cause ("CPU at 80%").

Logs: what one instance did

A log is a timestamped event from one process: "payment attempt 3 timed out after 2s". Rich and specific, and expensive — a busy service writes gigabytes a minute. Logs are for investigating after you know something is wrong, not for watching. Give every request a correlation id so one user's flow can be stitched together across services.

Traces: what one request did

A trace follows a single request across every service it touches, with each span timed. This is the one that answers "why was this request slow?" — because you can see that 800ms of a 900ms request went into one downstream call, and which one. This is what OpenTelemetry exists to standardize.

request #7f3a  total 912ms
  ├─ api-gateway        4ms
  ├─ auth               11ms
  ├─ cart-service      38ms
  ├─ pricing-service    9ms
  ├─ inventory-service  62ms
  └─ payment-service   780ms  ← here, and it timed out twice first

The rule that keeps it cheap

Instrument metrics first (cheap, always on), traces second (sample them — 1% of requests is usually enough to find a pattern), and logs always but at a sensible level. Also log at info by default and debug only when switched on; a library that logs by default will be removed from production to save money.

A worked example: checkout broken in Germany

  1. Metrics show it. The checkout error rate has jumped, but only where region = DE. Other regions are normal, which already rules out most causes.
  2. A trace shows where. A sampled failing request spends nearly all of its time in the payment step, specifically calls to the payment provider used for European cards.
  3. Logs show why. Searching for that request's correlation ID finds repeated timeouts against one provider endpoint, starting a few minutes after the provider's own maintenance window began.

The fix is to switch European traffic to the backup provider. Each tool answered exactly one question, in order, and the whole investigation took minutes.

DE onlypaymentsMetricsIs it broken?TracesWhere?LogsWhy?
In the Germany example, metrics showed the errors were only in DE, a trace pointed at the payment step, and logs showed the provider timing out.

Alerts that deserve to wake someone

Alert on what users feel: error rate, latency, failed checkouts. Do not alert on internal causes such as "CPU at 80%," which may be harmless. Every alert should have a clear action; if the response to an alert is usually "ignore it," delete or fix the alert, because noisy alerts teach people to ignore the real ones. Many teams define a target, such as 99.9% of requests succeeding over 30 days, and alert when they are using up their allowed failures too quickly.

Remember this

  • Metrics tell you something is broken. Traces tell you where. Logs tell you why one instance did what it did.
  • Alert on user-visible symptoms, not on causes.
  • Correlation ids are what turn a wall of logs into a single story.

Check your understanding

5 questions · first-try answers earn the most XP

1. Which observability tool answers the question 'why was this one request slow?'
2. What is the practical difference between metrics and logs in a production system?
3. Why should you alert on a user-visible symptom rather than a cause like CPU at 80%?
4. Why should traces usually be sampled rather than recorded for every request?
5. What does a correlation id let you do across a wall of logs?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Practice this in an incident

Try a design drill

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.