Debugging a Real Incident - Metrics, Logs and Traces Together in Practice
1. Recap: Time to Actually Use the Stack
Throughout this series, the stack grew piece by piece: metrics (articles 2 and 3), logs (article 4), traces (article 5), all unified in Docker Compose (article 6) and visualized in dashboards (article 7). This last article flips the script: instead of adding one more piece, we’ll break the PHP mini app on purpose and use the whole stack — dashboard, logs and traces — to investigate the problem from scratch, as in a real incident.
2. Simulating the Problem
In the app.php built in article 3, a small, deliberate change introduces a performance bug: a fraction of orders starts taking much longer than usual, and a smaller fraction starts actually failing.
// inside order processing, right after $state['queue_size']++
if (random_int(1, 100) <= 15) {
// simulate a slow external dependency (e.g. a payment service)
usleep(random_int(2_000_000, 4_000_000)); // 2-4 seconds, well above normal
}
if (random_int(1, 100) <= 5) {
http_response_code(500);
logToLoki("failed to process order: payment service timeout", "error");
$state['queue_size']--;
writeState($stateFile, $state);
echo "internal error\n";
exit;
}
This change stays live, and the investigation that follows takes exactly the path someone without access to this source code would: only looking at what the observability stack shows.
3. Step 1: the Dashboard Points to the Symptom
Generating continuous traffic against the PHP mini app and watching the dashboard built in article 7 (with the $app variable set to php-app), two panels change visibly:
- The p50/p95/p99 latency panel shows p50 relatively stable, but p95 and p99 shooting well above it — the classic pattern of “a minority of requests much slower than the majority”, consistent with the 15% chance of slowness introduced in the previous step.
- The errors per minute panel (based on
count_over_timeover logs withlevel="error") goes from zero to a constant error rate.
At this point, the dashboard has already answered the first question — “something is wrong, and it’s specifically in the PHP mini app” — but not the “why”. This is the natural boundary between what metrics can answer on their own and where you need to go one level deeper.
4. Step 2: the Logs Explain the Error
Going back to the dashboard’s logs panel (or to Explore, filtering directly):
{app="php-app", level="error"}
The message failed to process order: payment service timeout shows up repeatedly, tied to the times when the error panel went up. That’s already a concrete clue — it’s not a generic PHP error, it’s a specific business error, with a cause named in the log text itself (the “payment service”). But the log alone doesn’t say how much time was spent before the error happened, nor whether the slow requests (seen in the latency panel) are the same phenomenon as the requests that fail, or two different problems happening at the same time.
5. Step 3: the Traces Confirm Where the Time Was Spent
With the instrumentation from articles 5 and 6, every request generates a process_order span. Checking the OpenTelemetry collector logs (or, in a stack with a dedicated tracing backend, visually browsing the span tree) during the same time window as the spike seen on the dashboard:
docker compose logs otel-collector --since 5m | grep -A 5 process_order
The spans captured during the incident show durations (end_time - start_time) concentrated in two clearly separate groups: most in the range of tens of milliseconds (normal behavior) and a secondary group in the 2 to 4 second range — exactly the range artificially introduced in the simulation. The order.duration_ms attribute (added to the span in article 5) numerically confirms this bimodal distribution in each individual span, span by span, something that neither the aggregated latency panel (which shows percentiles, not individual cases) nor the error log (which only shows up for the 5% that actually fail, not the 15% that are merely slow) could show on their own.
6. Putting the Three Ends Together
The full investigation, reassembled:
- Metrics pointed out that something changed and when — p95/p99 climbing, error rate leaving zero — without anyone needing to know beforehand that the problem existed (exactly article 1’s definition of observability: answering an unanticipated question).
- Logs explained what was failing, with a specific business message (“payment service timeout”), quickly narrowed down by the
appandlevellabels thanks to Loki’s indexing model (article 4). - Traces confirmed where, inside the request, the time was actually being spent, at the granularity of individual requests — not just in aggregate — and connected the slow requests (visible only in the histogram’s tail) to the requests that generated error logs.
None of the three pillars alone reconstructs this full story: metrics without logs show that something changed, but not why; logs without metrics would mean digging through a huge volume of text without knowing where to look first; traces without the other two wouldn’t have been looked at in time, since nobody would be inspecting individual spans without first seeing the dashboard light up.
7. Series Conclusion
Over these eight articles, this series built a complete observability stack from scratch: what metrics, logs and traces are and why none of them replaces the other two; Prometheus collecting metrics by scraping two real mini applications, in plain Python and PHP; Loki receiving logs via its HTTP API, with an indexing model deliberately cheaper than traditional tools; OpenTelemetry as the neutral standard for generating traces, first in isolation, then unified through an OTLP collector; Grafana dashboards combining PromQL and LogQL; and, in this last article, the three pillars working together to investigate a simulated incident from symptom to root cause. The stack built here is deliberately minimal — no high availability, no long-term retention configured, no visual tracing backend — but the concepts and the investigation flow are exactly the same as those used in production observability stacks, at any scale.
References: