Metrics, Logs and Traces
Overview
A system with many servers always has something misbehaving. Monitoring is watching it for known problems; observability is having data rich enough to figure out problems nobody predicted. That data comes in three kinds: metrics, logs and traces.
Detailed Notes
What is monitoring and observability
Monitoring asks "is the thing I expected to break broken?" using predefined dashboards and alerts. Observability asks "why is it behaving this way?" by letting you explore the data with new questions. Monitoring is one part of observability.
The data that makes both possible is called telemetry, and it has three kinds:
- Metrics: numbers measured over time, like requests per second or memory used. Small and cheap, great for graphs and alerts.
- Logs: timestamped records of individual events, like "user 42 failed to log in". Detailed but bulky.
- Traces: the path of one request through many services. Each step is a span (a timed piece of work), and all spans of one request share a trace ID.
The problem it solves
Simple systems fail in predictable ways, so fixed checks are enough. Distributed systems fail in new ways every month, and no single server can tell you why checkout is slow. Without telemetry you are guessing, and every minute of guessing is a minute users suffer.
How it works
The pipeline:
- Services emit metrics, logs and spans.
- A collector (agent) gathers them and forwards them.
- Each kind goes to a store built for it (for example a time-series database, which is built for numbers over time, for metrics).
- Dashboards, alerts and query tools let people and automation use it.
Structured logs. Write logs as key-value data (usually JSON) instead of free text, so tools can filter by field:
{"level":"error","service":"payment","trace_id":"a1b2c3","msg":"connection pool exhausted"}
Putting the trace ID in every log line lets you jump from a slow trace to the logs of that request.
Cardinality is how many distinct values a label can take. A region label (5 values) is fine. A user_id label (millions of values) creates millions of separate time series and can overwhelm a metrics system. Keep such detail in logs and traces.
A simple example
An online store's customers complain that checkout "sometimes hangs". CPU graphs look fine.
- A metric shows checkout's slowest-1% latency jumped from 300 ms to 6 seconds.
- A trace of one slow request shows 5.5 seconds spent waiting on the payment service.
- The payment service's logs repeat "connection pool exhausted".
Metrics said something is wrong, the trace said where, the logs said why.
System design example
Every service emits the same three signals, a collector ships them to central stores, and one console shows dashboards and alerts. More detail means easier debugging but higher cost, so teams sample traces and limit log retention.
Summary
- Monitoring watches for known problems; observability lets you investigate unknown ones.
- Metrics tell you something is wrong, traces tell you where, logs tell you why.
- Use structured logs with a shared trace ID to connect all three.
- Keep metric labels low-cardinality and control retention and sampling to manage cost.
Architecture Diagram
Services emit metrics, logs and traces that are collected and used by humans.
- 1Applications and infrastructure emit metrics, logs and spans.
- 2A collector gathers them and ships them to purpose-built stores.
- 3Dashboards show trends; alerts notify people when rules trigger.
- 4The engineer uses all three signals to find the cause.
Common Interview Questions
Finished this lesson?
0 of 91 lessons done · 0% of the course

