Software EngineeringObservability

Jaeger 2.20 and Prometheus: A Two Container Tracing Setup With RED Metrics

A working compose file for Jaeger v2 with on-disk storage, span-derived rate, error and duration metrics in the Monitor tab, and per-environment labelling. Complete configs, the defaults worth overriding, and how to verify each part.

A topology diagram: three sender blocks, two OTLP and one Zipkin, feed a Jaeger container listing receivers, batch, span_metrics, storage and query; arrows leave it to a Badger block holding traces on disk and to a Prometheus block of derived metrics, with a return line labelled Monitor tab reads back.
Lead image A topology diagram: three sender blocks, two OTLP and one Zipkin, feed a Jaeger container listing receivers, batch, span_metrics, storage and query; arrows leave it to a Badger block holding traces on disk and to a Prometheus block of derived metrics, with a return line labelled Monitor tab reads back.
On this page

Audio edition

0:00 / 6:31

Ready

This is a two container tracing backend: Jaeger v2 storing spans on local disk, and Prometheus holding rate, error and duration metrics derived from those same spans. Applications send traces and nothing else, no metrics pipeline of their own, and Jaeger’s Monitor tab renders per-operation latency percentiles, request rate and error rate.

Jaeger v2 is an OpenTelemetry Collector distribution, which is what makes the second container unnecessary. Its image compiles in spanmetricsconnector, batchprocessor, attributesprocessor, filterprocessor, tailsamplingprocessor and prometheusexporter, so the connector that aggregates spans into metrics runs in the Jaeger process. A separate otel-collector in front of it, which many guides include, adds a hop and duplicates a component already present.

senders --OTLP 4317/4318--> [ jaeger ] --> badger (traces)
        --Zipkin 9411----->      |
                                 +--span_metrics--> :8889 --scrape--> prometheus
                                                                          |
                             Monitor tab <--- jaeger_query <--------------+

The compose file

services:
  jaeger:
    image: jaegertracing/jaeger:2.20.0
    container_name: jaeger
    command: ["--config", "file:/etc/jaeger/config.yaml"]
    user: root
    environment:
      DEPLOY_ENV: ${DEPLOY_ENV:?set DEPLOY_ENV in .env}
      SPAN_TTL: ${SPAN_TTL:-336h}
    ports:
      - "16686:16686"   # UI
      - "4317:4317"     # OTLP gRPC
      - "4318:4318"     # OTLP HTTP
      - "9411:9411"     # Zipkin
    volumes:
      - ./config/jaeger.yaml:/etc/jaeger/config.yaml:ro
      - jaeger-data:/badger
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:13133/status"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 10s
    restart: unless-stopped

  prometheus:
    image: prom/prometheus:v2.55.1
    container_name: prometheus
    command:
      - --config.file=/etc/prometheus/prometheus.yml
      - --storage.tsdb.retention.time=${METRICS_RETENTION:-90d}
      - --storage.tsdb.retention.size=3GB
    ports:
      - "127.0.0.1:9090:9090"
    volumes:
      - ./config/prometheus.yml:/etc/prometheus/prometheus.yml:ro
      - prometheus-data:/prometheus
    restart: unless-stopped

volumes:
  jaeger-data:
  prometheus-data:

Three details in there are not obvious. The jaegertracing/jaeger image is the v2 line; jaegertracing/all-in-one is v1 and end of life, and only full X.Y.Z tags are published, so a short 2.20 tag will not resolve. user: root is needed because named volumes are created root-owned while the image’s default uid is 10001, which leaves Badger unable to write to /badger; an init container that chowns the volume to 10001 is the alternative. Prometheus binds to loopback because Jaeger reaches it over the compose network, and the published port exists only for inspecting raw series by hand.

The Jaeger config

Version 2 takes all of its settings from this file.

# v2 is configured entirely by this file. The v1 environment variables,
# SPAN_STORAGE_TYPE and COLLECTOR_*, are not read.
service:
  extensions: [jaeger_storage, jaeger_query, healthcheckv2]
  pipelines:
    traces:
      receivers: [otlp, zipkin]
      processors: [memory_limiter, attributes/env, batch]
      exporters: [jaeger_storage_exporter, span_metrics]
    metrics/spanmetrics:
      receivers: [span_metrics]
      exporters: [prometheus]
  telemetry:
    resource:
      attributes:
        - name: service.name
          value: jaeger
    metrics:
      level: normal
      readers:
        - pull:
            exporter:
              prometheus:
                host: 0.0.0.0
                port: 8888

extensions:
  healthcheckv2:
    use_v2: true
    http:
      endpoint: 0.0.0.0:13133

  jaeger_query:
    storage:
      traces: main
      metrics: spm

  jaeger_storage:
    backends:
      main:
        badger:
          directories:
            keys: /badger/key
            values: /badger/data
          ephemeral: false
          ttl:
            spans: ${env:SPAN_TTL:-336h}
    metric_backends:
      spm:
        prometheus:
          endpoint: http://prometheus:9090
          normalize_calls: true
          normalize_duration: true

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
  zipkin:
    endpoint: 0.0.0.0:9411

processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 75
    spike_limit_percentage: 15

  attributes/env:
    actions:
      - key: deployment.environment.name
        value: ${env:DEPLOY_ENV}
        action: insert

  batch:
    send_batch_size: 512
    timeout: 5s

connectors:
  span_metrics:
    histogram:
      explicit:
        buckets: [10ms, 25ms, 50ms, 100ms, 250ms, 500ms, 1s, 2s, 5s, 10s, 30s]
    dimensions:
      - name: method
      - name: status
      - name: deployment.environment.name
        default: ${env:DEPLOY_ENV}
    metrics_flush_interval: 30s

exporters:
  jaeger_storage_exporter:
    trace_storage: main
  prometheus:
    endpoint: 0.0.0.0:8889

Storage. ephemeral: false is required; Badger defaults to ephemeral and drops every span on restart while a volume sits mounted and empty. ttl.spans defaults to 72 hours when unset, which is short enough that history disappears before most people look for it, and the value appears in the storage source rather than in any startup log.

Endpoints. Every listener needs an explicit 0.0.0.0. Collector components default to localhost, which is unreachable from outside the container regardless of how the ports are published.

Names. The connector is span_metrics on 2.20; the older spanmetrics spelling still resolves and logs a deprecation at startup. Leaving the connector’s namespace at its default matters too, because Jaeger 2.x queries traces_span_metrics_* and finds nothing when the namespace is cleared, which was the Jaeger v1 recipe.

Dimensions that match the spans

A dimension names an attribute to split the metrics along, and it is silently dropped when spans do not carry that attribute, leaving metrics with correct names and no labels. The OpenTelemetry semantic conventions are the intuitive choice and the wrong one for Spring senders:

instrumentationkeys on server spans
Micrometer Tracing, Boot 3 and 4method, status, uri, outcome
Sleuth with Brave, Boot 2http.method, http.path
OpenTelemetry semantic conventionshttp.request.method, http.response.status_code

Micrometer emits its own observation keys and Brave emits Zipkin’s, so method and status are the two both stacks agree on. Confirming this for any given deployment takes one query against a live instance:

curl -s "http://localhost:16686/api/traces?service=<svc>&lookback=1h&limit=20" \
  | python3 -c "import sys,json;print(sorted({t['key'] for tr in json.load(sys.stdin)['data'] for s in tr['spans'] for t in s['tags']}))"

Prometheus

global:
  scrape_interval: 30s

scrape_configs:
  - job_name: jaeger-spanmetrics
    static_configs:
      - targets: ['jaeger:8889']

  - job_name: jaeger-self
    static_configs:
      - targets: ['jaeger:8888']

The scrape interval matches the connector’s metrics_flush_interval; scraping faster duplicates samples without adding resolution. The second job collects Jaeger’s own telemetry, which covers refused spans, queue depth and storage write failures.

Series count follows the number of operations rather than traffic, since the metrics are aggregates. Each unique service, operation, kind and status combination produces one counter and one histogram, and an 11 bucket histogram is 14 series once +Inf, _sum and _count are added. Sixty seven operations across three services puts the ceiling near 2,000 series, which is negligible for Prometheus. Adding a URL, a document id or a tenant as a dimension removes that bound, which is the case a memory limit on the container is there to catch.

Badger is the larger consumer by an order of magnitude, at roughly a kilobyte per span against a couple of bytes per metric sample, so 90 days of metrics costs less to keep than 14 days of traces. du -sh /badger inside the container, divided by the TTL in force, gives the real rate for a given deployment.

Per-environment values

DEPLOY_ENV=dev
SPAN_TTL=168h
METRICS_RETENTION=90d

Everything that differs between environments lives in .env, so the same configs deploy everywhere. attributes/env stamps deployment.environment.name onto every span at ingest, which covers senders that cannot set it themselves: Zipkin’s model has a service name and no resource concept, so Brave-based applications have no way to express one. The OTLP senders can, through management.opentelemetry.resource-attributes, present in both Boot 3.5.7 and 4.0.0, and insert yields to any sender that does.

The attribute is also a span_metrics dimension, so metrics split by environment alongside traces. Old spans are not rewritten, so a deployment has a mixed window one TTL long after the change. That variable carries no default and compose refuses to start without it, on the grounds that an unlabelled instance mislabels everything it stores.

Verifying each part

# Container health
docker compose ps                      # jaeger reports healthy, not just running

# Metrics backend reachable. 501 means no metrics backend is configured;
# /api/metrics/minstep is a v1 route and 404s even when this is healthy.
curl -s "http://localhost:16686/api/metrics/calls?service=<svc>\
&endTs=$(date +%s000)&lookback=3600000&step=60000&ratePer=600000"

# Environment label present on the derived series
curl -s http://127.0.0.1:9090/api/v1/query \
  --data-urlencode 'query=count by (deployment_environment_name) (traces_span_metrics_calls_total)'

# Scrape targets both up
open http://127.0.0.1:9090/targets

A synthetic load of three services and seven operations produced 23 series and a Monitor tab showing a 45% error rate on the operation returning 500s, ranked against the other operations by P95 times request rate.

Limits

Badger is one node on local disk, with no replication and no way to scale sideways, so outgrowing the box means moving to a different storage backend rather than a bigger volume. Jaeger’s UI has no authentication, and Spring Security’s observability attaches granted authorities to every request span, so port 16686 needs a reverse proxy in front of it before the host is exposed. collector_instance_id appears as a metric label, so each restart starts a fresh set of series.

Boot 3 with Spring Security observability also emits security filterchain before, security filterchain after, authorize request and authorize method on every request, which is a large share of stored volume. filterprocessor is in the image and can drop them, at the cost of orphaning their children in the trace view, since those spans sit mid tree rather than at the leaves.

Continue reading

Complete index →