Azure 63: Distributed Tracing with OpenTelemetry
easy⏱ 5 mincourseazure
Traces, spans & context
A trace is one request's journey; each unit of work is a span with a start, end and parent. Services propagate a trace context (the W3C traceparent header) so spans in different processes join the same trace. OpenTelemetry is the vendor-neutral SDK + wire format — export the spans to App Insights, Datadog or Jaeger, your choice.
// W3C trace context header
// traceparent: 00-<trace-id>-<span-id>-01
// ^32 hex ^16 hex ^flags
Sampling
At scale you can't store every trace. Head sampling decides at the start (cheap, may miss the interesting ones); tail sampling decides after the trace completes (keeps slow/errored ones, needs a collector). Most teams keep 100% of error traces and a small % of the rest.
Measure the trace
Given spans { name, start, end } (ms), compute the total trace duration (latest end − earliest start) and the single slowest span. Log trace duration: Nms and slowest span: <name>.
Propagate the context or lose the trace
The #1 broken-tracing bug: an outbound call that doesn't forward traceparent, so downstream spans start a brand-new trace. Use auto-instrumentation and verify the trace is unbroken across every hop.
Quiz: what joins spans across services?
Spans in different processes join one trace via the propagated trace context (traceparent header) — not by timestamps or service names.