📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Explain W3C Trace Context. What is in the traceparent and tracestate headers, what is W3C Baggage and when should you use it, how does .NET propagate these headers (and what changed in .NET 10), and how do you handle trace context when crossing into other vendors' systems or accepting it from the public internet?

Covers the traceparent and tracestate formats, the sampled flag, W3C Baggage and its risks, DistributedContextPropagator and the .NET 10 switch to the W3C propagator, interoperating with B3 and vendors, and trust boundaries at the public edge.

Mid-Level Theory Intermediate baggage context-propagation distributed-tracing observability opentelemetry w3c-trace-context

🎯 Key points

  • traceparent = version-traceid-parentid-flags, e.g. 00-<32 hex>-<16 hex>-01; flag bit 0 = sampled
  • tracestate = up to 32 vendor key=value entries; must be forwarded even if unknown; a vendor updates only its own entry
  • W3C Baggage header carries application key/values to every downstream hop, in clear text, limited to about 8 KB
  • Before .NET 10 the default (legacy) propagator already wrote traceparent but sent baggage as Correlation-Context; .NET 10's W3C default uses the baggage header and W3C ids only
  • CreatePreW3CPropagator is a temporary bridge for services still reading Correlation-Context, not a permanent setting
  • OpenTelemetry's DefaultTextMapPropagator = TraceContext + Baggage; add B3Propagator for Zipkin-era or some service-mesh peers
  • Trust boundary: inbound traceparent from the internet can force 100% sampling (cost) and baggage can inject data; start a new trace, link the external context, strip baggage
  • Baggage is a data-leak path: allow-list keys, no personal data or tokens, suppress propagation to third parties

⏱ 30-second answer

W3C Trace Context standardises how a trace crosses process boundaries. traceparent is version-traceid-parentid-flags, for example 00-4bf92f35...4736-00f067aa0ba902b7-01, where the last byte's low bit means sampled. tracestate carries up to 32 vendor-specific key=value entries that every hop must forward even if it doesn't understand them.

W3C Baggage (baggage header) carries application key/values, such as a tenant tier, to every downstream service, in clear text. Use it sparingly and never for personal data.

In .NET, HttpClient writes the headers through DistributedContextPropagator.Current, and since .NET 10 that is the W3C propagator by default (standard baggage instead of Correlation-Context). OpenTelemetry uses TraceContext + Baggage propagators, plus B3 if you talk to Zipkin-era systems.

The trade-off: trusting inbound context gives end-to-end traces with partners, but at the public edge it lets anyone set your sampling and baggage.

🗣 Full answer (senior)

How I would answer this in an interview

"W3C Trace Context is the standard that lets a trace survive a hop between services written by different teams or vendors. It defines two HTTP headers. traceparent has four dash-separated fields: a version, which is 00 today; the 32-hex-character trace id; the 16-hex-character id of the calling span, which becomes the parent; and a flags byte where bit 0 says whether the caller sampled the trace. tracestate is a list of up to 32 vendor entries, like congo=t61rcWkgMzE, which carries vendor-specific data; the rule is that you forward it unchanged, and a vendor only edits its own entry, moving it to the front.

Separate from that is W3C Baggage, a baggage header of application key/values that propagates to every downstream hop. It's useful for things like a tenant.tier=gold that a downstream service uses to tag its spans, but it's sent in clear text to every service and often to third-party APIs, so personal data never goes in it. In .NET, HttpClient injects these headers through DistributedContextPropagator.Current. In .NET 10 the default changed to the W3C propagator, so baggage now goes in the standard baggage header instead of the old Correlation-Context, and the legacy hierarchical ids are no longer propagated. If an old service still relies on Correlation-Context, CreatePreW3CPropagator() restores the old behaviour while you migrate.

The mistake I see is trusting inbound context from the internet. A client can send traceparent with the sampled flag set on every request and force you to record everything, or stuff baggage that you then forward to internal services. At the public edge I start a new trace, keep the external context only as a span link, and drop inbound baggage. Inside the trust boundary, propagate everything; at the edge, decide."


The headers

Header Format Owner Rules
traceparent 00-{trace-id 32 hex}-{parent-id 16 hex}-{flags 2 hex} Standard All-zero ids are invalid; unknown versions parsed best-effort
tracestate vendor1=value,vendor2=value (max 32 entries) Vendors Forward unchanged; edit only your own entry and move it left
baggage key=value;metadata,key2=value2 Application Percent-encoded values; about 8,192 bytes total

Propagation formats you may meet

Format Headers Seen in .NET support
W3C Trace Context traceparent, tracestate Everything modern Default (TraceContextPropagator)
W3C Baggage baggage OpenTelemetry BaggagePropagator
B3 X-B3-TraceId... or single b3 Zipkin-era services, some Envoy/Istio set-ups B3Propagator in OpenTelemetry.Extensions.Propagators
Legacy .NET Request-Id, Correlation-Context Old Application Insights SDK apps CreatePreW3CPropagator()

Trust boundaries

Inbound from Honour traceparent? Honour sampled flag? Honour baggage?
Your own services Yes Yes (ParentBased sampler) Yes
Trusted partner with shared tracing Yes, or link Your choice Only agreed keys
Public internet / browsers Link only No No, strip it

Production example

After an upgrade to .NET 10, a downstream service that read Correlation-Context for a tenant tier lost it, and 30% of its spans had no tenant.tier tag, breaking a per-tier latency dashboard. We updated the reader to OpenTelemetry's Baggage API (standard baggage header) within a day instead of reverting to the legacy propagator.

🔍 What the interviewer is checking

Checks that the candidate understands the wire format behind propagation and the security, cost and compatibility decisions around it.

Green flags

  • Explains all four traceparent fields and the sampled flag
  • Knows tracestate forwarding rules and what baggage is for
  • Mentions the .NET 10 propagator change or DistributedContextPropagator
  • Treats inbound context at the edge as untrusted input (forced sampling cost, injected baggage)
  • Notes that every baggage byte travels on every downstream call

Red flags

  • Confuses baggage with span attributes
  • Suggests putting user details in baggage
  • Thinks a custom correlation header is equivalent

📚 Learn in depth

1. Why a standard was needed

Before 2020 every vendor had its own headers: Zipkin's X-B3-*, Jaeger's uber-trace-id, Application Insights' Request-Id, AWS's X-Amzn-Trace-Id. A request crossing two vendors lost its trace. W3C Trace Context (a W3C Recommendation since February 2020) defines one wire format everyone can forward.

2. traceparent in detail

00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
|  |                                |                |
|  trace-id: 16 bytes, random      parent-id: 8 bytes   trace-flags: 0x01 = sampled
version (00)
  • The parent-id is the span id of the caller's client span. The receiver creates a new span id for itself.
  • Sampled flag: tells the callee the caller recorded this trace. OpenTelemetry's ParentBasedSampler follows it, so a trace is either fully recorded or fully dropped.
  • Trace Context Level 2 (still a W3C Candidate Recommendation at the time of writing) adds a random flag saying the trace id's right-most 7 bytes are random, which lets samplers make consistent probability decisions.

3. tracestate

An ordered list, left = most recently updated. Example: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE. Vendors use it for things like their own sampling probability (OpenTelemetry uses the ot key for consistent probability sampling). Rules: at most 32 entries, keys lower-case, and a service that doesn't recognise an entry must forward it.

4. Baggage

baggage: tenant.tier=gold,feature.checkout_v2=on

Baggage is not attached to spans automatically. A service must read it (Baggage.GetBaggage("tenant.tier")) and copy it onto spans or logs if wanted; OpenTelemetry has a baggage span processor in contrib for that. Each hop forwards it, so every value costs bytes on every downstream request, and anything in it can leak to any third party you call.

5. How .NET propagates

HttpClient -> SocketsHttpHandler -> DistributedContextPropagator.Current.Inject(activity, request)
ASP.NET Core hosting -> DistributedContextPropagator.Current.ExtractTraceIdAndState / ExtractBaggage
  • .NET 10: DistributedContextPropagator.CreateDefaultPropagator() returns the W3C propagator and Current defaults to it. Baggage uses baggage, only W3C-format ids are propagated, and keys and values are encoded per the spec. CreatePreW3CPropagator() gives back the legacy behaviour.
  • SocketsHttpHandler.ActivityHeadersPropagator lets you override per handler; setting it to DistributedContextPropagator.CreateNoOutputPropagator() stops injection (useful for calls to third parties).
  • OpenTelemetry instrumentation and messaging code use Propagators.DefaultTextMapPropagator (composite TraceContext + Baggage) instead.

6. Edges and vendors

  • Outbound to a third party: they may log your trace id, which is harmless, but they also receive your baggage. Suppress propagation for external hosts or keep baggage empty.
  • Inbound from browsers: front-end OpenTelemetry can send traceparent for real end-to-end traces. Accept it from your own SPA origin if you want, but ignore the sampled flag and baggage.
  • Mixed formats: configure a composite propagator that extracts both W3C and B3 during a migration, and injects both until all peers speak W3C.

Try it yourself

  1. Call a .NET 10 API with curl -H "traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" and log Activity.Current?.TraceId and ParentSpanId.
  2. Send baggage: tier=gold and read it with Baggage.GetBaggage; then switch to CreatePreW3CPropagator() and see what changes.
  3. Use a DelegatingHandler to print outgoing headers for an HttpClient call.
  4. Configure CompositeTextMapPropagator with TraceContext, Baggage and B3, and call a service that only sends B3.
  5. Set ActivityHeadersPropagator to the no-output propagator for one named client and confirm the header is gone.

💻 Code

Edge handling and propagation choices in an ASP.NET Core 10 service.

// Program.cs
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Context.Propagation;
using OpenTelemetry.Extensions.Propagators; // B3Propagator
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

// During a migration from Zipkin-era services: extract and inject both W3C and B3.
Sdk.SetDefaultTextMapPropagator(new CompositeTextMapPropagator(
[
    new TraceContextPropagator(),
    new BaggagePropagator(),
    new B3Propagator()
]));

builder.Services.AddOpenTelemetry().WithTracing(t => t
    .SetSampler(new ParentBasedSampler(new TraceIdRatioBasedSampler(0.1)))
    .AddAspNetCoreInstrumentation()
    .AddHttpClientInstrumentation()
    .AddOtlpExporter());

// Calls to a third-party API: don't send our trace headers or baggage.
builder.Services.AddHttpClient("payments-provider")
    .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler
    {
        ActivityHeadersPropagator = DistributedContextPropagator.CreateNoOutputPropagator()
    });

var app = builder.Build();

// Public edge: never forward baggage that came from the internet.
app.Use(async (context, next) =>
{
    context.Request.Headers.Remove("baggage");
    Baggage.Current = default;
    await next(context);
});

// Inside the trust boundary, set baggage for downstream services (no personal data).
app.MapGet("/orders/{id}", (Guid id, HttpContext http) =>
{
    Baggage.SetBaggage("tenant.tier", http.User.FindFirst("tier")?.Value ?? "standard");
    Activity.Current?.SetTag("tenant.tier", Baggage.GetBaggage("tenant.tier"));
    return Results.Ok(new { id });
});

app.Run();
# See what the service makes of an incoming context
curl -s http://localhost:5000/orders/7c9e6679-7425-40de-944b-e07fc1f90ae7 \
  -H "traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" \
  -H "tracestate: congo=t61rcWkgMzE"

Note: removing the baggage header in middleware runs after ASP.NET Core hosting has already extracted it into the request activity, which is why the example also clears Baggage.Current. For full control, strip the header at the gateway (Azure API Management or Application Gateway rewrite rules).

⚠ Common mistakes

  • Mistake: Treating the parent-id in traceparent as the receiver's own span id. Why it is wrong: the receiver creates a new span; the header id is its parent. Instead: read it as "the caller's client span".
  • Mistake: Dropping or rewriting tracestate entries you don't recognise. Why it is wrong: it breaks vendors further down the chain. Instead: forward unknown entries unchanged.
  • Mistake: Putting user ids, emails or tokens in baggage. Why it is wrong: baggage is clear text, forwarded to every hop and third parties, and is a Privacy Act APP 11 exposure. Instead: only non-sensitive, bounded values like a tier or feature flag.
  • Mistake: Honouring the sampled flag from public clients. Why it is wrong: any client can force 100% recording and drive up cost. Instead: root sampler at the edge; link external context.
  • Mistake: Upgrading to .NET 10 without checking Correlation-Context consumers. Why it is wrong: the default propagator now sends baggage, so old readers see nothing. Instead: move readers to the Baggage API, or temporarily set CreatePreW3CPropagator().
  • Mistake: Mixing B3 and W3C peers without a composite propagator. Why it is wrong: traces split at the boundary. Instead: extract and inject both until the migration is done.
  • Mistake: Expecting baggage to appear on spans automatically. Why it is wrong: baggage and span attributes are separate. Instead: copy the keys you need onto spans explicitly.

🏛 Senior insight: trade-offs

The standard solves interoperability; the senior work is deciding where the trust boundary is. Inside it, forward everything and let the parent's sampling decision win so traces are complete. At the edge, treat inbound context as untrusted input, like any other header. Baggage is powerful but is effectively a global variable broadcast to every service; keep an allow-list of keys and review it like an API contract.

Option When it fits Cost When not to
W3C only All peers on modern SDKs None Zipkin/B3 peers remain
Composite W3C + B3 Migration from Zipkin or B3-configured mesh Extra headers on every call After migration
Legacy propagator (CreatePreW3CPropagator) Short-term during .NET 10 upgrade Non-standard headers As a permanent setting
Suppress propagation Calls to third parties Lose their side of the trace Partners who share your tracing

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions correlation ids alongside traceparent Why: Checks whether they still need a custom correlation id and how logs pick up the trace id
    How to answer

    Two mechanisms work together.

    • Log scopes: using (logger.BeginScope(new Dictionary<string, object> { ["OrderId"] = id })) adds properties to every log inside the block, flowing across await via AsyncLocal. ASP.NET Core already opens a scope per request with RequestId and RequestPath.
    • Distributed tracing: each request runs inside an Activity whose trace id comes from the incoming W3C traceparent header or is created new. With ActivityTrackingOptions (on by default in the Generic Host) every log carries TraceId and SpanId. HttpClient propagates traceparent automatically; message queues need it copied into message properties (the Azure Service Bus SDK does this).

    So the trace id is your correlation id; add business ids as properties. The trade-off: custom correlation headers are easy but don't interoperate with tracing tools.

  2. When: Candidate mentions propagating context outside HTTP Why: Checks they can carry the same headers through Service Bus messages
    How to answer

    Create a static ActivitySource, wrap the send in a Producer span and the handler in a Consumer span, and carry the context in the message. On send, call Propagators.DefaultTextMapPropagator.Inject to write traceparent (and tracestate/baggage) into ServiceBusMessage.ApplicationProperties. On receive, Extract it and pass the resulting ActivityContext as the parent to StartActivity, so the consumer's spans join the producer's trace.

    The Azure SDK can do some of this itself: it writes Diagnostic-Id in traceparent format, and its own spans are experimental, needing the Azure.Experimental.EnableActivitySource switch and AddSource("Azure.Messaging.ServiceBus.*").

    Tag spans with messaging semantic conventions. When one span handles a batch, or processing happens hours later, use span links instead of a parent. The trade-off: parent/child gives one tidy trace, but long-delayed work makes huge, misleading traces.

  3. When: Candidate mentions personal data or baggage risk Why: Checks their approach to keeping personal information out of telemetry
    How to answer

    Treat logs as a data store that attackers and too many staff can read. Never log secrets (passwords, tokens, Authorization headers, connection strings, card numbers) and keep personal information out: log identifiers like CustomerId, not names, emails or request bodies.

    Enforce it in code rather than by memory: Microsoft.Extensions.Compliance.Redaction lets you classify fields with attributes, map classifications to redactors (erase, or HMAC for a stable pseudonym) with AddRedaction, and apply them to logs with EnableRedaction. Use header allowlists in HTTP logging.

    In Australia, APP 11 requires reasonable steps to protect personal information and APP 11.2 requires destroying or de-identifying it when no longer needed, so retention matters, and a leaked log store can be a notifiable data breach. The trade-off: less detail in logs versus a smaller breach surface.

🛠 Real-world problems: how you handle them

Tenant tier vanished from spans after the .NET 10 upgrade
Situation
A multi-service SaaS platform [about 25 services] passed the customer's plan tier downstream so each service could tag spans and enforce rate limits. The upstream services were upgraded to .NET 10 first.
Signals
A Grafana panel of latency by tenant tier showed a growing 'unknown' series after each service upgraded. Rate limiting in a downstream .NET 8 service started treating gold customers as standard, and [two] customers reported throttling.
Investigation
Captured outgoing headers with a DelegatingHandler and saw `baggage: tenant.tier=gold` instead of `Correlation-Context`. Read the .NET 10 breaking-change notes: the default DistributedContextPropagator is now W3C. The downstream service read `Activity.Current.Baggage`, populated from Correlation-Context by its pre-W3C default.
Resolution
Immediately set `DistributedContextPropagator.Current = DistributedContextPropagator.CreatePreW3CPropagator()` in the upgraded services to restore behaviour. Then changed the downstream readers to OpenTelemetry's Baggage API with the composite TraceContext + Baggage propagator, and removed the legacy setting once all services read the standard header.
Prevention
Added a contract test that sends a request through two services and asserts the tier arrives. Baggage keys are now an allow-list documented in an ADR. The upgrade checklist includes the runtime breaking-change list.

How to tell it (STAR)

**S:** At [company], after upgrading part of our platform to .NET 10, gold customers started being throttled as standard. **T:** I had to restore correct behaviour fast and finish the migration properly. **A:** I captured the headers, found .NET 10 now sends standard W3C baggage instead of Correlation-Context, rolled back to the legacy propagator as a stopgap, then moved every reader to the Baggage API and added a cross-service contract test. **R:** Throttling complaints stopped [within the hour], and we removed the legacy propagator [two weeks] later with zero 'unknown' tier spans.

More in Tracing

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me