envoy-guide
Module 4 · Observability·14 min·intermediate

Distributed tracing

Wire up Jaeger/Zipkin and see a span cross two Envoys.

What tracing answers that logs and metrics can't

A user clicks "checkout." Behind the scenes that triggers eight services calling each other. Total time: 2.4 seconds. Where did the time go?

  • Logs answer: "what happened at each service?"
  • Metrics answer: "is service X slow on average?"
  • Tracing answers: "for this specific request, which hop ate the time?"

A trace is a tree of spans, one per service hop. Each span knows its parent. Together they form the timeline of a single request across the fleet.

Each bar is a span. Indentation = parent/child. The fat one in the middle (inventory) is your culprit.

Envoy's role

Envoy participates in tracing by:

  1. Generating a trace ID for incoming requests that don't have one.
  2. Annotating a span for itself with timing, status, and metadata.
  3. Propagating trace headers (x-b3-*, traceparent, etc.) on the outbound side, so the next hop can pick up the trace.
  4. Reporting spans to a tracing backend — Jaeger, Zipkin, Datadog, OpenTelemetry Collector, etc.

The application must forward the incoming trace headers when it makes its own outbound calls. Without that, you get isolated single-hop spans instead of a connected trace.

Configure tracing

Two pieces: a tracing block in the HCM, and a cluster the tracer can reach. Here's a Zipkin example (Jaeger speaks Zipkin too):

YAML
          tracing:
            provider:
              name: envoy.tracers.zipkin
              typed_config:
                "@type": type.googleapis.com/envoy.config.trace.v3.ZipkinConfig
                collector_cluster: zipkin
                collector_endpoint: "/api/v2/spans"
                collector_endpoint_version: HTTP_JSON

  clusters:
  - name: zipkin
    type: STRICT_DNS
    connect_timeout: 1s
    load_assignment:
      cluster_name: zipkin
      endpoints:
      - lb_endpoints:
        - endpoint: { address: { socket_address: { address: jaeger, port_value: 9411 }}}

The collector_cluster is just a normal Envoy cluster — same shape as any upstream.

You usually also want to bump sample rate for dev:

YAML
          tracing:
            provider: { ... }            # as above
          # Sample 100% of requests in dev — drop way down in prod
          # (set under tracing.random_sampling)
OpenTelemetry is the modern path

For greenfield setups, point Envoy at an OpenTelemetry Collector instead of Jaeger directly — same idea, but the OTel Collector can fan out to Jaeger, Tempo, Datadog, etc. without you reconfiguring Envoy. Use the envoy.tracers.opentelemetry provider.

Hands-on: see a two-hop trace in Jaeger

Hands-on · Trace a request across two Envoys

Use docker-compose to bring up Jaeger and two Envoys chained together.

YAML
services:
  jaeger:
    image: jaegertracing/all-in-one:latest
    environment:
      COLLECTOR_ZIPKIN_HOST_PORT: ":9411"
    ports: [ "16686:16686", "9411:9411" ]   # UI, Zipkin

  envoy-edge:
    image: envoyproxy/envoy:v1.31-latest
    volumes: [ "./envoy-edge.yaml:/etc/envoy/envoy.yaml" ]
    ports: [ "10000:10000" ]

  envoy-inner:
    image: envoyproxy/envoy:v1.31-latest
    volumes: [ "./envoy-inner.yaml:/etc/envoy/envoy.yaml" ]

envoy-edge.yaml: hello-world that proxies to envoy-inner, with a tracing block pointing at jaeger:9411.

envoy-inner.yaml: hello-world that proxies to httpbin.org, with the same tracing block.

Bring it up, then:

Shell
curl -s localhost:10000/get

Open Jaeger UI at http://localhost:16686. Pick the envoy-edge service in the dropdown and search. You'll see a trace with two spans — one per Envoy — connected as a parent/child. Click in to see request duration, headers, and the upstream cluster each Envoy hit.

Tear down with docker compose down.

Apps must forward the headers

If you put a real application between the two Envoys instead of chaining them directly, the app must forward the incoming x-b3-* / traceparent headers on its outbound HTTP calls. Most HTTP client libraries don't do this by default — you need a middleware. Otherwise you'll get two disconnected traces instead of one connected one.

Real-world example · An e-commerce site debugging slow checkout
Problem
p99 checkout latency jumped from 400ms to 2.5s overnight. Logs across eight services each look "fine on average." Metrics show something is slow somewhere. Nobody can point at the culprit.
Envoy solution
The team opens Jaeger, filters traces by http.url=/checkout and {"duration > 2s"}, and clicks the worst one. The waterfall view shows 1.8 seconds spent in a single span: a previously-fast call to the inventory service. They drill into the inventory Envoy's stats, find a circuit-breaker overflow on its DB connection pool, and resize the pool. p99 drops back to 400ms before lunch.

Module 4 in one sentence

Logs, metrics, and traces — Envoy gives you all three for free, with the same config skeleton you've been writing all along. That alone is worth the price of admission.

Module 5 ties everything back together: Envoy as a sidecar, then xDS and Istio.

Quick check

For a trace to span two Envoys, the upstream service must…

Practical task
Finish the quick check and tick off the task to unlock.
Quick checkTasks 0/3