8.14Disabling the Distributed Tracing Context (the traceparent Header)

Updated on Aug 20, 2026~2 min read

When making an HTTP remote request, by default the distributed tracing context contained in the current Activity (such as traceparent and tracestate) is automatically injected into the request's HTTP headers. This mechanism helps downstream services correctly identify and correlate with the same distributed tracing chain.

If, for certain business or security requirements, you need to disable this automatic injection behavior, you can configure it with the following code:

csharp
// Configure the default clientservices.AddHttpClient(string.Empty, client => { })    .ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler()    {        ActivityHeadersPropagator = null // Disable distributed context propagation, or use DistributedContextPropagator.CreateNoOutputPropagator()    });

By setting ActivityHeadersPropagator to null, you can prevent the runtime from automatically injecting the current active distributed tracing information into the HTTP request headers, thereby controlling tracing context propagation. Related Issues: #109558, #90407, #IC7ZZS.