QA Interview Hub · Knowledge base · Quizzes · Українська

Logs and observability › Observability: logs, metrics, traces

Logs, metrics and traces: three signals

Logs, metrics and traces complement each other: a metric shows what is wrong, a trace shows where, and a log shows why. Logs are separate events with context, metrics are numeric series over time, and traces are the path of a request through services. Latency is taken as percentiles, and user or request ids are kept out of metric labels because cardinality explodes.

Logs · Observability

After a release everything "works", but complaints grew. Where do you see it if the test is green?

A functional test checked that a response came back with the needed fields. An hour after a release, support gets complaints about slow payment, while the post-deploy check is already green. A test answers "does one user’s scenario work", not "how does the system feel under real traffic". The second needs the system’s own signals. This lesson covers three such signals (logs, metrics, traces), what each can do and how they complement each other during an investigation.

How it works and why. Monitoring answers questions that were anticipated ("CPU above 90%?"). Observability is the ability to explain the state of a system from its external signals, including for questions nobody anticipated ("why is it slow only for Safari users and only for cards of one bank?"). For that, three signals keep different detail at different cost.

LogsMetricsTraces
What it isseparate events with contextnumeric series over timethe path of one request through services
Answerswhat exactly happened in this requestwhat and how much (error share, p95)where time was lost or the error arose
Costhigh: volume grows with trafficlow: size does not depend on trafficmedium, usually with sampling
Weak spothard to see the overall picturedoes not say "why" or for whomnot every request is kept

Metrics are cheap because the system stores not events but aggregates: a request counter and a latency histogram. They form the base of dashboards and alerts. But a metric does not know which request exactly is slow. So the typical order is: a metric says something is wrong, a trace shows where, a log explains why.

Three signals in one investigation

1. Metric: the 5xx share rosewhat and how much: the alert fired2. Trace: a slow span in paymentswhere exactly the time went3. Logs of that span by trace idwhy: gateway timeout 3000 ms
Figure 1. Each next step is narrower and more expensive than the previous one. The link between them is held by the trace id and shared service labels.

Example: from an alert to the cause. An hour after the release, a notification: the 5xx share in the checkout service is above 2%. The query behind such a chart (Prometheus):

# error share over 5 minutes (metric names are illustrative)
sum(rate(http_requests_total{service="checkout",status=~"5.."}[5m]))
  / sum(rate(http_requests_total{service="checkout"}[5m]))

# p95 latency from a histogram
histogram_quantile(0.95,
  sum by (le) (rate(http_request_duration_seconds_bucket[5m])))

The metric shows the problem exists since 14:05 and affects only POST /payments. Then take a few traces of this endpoint with errors: in all of them the longest span is the call to the payment gateway. Finally the logs of that span by trace id: "gateway timeout 3000 ms". Without the metric you would not know the problem began, without the trace you would search dozens of services, without the log you would not know the cause. For a tester this is ready material for a bug report and a hint of what to verify after the fix.

Which metrics to look at. For services there is the RED set: Rate (requests per second), Errors (the share of errors), Duration (latency, percentiles). For resources USE: Utilization, Saturation, Errors. The four golden signals from the Google SRE book are also mentioned often: latency, traffic, errors, saturation. Latency is taken as percentiles (p95, p99): an average hides the slow "tail" that users actually feel.

Limits and alternatives. Metrics have "cardinality": every unique combination of labels is a separate series. A userId or orderId label creates millions of series, and the monitoring system slows down or the bill jumps. So labels get bounded values (service, method, status class), while details are left to logs and traces. Traces are sampled, so a specific request may not be in the store (see the lesson on traces). These signals do not replace tests: they see consequences and do not verify requirements. A tester uses them as an extra oracle and as an investigation tool.

Typical mistakes.

  • Looking only at average latency: p99 can be ten times worse.
  • Putting a user or request id into a metric label: an explosion in the number of series.
  • Starting from logs when you first need to find where the problem is: thousands of entries without a landmark.
  • Treating "metrics are green" as proof that all is fine: they aggregate, and a problem of a small group of users can be invisible.

Check yourself

An alert says p95 latency doubled. Which signal do you open second and why not the logs?

Answer

Traces. The metric said what and how much, not where. A trace of a slow request shows which span takes the time (a DB call, an external gateway). Logs without that landmark are thousands of entries, while with a span’s trace id you can read exactly the needed ones.

Why is a userId label a bad idea in a metric but fine in a log?

Answer

A metric stores a separate series for every label combination, so millions of users give millions of series and overload the store. A log stores an event with fields, and one more field only grows the entry size, not the number of objects that must be indexed as series.

In an interview. Junior: Logs are events with context, metrics are numbers over time, traces are a request’s path through services. A metric shows what is wrong, a trace where, a log why. Middle/Senior: After a release I look at the RED metrics of services touched by the change and at percentiles, not the average. I investigate from a metric to a trace and logs by trace id. I remember label cardinality and trace sampling. For critical scenarios I ask for synthetic checks in production and an alert that I verified in a test environment.

More articles in this chapter