As I understand there are 2 main methods to disable trace propagation in .NET 6 (for header alteration):
DistributedContextPropagator.Current = DistributedContextPropagator.CreateNoOutputPropagator()
to make a process-wide change;new HttpClient(new SocketsHttpHandler { ActivityHeadersPropagator = null });
to make a specificSocketsHttpHandler
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.