6 min read

Observability - What It Is, Metrics vs Logs vs Traces and the Prometheus + Loki + Grafana Stack

1. Why “Monitoring” Is No Longer Enough

For a long time, “monitoring” a system basically meant one thing: setting up a few alerts (high CPU, full disk, process down) and hoping they cover the problems that will actually happen. That works as long as the system is simple and the ways it can fail are few and known in advance.

The problem shows up when the system grows: dozens of services talking to each other, running across multiple containers or machines, with failures that emerge from unpredictable combinations of factors. In that scenario, the question stops being “did this specific alert fire?” and becomes “why did this specific request get slow, right now, in this service, for this user?” — a question nobody thought to anticipate with an alert set up in advance.

Observability is the property of a system that lets you answer this kind of new, unforeseen question just by looking at the data it exposes externally — without having to add new instrumentation or deploy new code every time a different question comes up. It rests on three kinds of data, informally called “the three pillars”: metrics, logs and traces. This is the first part of a series on observability that will build, article by article, a complete, working stack with practical examples in Docker Compose.

2. Metrics: Numbers Aggregated Over Time

A metric is a numeric value associated with a timestamp, collected repeatedly over time — a time series. Examples: requests per second, memory usage, average response time, number of errors in the last 5 minutes.

Important characteristics:

  • Cheap to store in volume and over the long term — one number per time interval takes up much less space than a full text log, which lets you keep months or years of history without prohibitive cost.
  • Great for alerts and dashboards — questions like “did the error rate go above 5%?” or “is p99 latency climbing?” are naturally answered by metrics.
  • Aggregated, not individual — an “average response time” metric says nothing about which specific request was slow, only that, on average, something changed. To investigate the “which” and the “why”, you need the other two pillars.

3. Logs: Discrete Events with Rich Context

A log is a timestamped textual record of a specific event: a request received, an error caught, a database connection opened. Unlike a metric, a log carries arbitrary context — a full error message, a stack trace, a request payload.

That richness has a cost: logs are much more expensive to store and index than metrics, especially if every log line is fully indexed (full-text search). That’s why modern log tools like Loki (article 4 of this series) make a deliberate choice to index only a small set of labels and treat the line content as unindexed text — a different balance from traditional Elasticsearch, which indexes everything.

4. Traces: the Path of a Request Across Services

A trace captures the full path of an individual request as it crosses multiple services — how much time was spent at each step, in what order, and exactly where a failure or slowdown happened. A trace is made up of spans: each span represents a unit of work (an HTTP call, a database query, an RPC call), with a start, an end and metadata.

While metrics answer “did something change?” and logs answer “what happened in this specific event?”, traces answer “where exactly, across ten services, is the time being spent for this particular request?” — a question that becomes essential (and nearly impossible to answer without traces) as soon as a system stops being a monolith. Article 5 of this series covers OpenTelemetry, the current standard for generating traces.

User request
  │
  ├─ Span: API Gateway (2ms)
  │    │
  │    └─ Span: Orders Service (45ms)
  │         │
  │         ├─ Span: Database query (38ms)  ← bottleneck here
  │         └─ Span: Call to Inventory Service (5ms)

5. This Series’ Stack: Prometheus + Loki + Grafana

This series will build a minimal but working observability stack, using three open source tools that have become a de facto standard:

  • Prometheus — collects and stores metrics, using a “scraping” model (it actively fetches metrics from each application, instead of waiting for the application to send them). It comes with PromQL, a query language specific to time series.
  • Loki — log aggregation, created by the same company behind Grafana, with a deliberate “index like Prometheus” philosophy: few indexed labels, line content searched by scanning at query time. This makes it significantly cheaper to operate than traditional Elasticsearch-based stacks.
  • Grafana — the visualization layer, able to query both Prometheus (PromQL) and Loki (LogQL) — and, later in this series, tracing data too — in unified dashboards.

None of the three appears in isolation by accident: metrics tell you “what”, logs tell you “why” and traces tell you “where” — and the stack only fulfills its observability role when all three complement each other.

6. Bringing Up the Basic Version with Docker Compose

To try the stack without installing anything locally besides Docker, a minimal docker-compose.yml already brings up all three tools:

# docker-compose.yml
services:
  prometheus:
    image: prom/prometheus:v2.55.0
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro

  loki:
    image: grafana/loki:3.2.0
    ports:
      - "3100:3100"

  grafana:
    image: grafana/grafana:11.3.0
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
    depends_on:
      - prometheus
      - loki

Prometheus needs a minimal configuration file so it doesn’t fail on startup — for now, just to monitor itself:

# prometheus.yml
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

Bringing everything up:

docker compose up -d
  • Prometheus is available at http://localhost:9090 — it’s worth opening it and running a query like up in the expression field, which should return 1 for Prometheus itself.
  • Loki is available at http://localhost:3100 (with no visual interface of its own — it’s queried through Grafana or its HTTP API).
  • Grafana is available at http://localhost:3000 (login admin / admin, as set by the environment variable above).

In Grafana, under Connections → Data sources, add Prometheus (http://prometheus:9090, using the Compose service name as the hostname, since the containers are on the same network) and Loki (http://loki:3100) as data sources. From here, the stack is up — but still empty, with no real application sending data.

7. Conclusion and Next Steps

We saw the problem observability solves — answering unanticipated questions about a system in production —, the complementary roles of metrics, logs and traces, and brought up this series’ minimal stack: Prometheus, Loki and Grafana running via Docker Compose. In the next article, the stack gets its first real data source: a mini application in plain Python that exposes metrics at /metrics, with Prometheus configured to scrape them.


References:

  1. Prometheus — Overview
  2. Grafana Loki — Documentation
  3. Grafana — Documentation
  4. OpenTelemetry — Observability Primer