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.

Distributed tracing, trace ids and OpenTelemetry

A distributed trace links all operations of one request with a shared trace id that services pass along in a header, such as the W3C traceparent. A trace consists of spans forming a tree. OpenTelemetry is a vendor-neutral standard and set of SDKs for traces, metrics and logs. The trace id is written to logs. Because of sampling, a missing trace does not prove the request never happened.

Logs · Tracing

An e2e test failed on the "Pay" step. Which of ten services broke?

One click on "Pay" starts a chain: gateway, checkout, payments, an external payment provider, a database, a notification queue. The test sees only the final 500. Searching for the cause across each service’s logs means matching entries by time and hoping the clocks did not drift. A distributed trace solves this: all operations of one request are linked by a common identifier. This lesson covers how it is built, what traceparent is, what OpenTelemetry is and how to use it from tests.

How it works and why. A trace is the whole path of a request, a span is one operation (an HTTP call, a DB query) with a start, a duration, attributes and a status. Spans form a tree: each has its parent’s id. For services to know they belong to one trace, the context is passed in request headers. The W3C Trace Context standard defines the traceparent header:

traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
             version-trace id (32 hex)-parent span id (16 hex)-flags

The flag 01 means "sampled": the caller may have recorded the trace, and this decision is passed on. An all-zero trace id or span id is invalid. The extra tracestate header carries vendor data. Older systems use their own X-Request-Id, X-Correlation-Id or the B3 format; the key is that this identifier lands in every log entry (a traceId field), then you go from a trace to logs and back in one click.

A trace as a span chart

api-gateway 3.1 scheckout 2.9 spayments 2.6 sgateway call 2.2 s: timeout
Figure 1. The bar width is the span duration. It shows that all the time goes into the gateway call, which ends with an error, while the other services merely waited.

OpenTelemetry (OTel). This is an open, vendor-neutral standard and a set of SDKs for traces, metrics and logs. The parts: APIs and SDKs for languages (manual and automatic instrumentation of HTTP clients, databases, frameworks), the OTLP transfer protocol (gRPC or HTTP) and the Collector: an intermediate service that receives data, processes it (filters, masks fields, samples) and forwards it to a backend (Jaeger, Tempo, Datadog and others). The maturity of the signals differs across languages, so before using logs or metrics in a project check the language’s documentation.

Example: a test puts the trace id into the report. The test generates a traceparent itself and adds it to the API request. A server instrumented with OTel continues this trace. If the test fails, the trace id is in the report, and it opens the full path of the request:

A test puts the trace id into the report

import { randomBytes } from 'node:crypto';

test('an order is created', async ({ request }, testInfo) => {
  const traceId = randomBytes(16).toString('hex');
  const spanId = randomBytes(8).toString('hex');
1  const traceparent = '00-' + traceId + '-' + spanId + '-01';

  const res = await request.post('/api/orders', {
2    headers: { traceparent },
    data: { sku: 'A-1', qty: 1 },
  });
3  testInfo.annotations.push({ type: 'trace-id', description: traceId });
  expect(res.status()).toBe(201);
});
  1. Building the header. 00 is the version, then 32 hex characters of trace id, 16 hex characters of span id and 01, the sampled flag.
  2. Passing it on. The header goes with the API request, and a server instrumented with OTel continues this trace.
  3. The report. The trace id lands in the test annotation: it finds the whole path of the request in the trace and log stores.
Figure 2. The numbers mark three places in the code, not line numbers.

Why this beats searching by time: the id is unambiguous, so other people’s requests on a shared stand do not land in the results. The flag -01 asks to record the trace; services with a sampler that honours the parent’s decision keep it even if they normally sample only a small share. A trap: some gateways at the edge of the system drop or replace incoming tracing headers, and then the test’s trace id does not match the real one. Check that the response or the logs really contain this id.

Sampling. Recording every trace is expensive. Head sampling decides at the start of a request (for example keep 5%), which is cheap but may drop exactly the failing request. Tail sampling decides after completion and can keep all error and slow traces, but requires buffering in the Collector. So for a rare failure "no trace" does not mean "no request".

Limits and alternatives. Context disappears where a service did not pass it on: an asynchronous queue without header propagation, a custom HTTP client without instrumentation, a thread that lost the context. Then the trace breaks in two and the "bottleneck" is not visible. Without traces, correlation ids in logs remain: worse, but it works. Traces do not replace metrics: they show individual requests, not the overall picture.

Typical mistakes.

  • Not writing the trace id into logs: the trace exists, but there is nothing to jump to the logs by.
  • Hoping queues and background jobs pass context on their own: it is propagated explicitly.
  • Treating a missing trace as proof the request did not happen: maybe the sampler did not select it.
  • Using an all-zero or a made-up short trace id: the header is invalid and the server ignores it.

Check yourself

A test added a traceparent header, but the trace store has no request with this trace id. Name four possible causes.

Answer

A gateway at the entry dropped or replaced the header; the server is not instrumented or does not continue incoming context; a sampler dropped the trace (head sampling that ignores the flag); the header is invalid (wrong length or zeros). First check whether the id reaches at least the service’s logs.

Why is tail sampling better than head sampling for investigating failures, and what does it cost?

Answer

The decision is made after the request completes, so all error and slow traces can be kept and normal ones dropped. The cost: the Collector must buffer all spans until the trace finishes, which means memory and more complex infrastructure.

In an interview. Junior: A trace is a request’s path through services, made of spans. The identifier is passed in a header such as traceparent, and by it you find all entries of that request in the logs. Middle/Senior: I know the traceparent format and that the sampled flag passes the recording decision on. In tests I generate a trace id, add it to the report and check that it reaches the logs. I understand sampling (head versus tail) and that context is lost on queues and unsupported clients, so I verify that separately.

Dashboards, alerts and SLI/SLO for a QA

Alerts are set on user-facing symptoms such as error rate or latency, while SLI, SLO and error budget give a shared language for reliability. An SLI is a measurable indicator, an SLO is a target for it over a period, and an SLA is an external promise. The error budget is 100% minus the SLO: for 99.9% over 30 days that is about 43 minutes. A useful alert has a runbook.

Logs · SLO and alerts

An alert rings every night about CPU, and a real payment failure woke nobody. What is wrong?

A team set an alert "CPU above 80%". It fires every night during backup, and people learned to ignore it. When payment really stopped working for 5% of users while CPU was normal, there was no notification. This is the classic story of "alert fatigue" and of alerts on causes instead of symptoms. This lesson covers how to read a dashboard, which alert is useful, and how SLI/SLO give a shared language between testing, development and business.

How it works and why. A dashboard shows the state on one screen: error share, p95 latency, traffic, queues. A good dashboard answers "is everything fine?" in seconds and leads deeper (drill-down) to a chart of a specific service, then to traces and logs. An alert is an automatic notification when a condition holds for some time. The principles:

  • Alert on symptoms for the user (error share, latency), not on every internal detail. High CPU on its own does no harm if requests complete in time.
  • Every alert is actionable: someone knows what to do (a runbook). Noisy alerts get ignored.
  • A condition with a duration (for: 10m) so it does not fire on a one-second spike.
  • Percentiles (p95, p99), not the average: an average hides the slow "tail".

Two alerts for one problem

Wrong

CPU above 80%

A cause, not a consequence for the user. Fires every night, no runbook. A real payment failure does not touch it.

Right

5xx above 2% for over 10 min

A symptom: users see errors. It has a duration and a runbook link.

Figure 1. A useful alert describes the user’s pain, has a time threshold and says what to do.

SLI / SLO / SLA. SLI (indicator) is a measurable quality figure: the share of successful requests, the share of responses faster than 300 ms. SLO (objective) is a target for an SLI over a period: "99.9% of requests succeed over 30 days". SLA is an external contractual promise with consequences for breaking it, usually looser than the internal SLO. The error budget is the allowed share of failures: 100% minus the SLO. While the budget is not spent, the team can ship changes fast; once spent, reliability comes first. The budget in time for a 30-day period:

SLOBudget over 30 days
99%7.2 hours
99.9%43.2 minutes
99.99%4.32 minutes

Example: a symptom alert and checking it. A rule for Prometheus (metric names are illustrative):

groups:
  - name: checkout
    rules:
      - alert: CheckoutHighErrorRate
        expr: |
          sum(rate(http_requests_total{service="checkout",status=~"5.."}[5m]))
            / sum(rate(http_requests_total{service="checkout"}[5m])) > 0.02
        for: 10m          # do not fire on a short spike
        labels:
          severity: page
        annotations:
          summary: "The 5xx share in checkout has been above 2% for 10 minutes"
          runbook_url: https://wiki.example.com/runbooks/checkout-5xx

What remains is to check that the rule works. A tester in a test environment induces a failure artificially (fault injection: a gateway mock configured to return 500 for 5% of requests), waits over 10 minutes and checks that the alert goes into the firing state and the notification reaches the right channel with a runbook link. Then restores the service and checks that the alert resolves. Without such a check, a rule can for years point at a metric that no longer exists and stay silent.

Limits and alternatives. A fixed threshold (2%) does not account for how fast the budget is being spent. Mature teams alert on the speed of budget "burn" (burn rate) over several windows: fast burn wakes a person, slow burn creates a task. For low traffic the share is unstable: one failure out of ten requests is 10%. So they add a minimum request volume or look at longer windows. Synthetic checks (a script regularly walks a key scenario in production) catch failures when traffic is low, for example at night.

Where QA fits. Checks that key scenarios are covered by metrics and alerts; that an alert really fires on an injected failure; that the runbook is current. SLOs are used as a release criterion: a canary release with a rollback if a metric is worse than the threshold. And a dashboard is used to assess the effect of a release without waiting for complaints.

Typical mistakes.

  • An alert on a cause (CPU, memory) instead of a symptom: noise and missed real failures.
  • An alert without a runbook: the recipient does not know what to do.
  • An SLO of 100%: a zero budget, no changes. The target must be reachable.
  • Not testing alerts: a rule may have broken when a metric was renamed.

Check yourself

An SLO of 99.9% over 30 days. One outage lasted 50 minutes. Is the budget spent?

Answer

Yes. A 0.1% budget of 30 days is about 43.2 minutes, and the outage lasted longer. This assumes the SLI counts downtime; if the SLI is a share of requests, an outage on part of the traffic spends the budget more slowly. After exhaustion reliability comes first: fewer risky releases, root-cause analysis.

Why is an alert on p95 latency better than one on average latency?

Answer

The average is diluted by fast responses: five percent of very slow requests barely move it, though every twentieth user waits. p95 shows the threshold exceeded by 5% of requests, so this "tail" is visible and can be alerted on.

In an interview. Junior: A dashboard shows system state, an alert notifies about a problem. An SLI is an indicator, an SLO a target, an SLA a promise to the customer. Alerts are made on symptoms, for example the error share. Middle/Senior: I check that an alert is actionable, has a duration and a runbook, and that it fires on an injected failure in a test environment. I use the error budget as a language for release decisions and take burn rate and minimum traffic volume into account. For night and low traffic I ask for synthetic checks.