Logs, metrics and traces
A system you can ask questions
Section titled “A system you can ask questions”At 03:12 a customer cannot check out. You cannot attach a debugger to a production system for every request, and you cannot ask the system what it is doing. What you have is what it wrote down while it ran.
OpenTelemetry’s primer defines observability as the ability to understand a system from the outside, by asking questions about it without knowing its inner workings. The data the system emits so that you can ask those questions is its telemetry, and the primer names three kinds: logs, metrics and traces. Which kind you reach for decides how fast you find the answer.
The system in this module is a small online shop. Customers reach a Shop application, which calls a Product database on every request, and calls a Payment provider and an Email delivery service on the 5% of requests that are checkouts. Traffic is 300 requests a second.
Three kinds of record
Section titled “Three kinds of record”| A log | A metric | A trace | |
|---|---|---|---|
| One record is | A timestamped record of one event | A measurement captured at runtime, combined with others over a time window | The path of one request through the services, made of spans |
| It answers | What happened, to this request, at this moment? | How much, how often, and is it getting worse? | Where did this request spend its time? |
| Its cost grows with | The number of events | The number of distinct label combinations | The number of requests kept |
| It is weak at | Showing a trend: you must count lines | Showing one request: the individual events are merged | Showing everything: traces are usually sampled |
OpenTelemetry’s definitions are close to this table. A log is a timestamped text record, structured or not. A metric is a measurement of a service captured at runtime. A trace is the path of a request through an application.
Mental model. A metric tells you that something is wrong and how badly. A trace tells you where in the request path it is wrong. A log tells you what happened at that place. You usually go in that order, and each one is cheap or expensive for a different reason.
Challenge
Log, metric or trace?
Each question is best answered by one kind of telemetry. A log records one event, a metric aggregates measurements over time, and a trace follows one request through the services. Put each question under the signal that answers it most directly.
Sorting needs JavaScript.
Categories
- Log
- A timestamped record of one event.
- Metric
- A measurement combined with others over a time window.
- Trace
- The path of one request through the services.
Check your answers at least once before looking at the answers.
Logs: the detail, at a price
Section titled “Logs: the detail, at a price”A structured log is a log with a defined, consistent schema, which means stable field names, types and meaning. That is not the same as being valid JSON. A structured line from the shop can be filtered by field instead of searched as text:
{"time":"2026-10-08T03:12:44Z","level":"error","service":"shop","trace_id":"4bf92f3577b34da6a3ce929d0e0e4736","message":"payment call timed out","timeout_ms":800}The trace_id field is what ties a log to a trace. OpenTelemetry’s log records have top-level TraceId and SpanId fields, and it can attach the IDs of the active trace and span to a log automatically. From a slow trace you can then open exactly the lines that belong to it.
The cost of logs follows traffic. At 300 requests a second the shop handles 300 × 86,400, which is 25,920,000 requests a day. If each request writes one line of 200 bytes (an assumption chosen for the arithmetic, not a measurement), that is 25,920,000 × 200 bytes, about 5.2 GB a day. Triple the traffic to 900 requests a second, as in one of the incidents later in this module, and it is 77,760,000 lines and about 15.6 GB a day. Nothing is wrong with that, but it is why teams sample, shorten or expire logs, and why counting errors by scanning lines is slow.
Metrics: cheap to keep, impossible to take apart
Section titled “Metrics: cheap to keep, impossible to take apart”OpenTelemetry names three kinds of instrument. A counter only goes up, like an odometer. A gauge is a value at the moment it is read, like a fuel gauge. A histogram is an aggregation of values on the client, such as request latencies, which lets you read percentiles later.
What a metric stores does not depend on how many requests it counted. A counter of requests, labelled by service and by status class, is one number per combination. With 5 services and 3 status classes that is 5 × 3, which is 15 series, whether it counts 300 requests a second or 900.
The danger is in the labels. OpenTelemetry defines cardinality as the number of unique attribute combinations reported for a metric, and its metrics SDK documentation describes a default limit of 2,000 combinations, with more folded into an overflow point. Prometheus’s guidance on naming is blunt: every unique combination of label values is a new time series, and you should not use labels for dimensions with high cardinality, such as user IDs or email addresses. One label with a million users does not add a million to a number, it multiplies the series by a million. Put the user ID in a log line or a span attribute, where one more value costs one more record.
Traces: one request, end to end
Section titled “Traces: one request, end to end”A trace follows one request from its entry to its last call. It is made of spans, one for each unit of work, and a later lesson reads one closely. What matters here is the cost. A trace is stored per request, so keeping all of them costs as much as logs, and Google’s Dapper paper names low overhead as a design goal and sampling as one of the techniques it used to reach it. A sampled trace system keeps a share of the requests, which means that the request you wish you had is sometimes not there.
What happens if you only have one kind?
Section titled “What happens if you only have one kind?”Take the shop, with a customer who got an error at 03:12.
- Only logs. You can find the line. But to know whether errors are rare or common, you count lines among 25,920,000 a day, and to know which service was slow, you join lines from several services by hand.
- Only metrics. The checkout error rate went up at 03:10 and you can see it clearly. You cannot see which request failed, or why: the individual events were merged into counts.
- Only traces. You can see exactly where one request lost its time. If it was not kept by the sampler, you cannot see it, and a rate such as “one request in a hundred” is not something a handful of traces can tell you.
Each kind is the cheapest way to answer one question, and a poor way to answer the others. That is why the next two lessons read metrics and traces side by side on the same incident.
- Observability is understanding a system from the outside by asking questions about its telemetry: logs, metrics and traces.
- A log records one event, a metric aggregates measurements over time, and a trace follows one request across services.
- The cost of logs follows traffic: 300 requests a second is 25,920,000 requests a day, and one 200-byte line each is about 5.2 GB a day.
- The cost of a metric follows its label combinations, so 5 services × 3 status classes is 15 series at any traffic, and a user ID label multiplies the series by the number of users.
- Put a trace ID in every log line, and keep unbounded values out of metric labels.
- Each kind answers one question cheaply and the others badly, so incidents are read with all three.
Next: metrics and the four golden signals, read on a live incident.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.