The Four Signals: Metrics, Logs, Traces and Profiles
A customer writes in: "I tried to pay three times and it was so slow I gave up." Your uptime checker says the shop is up, and your alert says checkout is slow. But slow where, and why? To answer, engineers use four kinds of telemetry, the data a running system reports about itself: metrics, logs, traces and profiles. Each one answers a different question. This lesson shows which one to reach for and how they fit together.
Metrics: the vital signs
A metric is a number measured again and again over time, such as requests per second, the percentage of requests that fail, or memory in use. Each measurement is stored with its time, so you get a line you can draw on a graph. Because each point is only a number and a timestamp, metrics are cheap to keep for months.
Metrics are the best tool for two questions: is something wrong, and how bad is it? They power the dashboards and alerts from the previous lesson. What they cannot tell you is why. A graph showing checkout time jumping from 0.4 to 2.3 seconds does not say which customers were hit or what went wrong.
Logs: the diary
A log is a stream of timestamped messages a program writes as it works, usually one line per event. Each line can say exactly what happened, for example "fraud check slow for order 8812, retrying", with as much detail as the programmer chose to include.
That detail makes logs the best answer to "what exactly happened?", and it also makes them expensive. A busy shop can write millions of lines an hour, and every line must be sent, stored and kept searchable. For that reason, many teams keep logs for only days or weeks.
Traces: the route
A modern app is often split into services, separate programs that call each other over the network: one for the shop page, one for the cart, one for payments. A single click on "Pay" can pass through five of them.
A trace follows one request on that journey. Each timed step is a span, with a name, a start time and a duration, and spans nest inside each other like a family tree. Every span carries the same trace ID, a unique label for that one request. Drawn as bars, a trace shows at a glance where the time went: the checkout took 2.3 seconds, and 2.1 of them were spent in payments.
Profiles: the X-ray
A trace points at the slow service but not at the slow code inside it. A profile does that. A profiler looks inside a running program many times per second, notes which function is running at that moment, and counts the results. Functions that turn up in many samples are where the processor's time, called CPU time, goes. Memory profiles do the same for memory.
Profiles are often drawn as a flame graph: stacked blocks, where a wider block means more CPU time. They answer the most detailed question of the four: which function is the cost? For example, "fraud_check() uses 62% of the payment service's CPU".
How the four work together
The signals are most useful in sequence, each one narrowing the search. Here is how the slow-checkout complaint might be solved.
An alert based on a metric says checkout is slow. You open the trace of one slow checkout and see that payment took most of the time. You copy that request's trace ID and search the logs for it, finding warnings that the fraud check was retried three times. Finally, the payment service's profile shows fraud_check() spending most of its CPU time reloading a list of rules, which you can keep in memory instead.
The trace ID is what ties the signals together. When services write it into every log line, one search takes you from a trace to its exact log lines. OpenTelemetry, an open standard you will meet later in this course, helps apps produce all four signals in a consistent way.
Check yourself
A graph shows errors jumped to 6%. Which signal do you open to read the exact error message?
Logs, because they record each event with its details, while the metric only counts them.
A checkout takes 3 seconds and passes through five services. Which signal shows which service took the time?
A trace, because its spans time each step of that one request across all the services.
What links a trace to the log lines of the same request?
The trace ID, which every span carries and which services can also write into every log line.
Go deeper
- The beginner’s guide to Observability: the everyday vocabulary of observability work, one term at a time.
- Exploring the Power of Observability with OpenTelemetry Collector: how one collector gathers these signals and sends them where you need them.