You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Disabling activity trace propagation for a specific HttpClientHandler with underlying BrowserHttpHandler #85883
Seems there are mainly 2 methods for disabling trace propagation (header alteration) for a HttpClient:
DistributedContextPropagator.Current = DistributedContextPropagator.CreateNoOutputPropagator() to make a process-wide change;
new HttpClient(new SocketsHttpHandler { ActivityHeadersPropagator = null }); to make a specific SocketsHttpHandler change.
The problem is that when the project is used under a browser (in a Blazor WASM project), primary handler (which is by default HttpClientHandler) uses a BrowserHttpHandler as an underlying handler. And this handler doesn't have anything for propagator control. More than that it is marked as internal which makes in unavailable for a client.
But just like SocketsHttpHandler (which is created inside HttpClientHandler when not under browser platform) it also creates an underlying DiagnosticsHandler (also internal, btw). And I'm not sure there is any possibility to disable trace propagation for it except method (1).
The only solution I've came across currently is based on this gist. However I couldn't find a way to make it work for a specific HttpClientHandler or at least HttpClient.
This is need in a case where there are multiple typed HttpClient's which are accessing different API resources. And some of them are CORS limited which makes usage of custom headers problematic. But we don't want to loose tracing for other APIs.
Is there any workaround for .NET 6?
The only one I have in my mind right now is to duplicate BrowserHttpHandler in my app and 'reinvent' HttpClientHandler to use a custom one when under browser. But I'm not sure if it's the right path to choose.
Also I've found some discussions about DiagnosticHandler.SuppressActivityPropagation ( #29796 and #29291). Is this already implemented? Couldn't find anything.
@MihaZupan thanks for the gist with another workaround. I was hoping that one of those mentioned enhancements were implemented to make a more granular control.
Just in case if this needs more examples, we make requests for GitHub API under Blazor WASM. When activities are enabled (to track other requests) making a simple GET request under Chrome results in errors like this:
Stating that Request header field traceparent is not allowed by Access-Control-Allow-Headers in preflight response.
Activity
radical commentedon May 8, 2023
cc @pavelsavara @maraf @lewing
MihaZupan commentedon May 9, 2023
Workarounds are possible, but ideally, there would be a proper way to configure this via API.
You can disable this entirely for the process by setting an AppContext switch
or environment variable
Or configure it per handler with a hacky workaround like this: https://gist.github.com/MihaZupan/835591bb22270b1aa7feeeece721520d
which involves creating a custom propagator, and inserting a custom handler for clients where you want to disable trace propagation.
uhfath commentedon May 10, 2023
@MihaZupan thanks for the gist with another workaround. I was hoping that one of those mentioned enhancements were implemented to make a more granular control.
Just in case if this needs more examples, we make requests for GitHub API under Blazor WASM. When activities are enabled (to track other requests) making a simple GET request under Chrome results in errors like this:

Stating that
Request header field traceparent is not allowed by Access-Control-Allow-Headers in preflight response.pavelsavara commentedon Sep 17, 2025
I think we already implemented this withHttpActivityPropagationSupportandSystem.Net.Http.EnableActivityPropagationlinker feature.Edit: you are asking about granular control
runtime/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.Current.Manifest/WasmFeatures.props
Line 10 in 0b195cc