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

System Design › Reporting, metrics, observability

Observability and testing

Observability is the ability to understand the internal state of a system from its external signals: logs, metrics and traces. A metric says that something got worse, a trace shows where, a log explains why. They are tied together by a correlation id or trace id that the test generates, puts into the request and saves in the report. traceparent requires the W3C Trace Context format; services ignore an arbitrary string.

System design · Observability

A test got a 500 from the transfer. In which of five services to look for the cause?

In a microservice system a transfer request passes through the gateway, the transfers service, the accounts service, anti-fraud and a queue. The test sees only a "500" at the entrance. Without a shared identifier, the investigation is a needle search in five log streams by time: close, but not certain. With an identifier the test itself put into the request, the logs of all services are found with one search. The lesson covers what observability is, how to pass an identifier from a test and how else QA uses these signals.

How it works and why. Observability is the ability to understand the internal state of a system from its external signals: logs (what happened, event by event), metrics (numbers over time: error rate, latency) and traces (the path of one request across services). For QA they answer different questions: a metric says something is wrong, a trace shows where, a log explains why. What ties them together is a request identifier: a correlation id or trace id. Each service takes it from the incoming request, writes it into every log line and passes it on. Then the logs of scattered services are gathered into one story.

One id through the whole system

Testputs the id in a header and in the reportGatewayreads the id, logs it, passes it onTransfers and accounts servicesthe same id in every lineLog search by idone story of the whole request
Figure 1. The test is the start of the chain: it knows the id in advance and can put it in the report.

Example: send an id and store it in the report. The simplest option is a custom header:

test('transfer completes', async ({ request }, testInfo) => {
  const corrId = 'e2e-' + testInfo.testId + '-' + Date.now();
  const res = await request.post('/api/transfers', {
    headers: { 'X-Request-Id': corrId },
    data: { from: 'acc_1', to: 'acc_2', amount: 30 },
  });
  testInfo.annotations.push({ type: 'request-id', description: corrId });
  expect(res.status()).toBe(201);
});

The header name depends on the project: it may be X-Request-Id, X-Correlation-Id or the standard traceparent from W3C Trace Context. An arbitrary string won't do for traceparent: the value has the format 00-<trace-id, 32 hex>-<parent-id, 16 hex>-01, otherwise services ignore it and start a new trace. So for the standard header the id is generated in the right format:

import { randomBytes } from 'node:crypto';

const traceId = randomBytes(16).toString('hex'); // 32 hex chars
const spanId = randomBytes(8).toString('hex'); // 16 hex chars
const traceparent = '00-' + traceId + '-' + spanId + '-01';

const res = await request.post('/api/transfers', {
  headers: { traceparent },
  data: { from: 'acc_1', to: 'acc_2', amount: 30 },
});
testInfo.annotations.push({ type: 'trace-id', description: traceId });

Now the report has the trace id next to the failure, and it can be pasted into the tracing system or log search. Some tools (for example OpenTelemetry with default settings) pick up traceparent from the incoming request and continue the trace, so in the system the test shows up as the start of the chain. Whether a service supports this must be checked on the project: if not, fall back to your own header.

How else QA uses observability.

  • Checking side effects. Not only the API response but also that the event reached the queue and the audit log with the same id.
  • Release check. After a deploy, look at the error rate and latency in metrics: tests may be green while production is already degrading.
  • Synthetic monitoring. A small set of scenarios (login, viewing a balance on a test account) that regularly hit production and alert on failure.

Limits and alternatives. An identifier helps only if every service writes it. If one of them loses the id (an asynchronous worker without context propagation), the chain breaks, and that is also a finding for QA: check that the id reaches the message handler. Logs with personal data must not end up in test reports: the id is not a secret, but a card number or a token in a log is a security problem. Synthetic checks in production must run on a dedicated test account with safe actions, not create real transfers.

Common mistakes.

  • Generating an id but not storing it in the report: after a failure there is nowhere to get it from.
  • Passing an arbitrary string in traceparent: the vendor ignores an invalid value and starts a new trace.
  • Relying only on the API response and not looking at the queue and the audit log.
  • Putting actions with real money into synthetic checks.

Check yourself

A test sends traceparent: e2e-123. The service logs for this id are empty. Why and how to fix it?

Answer

traceparent has the format 00-<32 hex>-<16 hex>-01. An arbitrary string is invalid, so services ignore the header and create their own trace id. You need to generate proper values (32 and 16 hex characters), send them and store the trace id in the report. Or use a custom header such as X-Request-Id if the project supports it.

How do a metric, a trace and a log differ for investigating a test failure?

Answer

A metric shows that something got worse (error rate, latency) and when. A trace shows the path of one request across services and where it slowed or failed. A log explains what exactly happened at that place. Investigation usually goes from metric to trace to log, and the request identifier ties them together.

In the interview. Junior: Observability is logs, metrics and traces. A correlation id passes through all services and the request logs can be found by it. Middle/Senior: The test generates the id itself in the right format (for traceparent it is 32 and 16 hex characters) and stores it in the report, so within a minute I find the logs of all services for a specific failure. After a release I use metrics and synthetic checks as a continuation of testing, and check side effects (queue, audit log) by the same id.

More articles in this chapter