Observability explained: logs, metrics and traces (and how they differ from monitoring)

When production breaks, you need to know what failed, where, when, why and for whom. Observability is how a system answers those questions. Learn the three pillars, logs, metrics and distributed tracing, plus correlation IDs, percentiles, the golden signals, health checks and alerts people don't ignore.

A car dashboard seen from the driver's seat. There are three gauges: speed, fuel and engine temperature, and a small amber engine warning light is on. Through the windscreen, the road is clear. A banner at the top says 'You can't fix what you can't see.'
Fig. 1 — A driver doesn't open the bonnet every few minutes. The dashboard tells them how the car is doing, and warns them before it breaks down. Observability is your system's dashboard.

A user writes in: “Checkout is slow.”

  • “How slow?” “Very slow.”
  • “Which step?” “I don’t know. Just slow.”

Without the right tools, that’s where you get stuck. To fix a problem in production, you need to answer five questions:

  1. What is failing? Which API, which feature?
  2. Where? Which service, which server?
  3. When did it start? Five minutes ago, right after a deploy?
  4. Why? A slow database, a network issue, a bad release?
  5. Who is affected? Everyone, or one region, one app version, one kind of user?

Observability is how well your system can answer those questions from the outside, using the data it gives off.

“You can’t fix what you can’t see. In production, visibility is survival.”

This article opens the Observability, security & operations thread.

Monitoring vs observability

The two words are often mixed up, but they ask different questions.

  • Monitoring asks: “Is it working?” It watches things you already know can go wrong: is the service up, is the error rate above 5%, is the disk full?
  • Observability asks: “Why is it behaving like this?” It lets you dig into problems you didn’t predict.

Monitoring tells you: “The error rate is 5%.” Observability lets you find out: “The errors are only for users in Asia, only for uploads over 100 KB, and only since version 2.3.1. The new validation code times out on large files.”

You need both. Monitoring tells you something is wrong; observability helps you find what.

The three pillars: logs, metrics and traces

Observability rests on three kinds of data. Each answers a different question:

Three pillars holding up a roof labelled 'observability'. The first pillar, logs, answers 'what happened?' and shows a line of JSON with an order ID and an error. The second, metrics, answers 'how much, how often?' and shows a small line chart of error rate over time. The third, traces, answers 'where did the time go?' and shows a request's path as stacked bars across services.
Logs tell you what happened. Metrics tell you how much. Traces tell you where the time went.
Pillar Answers Example
Logs What exactly happened? “Payment for order 42 failed: card declined, 14:23:45”
Metrics How much? How often? Is it getting worse? “Error rate is 2.5%, up from 0.1% an hour ago”
Traces Where did the time go in this one request? “Checkout took 2.5 s; 1.9 s of that was the payment provider”

A typical investigation uses all three: a metric alerts you that errors are up, a trace shows which service is slow, and the logs of that service tell you why.

Logs: what happened

A log is a timestamped note your code writes when something happens. Three habits make logs useful instead of noisy.

1. Write structured logs, not sentences. A sentence like "User 7 placed order 42 for ₹1,200" is easy to read but hard to search. Write fields instead, usually as JSON, so you can search amount > 1000 AND paymentMethod = "upi".

// Java · SLF4J 2 structured logging
log.atInfo()
   .setMessage("Order placed")
   .addKeyValue("orderId", order.id())
   .addKeyValue("userId", user.id())
   .addKeyValue("amount", order.total())
   .addKeyValue("paymentMethod", order.paymentMethod())
   .log();

2. Add a correlation ID to every log line. One click can pass through five services, each with its own logs. Give each request a unique ID at the front door, pass it along in a header (such as X-Correlation-ID), and add it to every log line. Then one search shows the whole journey:

[corr=abc-123] [api-gateway]   request received
[corr=abc-123] [auth]          user authenticated
[corr=abc-123] [order]         order created
[corr=abc-123] [payment]       payment failed: gateway timeout

In Java, the usual way is to put the ID in the logging MDC (a per-request context) in a filter, so every log line picks it up automatically.

3. Send all logs to one place. Logs spread across 50 servers are useless at 3 a.m. Ship them to a central store, such as the ELK stack (Elasticsearch, Logstash, Kibana), Grafana Loki or a cloud logging service, where you can search across every service at once.

Use log levels sensibly: ERROR for something that failed and needs attention, WARN for something odd that the system handled, INFO for key business events (order placed, payment made), DEBUG for detail you switch on only while investigating. And never log passwords, card numbers or tokens.

Metrics: how much and how often

A metric is a number measured over time: requests per second, error rate, memory used. Metrics are cheap to store and fast to chart, so they power your dashboards and alerts.

There are three basic kinds:

  • Counter: only goes up. Total requests, total errors.
  • Gauge: goes up and down. Memory in use, open connections, queue length.
  • Histogram: records how values are spread out. Request durations, so you can work out percentiles.

What should you measure? Start with Google’s four golden signals for every service:

Signal Question Example
Latency How long do requests take? p99 of checkout = 800 ms
Traffic How much demand is there? 1,500 requests a second
Errors How many fail? 0.3% return 5xx
Saturation How full is it? DB connection pool 90% used

In Spring Boot, Micrometer (included with Actuator) records many of these for you, and tools like Prometheus and Grafana store and chart them.

Why averages lie

Say 99 requests take 100 ms and 1 takes 10 seconds. The average is about 200 ms, which looks fine. But one user in a hundred is waiting 10 seconds, and on a busy site that’s thousands of people.

A bar chart of 100 request times. Ninety-nine short bars sit at about 100 ms. One very tall bar at the far right reaches 10 seconds. A dashed line across the chart marks the average at about 200 ms, labelled 'looks fine'. Labels on the right mark p50 at 100 ms and the slowest 1% at 10 seconds, labelled 'what some users really feel'.
The average hides the slow requests. Percentiles show them.

So track percentiles:

  • p50 (median): half of requests are faster than this.
  • p95: 95% are faster; 1 in 20 is slower.
  • p99: 99% are faster; 1 in 100 is slower.

Alert on p95 or p99, not the average. The slowest requests often come from your busiest, most valuable users, like the ones with big carts.

Traces: where did the time go?

A log tells you what happened inside one service. But a slow checkout might touch a gateway, auth, orders, payments and email. Which one is slow?

Distributed tracing follows one request across every service. At the start, the request gets a trace ID. Each service records a span, a timed piece of work, tagged with that trace ID, and passes the ID to the next service. A tracing tool then draws all the spans as one timeline:

A trace drawn as a waterfall of horizontal bars on a time axis from 0 to 2.5 seconds. The top bar, API gateway, spans the full 2.5 seconds. Below it, auth takes 100 ms at the start. Order service takes about 2.3 seconds, and inside it: validation 45 ms, payment service 2.1 seconds, and email 150 ms. Inside the payment service, the call to the external payment provider takes 1.9 seconds and is highlighted in red with the label 'slowest: found it'.
A trace shows one request as a waterfall. The long red bar is where the time went.

Here the answer jumps out: 1.9 of the 2.5 seconds were spent waiting on the outside payment provider. No guessing needed.

Today the standard way to do this is OpenTelemetry, an open standard supported by most tools (Jaeger, Zipkin, Grafana Tempo, and the big cloud providers). In Spring Boot 3, Micrometer Tracing adds trace IDs to your requests and logs with very little code.

Tracing every request is expensive, so most systems sample, keeping, say, 1% of traces. The catch: a rare bug might never be sampled. A common fix is to always keep traces that are slow or end in an error, and sample only the normal, healthy ones.

Health checks: am I OK to serve traffic?

Load balancers and Kubernetes need to know which instances are healthy, so each service exposes small health endpoints. There are three kinds, and mixing them up causes outages:

Check Question If it fails
Liveness Is the process alive and not stuck? Restart it
Readiness Can it handle requests right now (database reachable, cache warm)? Stop sending it traffic, but don’t restart it
Startup Has it finished starting up? Wait a bit longer before checking the others

Keep liveness simple: “is the process responding?”. If liveness checks the database and the database blips, Kubernetes restarts every instance at once, which turns a small hiccup into a full outage. Database checks belong in readiness. Spring Boot Actuator gives you /actuator/health/liveness and /actuator/health/readiness out of the box.

Alerts people don’t ignore

Dashboards only help if someone is looking. Alerts make the system tap you on the shoulder. But too many alerts are as bad as none: if the pager goes off ten times a night for things that don’t matter, people start ignoring it, including the one that does. This is alert fatigue.

Good alerts follow a few rules:

  • Alert on symptoms users feel, not causes. “Checkout success rate below 95% for 5 minutes” matters. “CPU above 70%” might be a normal busy hour.
  • Every alert must need action. If nobody needs to do anything, it’s a dashboard, not an alert.
  • Say what, how bad, and what to do. Include the current value, the impact, and a link to the runbook.
  • Use levels. Only page someone at 3 a.m. for things that hurt users now. Everything else can wait for working hours.

What breaks, and how to fix it

What breaks What you see The fix
Logging system is down Services slow down or fail because writing a log blocks Send logs asynchronously with a bounded buffer. Dropping logs beats dropping requests
Metric explosion You add userId as a metric label; a million users means a million time series, and Prometheus falls over Keep labels to small, fixed sets: endpoint, method, status code. Put user IDs in logs and traces
The rare bug is never traced 1% sampling misses a bug that hits 1 in 10,000 requests Always keep error and slow traces; sample the rest
Lost correlation ID A request’s logs stop at one service and the trail goes cold Pass the ID on every call, including through message queues
Alert fatigue Real alerts are ignored among the noise Alert on user-facing symptoms, delete alerts nobody acts on

Puzzle 1: the dashboard says everything is fine

Averages and totals hide small groups. That 0.1% might be every customer paying with one particular bank, or every request with more than 20 items, and for them, checkout fails every single time.

How to find it:

  • Look at p99 latency and the slowest requests, not the average.
  • Break the errors down by endpoint, region, app version and payment method. A tiny overall rate can be 100% for one slice.
  • Pull a trace for one of the failing customers, and follow its correlation ID through the logs.

Puzzle 2: a hundred alerts at once

Most of those 100 alerts are side effects of the same problem. Design alerts in layers:

  1. User-facing symptoms (page someone): “checkout success rate below 95%”.
  2. Service health (context, not a page): “payment service errors above 5%”.
  3. Resources (context, not a page): “database connection pool exhausted”.

Only the top layer wakes people up. The lower layers are there to explain it. Group related alerts together, and silence the ones that are just knock-on effects. And because this started with a deploy, show recent deploys on the dashboard: “what changed?” is the first question in almost every incident.

Key takeaways

  1. Monitoring asks “is it working?”; observability asks “why is it behaving like this?”. You need both.
  2. Logs say what happened. Make them structured, centralised, and tagged with a correlation ID.
  3. Metrics say how much. Track the golden signals (latency, traffic, errors, saturation), and use percentiles, not averages.
  4. Traces show where the time went across services. Use OpenTelemetry, and always keep error and slow traces.
  5. Health checks: keep liveness simple; put dependency checks in readiness.
  6. Alert on user-facing symptoms, and only when someone needs to act.

This opens the Observability, security & operations thread. Next, we’ll look at deployment and operations: blue-green deploys, canary releases and rollbacks, and how to ship changes without breaking production.

Comments

LEAVE A COMMENT
No sign-up. Comments appear after a quick review.