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:
- Generating a trace ID for incoming requests that don't have one.
- Annotating a span for itself with timing, status, and metadata.
- Propagating trace headers (
x-b3-*,traceparent, etc.) on the outbound side, so the next hop can pick up the trace. - 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):
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:
tracing:
provider: { ... } # as above
# Sample 100% of requests in dev — drop way down in prod
# (set under tracing.random_sampling)
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
Use docker-compose to bring up Jaeger and two Envoys chained together.
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:
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.
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.
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.
For a trace to span two Envoys, the upstream service must…