Metrics tell you something is wrong, traces tell you where, logs tell you why

A 5xx alert during a sale, investigated in order: metrics, then traces, then logs.
Imagine a sale has just started on a shopping app. Two minutes in, the on-call phone buzzes: "5xx rate above 5% for 5 minutes on checkout." Customers are seeing 503 "try again" pages.
The worst move at this point is to open the logs and scroll. Here is the order I would follow instead.
The problem
Without monitoring set up beforehand, a sale-day incident looks like this: users complain on social media first, someone scrolls through thousands of log lines, and nobody can tell whether the cause is traffic, a bad deploy, a slow database or a permission change.
Each of those has a different fix. Scaling up does nothing for a bug, and rolling back does nothing for a full database. So the first job is not to fix, it is to find out which kind of problem this is.
The solution: metrics, then traces, then logs

Metrics, traces and logs each answer a different question, so go through them in that order.
The three pillars answer different questions:
- Metrics: how much, how often? p95 latency, 5xx rate. Cheap numbers, used for alerts.
- Traces: where was the time spent in one request?
- Logs: what exactly happened?
During an incident I go in that order.
Step 1: the alert. An alert policy is a condition, a duration and a notification channel. Here it is "5xx rate above 5% for 5 minutes, notify Slack and on-call". The duration matters: it stops one bad second from waking anyone up.

An alert policy is a condition, a duration and a notification channel; the duration filters out one bad second (example data).
Step 2: the four golden signals. In Metrics Explorer I check latency, traffic, errors and saturation side by side. Say traffic has tripled, p95 latency is rising, and the instance count is flat at its maximum. That pattern points to capacity, not code. When a service is at max replicas, requests queue briefly, latency rises, and then the load balancer returns 503. I watch p95 rather than the average, because the average hides the slow tail.
If instead traffic is normal and errors started right after a deploy, that points to the deploy. Error Reporting would show a new error group, and the fix is to roll back.

The four golden signals look different for a capacity problem and a bad deploy, and each has a different fix.
Step 3: a trace. In Trace explorer I filter for slow checkout requests and open one. If the longest span is the order database call, the database is the bottleneck, not the app.
Step 4: the logs. Now I read logs with a narrow query, not a scroll:
resource.type="cloud_run_revision" severity>=ERROR The app prints structured JSON, so I can filter by fields such as orderId instead of searching text. The load balancer writes a log entry per request (status, latency, client location) once request logging is enabled on the backend, which shows exactly which paths returned 503. Cloud SQL slow-query logs, if the flag is on, would confirm a slow query on the orders table. And if the errors were 403s rather than 503s, I would check audit logs, which record who changed an IAM role and when.

A trace shows the order database call is the longest span; a narrow log query and the right log source explain why.
Step 5: act on what the signals said. Capacity problem: raise max instances or pods, and check database connections. Bad deploy: shift traffic back to the previous Cloud Run revision, which changes routing only, with no rebuild.
Trade-offs and limits
- Prevent the obvious one. For a known sale, 503s from capacity are predictable. Pre-scaling and a load test at expected peak beat a perfect alert.
- Logs cost money. I would control volume with a
LOG_LEVELsetting (INFO or WARNING in production), exclusion filters for noisy entries, and a sink to Cloud Storage or BigQuery for long retention. - Trace a sample, not everything. Sampling a fraction of requests, for example 5%, keeps cost down and is usually enough to find the slow span.
- Rollback does not undo a migration. Switching revisions changes traffic only. Database migrations must stay backward compatible, or rollback won't help.
- Alerts need a runbook. An alert that fires without a link to the dashboard and the steps is just noise at 2 AM.
Takeaway
Alert on symptoms users feel: error rate and p95 latency.
Investigate in order: metrics, then traces, then logs.
Decide whether it is capacity or code before you touch anything.


