AlgoViz

Jaeger

medium 28 min

Jaeger is an open-source store and viewer for distributed traces.

See it run

Spans from several services become one timeline. Sampling and buffering decide what it costs.

Operations

One trace

A user places an order. Two services make spans and Jaeger joins them.

Step 1 of 6

New id

Our systemUserWeb servicespan APay serviceCollectorTrace storage

The web service sees no traceparent, so it makes a trace id and span A.

Step 1: New id

trace = new_trace_id()with span("POST /order", trace) as a:    headers["traceparent"] = (trace, a.id)    call_pay(headers)export_later(a)# in paywith span("charge", parent=headers["traceparent"]) as c:    charge()export_later(c)
Work
Export is later
State
Spans

Say that spans are exported later, so tracing does not delay the answer.

In the real world

The same jaeger doing real jobs. Pick one and step through it.

One service does not pass the context on.

Step 1 of 3

Web calls pay

Our systemUserWeb servicespan A, trace 1Pay serviceno headerCollectorTrace storage

A self-written client forgets the traceparent header.

Step 1: Web calls pay

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Memory storage in production

    critical

    Every trace is lost on a restart, and without a limit memory grows.

    Wrong
    backends:  main:    memory: {}
    Right
    backends:  main:    elasticsearch:      server_urls: ["https://es1:9200"]
  • Each service samples alone

    critical

    Traces have holes, because services keep different requests.

    Wrong
    if random() < 0.1: record()
    Right
    OTEL_TRACES_SAMPLER=parentbased_traceidratioOTEL_TRACES_SAMPLER_ARG=0.1
  • Rates from sampled traces

    major

    Tail sampling keeps errors on purpose, so the error share looks far too high.

    Wrong
    error_rate = kept_errors / kept_traces
    Right
    # span metrics first, sampling after
  • The interface on the internet

    critical

    It has no accounts, and traces contain URLs, queries and ids.

    Wrong
    -p 0.0.0.0:16686:16686
    Right
    # only behind a login proxy
  • More collectors for slow storage

    minor

    The queues fill a little later, that is all.

    Wrong
    replicas: 20
    Right
    # Kafka, more storage, or fewer spans

Interview tips

  • How to explain it

    • One id for one request.
    • Spans form a tree.
    • Jaeger stores and draws it.
  • Reading a trace

    • Look at self time.
    • Look for staircases and gaps.
    • Compare slow with normal.
  • Reach for it when

    • Requests cross many services.
    • Only some requests are slow.
    • You run OpenSearch or Elasticsearch anyway.
  • Keep in mind

    • Storage is the limit.
    • Version 1 has ended.
    • No accounts in the interface.