Ankit KanojiyaAdvanced

Evergreen guide by Ankit Kanojiya · Advanced · DevOps & Cloud

Observability: Logging, Metrics, and Tracing Done Right

A guide to the three pillars of observability and how to combine logs, metrics, and traces to understand production systems. Covers cardinality, sampling, and SLO-based alerting.

Observability is the ability to understand a system's internal state from the signals it emits. In distributed systems, failures are rarely reproducible on a laptop, so the data a system produces in production becomes the primary debugging tool. Three complementary signals, often called the three pillars, do most of the work.

Logs, Metrics, and Traces

Each signal answers a different question:

  • Logs are discrete, timestamped records of events. They answer what happened in detail, including context specific to one request.
  • Metrics are numeric measurements aggregated over time, such as request rate or error count. They answer how much and how often, and they are cheap to store and query.
  • Traces follow a single request as it crosses service boundaries. They answer where time was spent and which service failed.

The three are strongest together. A metric alerts that error rate rose, a trace localizes the failing service, and logs from that service explain the specific cause.

Structured Logging

Plain text logs are hard to query at scale. Structured logs emit machine-parseable records, usually one JSON object per line, so a log platform can filter and aggregate them.

{"level":"error","ts":"2026-11-14T10:00:00Z","service":"checkout","trace_id":"abc123","msg":"payment declined","order_id":"7788"}

Including a trace identifier in every log line is what links logs back to traces. Avoid logging secrets or personal data, and prefer levels consistently so that error truly means something actionable.

Metrics and Cardinality

Metrics are typically stored as time series identified by a name and a set of labels. The critical constraint is cardinality: the number of unique label combinations. Each distinct combination is a separate time series, and unbounded cardinality is the most common way to overwhelm a metrics backend.

# Good: bounded label values
http_requests_total{method="GET", status="200", route="/api/users"}

# Dangerous: user_id has unbounded values
http_requests_total{user_id="500123"}

Putting a user identifier, request identifier, or raw URL with query strings into a label can create millions of series. Keep labels to low-cardinality dimensions such as method, route template, and status class. High-cardinality context belongs in logs or traces, not metrics.

Distributed Tracing

A trace is a tree of spans, each representing a unit of work with a start time and duration. Context is propagated between services through headers, commonly the W3C traceparent header, so spans from different services join into one trace.

Instrumenting every request fully is expensive, so tracing relies on sampling:

  • Head-based sampling decides at the start of a request whether to record it. Simple and cheap, but it may miss rare errors.
  • Tail-based sampling buffers spans and decides after the request finishes, so it can keep all traces that errored or were slow. More accurate, but requires more infrastructure.

A common approach is to always sample errors and slow requests while sampling a small percentage of normal traffic, balancing cost against coverage.

Alerting on What Matters

Alerting on raw resource metrics such as high CPU produces noise, because high CPU is not inherently a problem. Better alerts are tied to user-facing symptoms expressed as Service Level Objectives.

An SLO sets a target, for example 99.9 percent of requests succeed over 30 days. The allowed failure is the error budget. Alerting on the rate at which the budget is burning catches real degradation while tolerating harmless blips.

# Alert when the fast burn rate would exhaust the budget quickly
- alert: HighErrorBurn
  expr: error_rate_5m > (14 * 0.001)
  for: 5m

This symptom-based approach reduces pager fatigue, because engineers are woken for problems that affect users rather than for transient internal spikes.

Trade-offs

Observability is not free. More signals mean more storage, more network overhead, and more cost. Logging every request at debug level in production is rarely justified; sampling and log levels exist to contain this. Similarly, a thousand dashboards nobody reads provide a false sense of safety. The useful measure is time to diagnose an incident, not the volume of data collected.

Open standards reduce lock-in. Instrumenting with a vendor-neutral format lets teams switch backends without re-instrumenting every service, which is valuable given how quickly the tooling landscape changes.

Summary

Logs, metrics, and traces answer different questions and are strongest in combination, linked by shared identifiers. Keep metric cardinality bounded, sample traces to control cost while preserving errors, use structured logs, and alert on user-facing symptoms through SLOs rather than raw resource usage.