Advertisement
Advanced .NET, Diagnostics & Performance

How does distributed tracing correlate a single logical request across multiple microservices, and what is a 'trace context' propagated between them?

Short answer

Distributed tracing assigns a unique trace ID to a request when it first enters the system, propagated forward via HTTP headers (following the W3C Trace Context standard: traceparent header) to every downstream service call, with each service creating its own 'span' (a timed…

Save .NET mock interview
Advertisement
AModel answer
Distributed tracing assigns a unique trace ID to a request when it first enters the system, propagated forward via HTTP headers (following the W3C Trace Context standard: traceparent header) to every downstream service call, with each service creating its own 'span' (a timed unit of work) tagged with that shared trace ID -- an observability backend then reconstructs the full request timeline by linking all spans sharing the same trace ID, letting you visualize exactly how long each hop in a multi-service call chain took.
// W3C traceparent header automatically propagated by OpenTelemetry instrumentation
// traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
//              version-traceId-------------------------spanId----------flags

builder.Services.AddOpenTelemetry()
    .WithTracing(t => t.AddAspNetCoreInstrumentation().AddHttpClientInstrumentation());
// HttpClient calls automatically propagate the traceparent header to downstream services
Real-world example
A distributed trace reveals that a single user-facing API request spent 200ms in the API gateway, 50ms in an order service, and a surprising 1800ms in a downstream inventory service call, immediately pinpointing exactly where to focus optimization effort.
Likely follow-ups
  • What is a 'span' versus a 'trace' in distributed tracing terminology?
  • How does trace sampling reduce overhead in high-throughput systems?
Related topics