5

When I send any requests with HttpClient, it automatically attaches the header TraceParent to the request headers. I tried clearing all the default request headers, but that didn't make a difference.

Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104

1 Answers1

1

Header traceparent or Request-Id specified by DiagnosticsHandler: https://github.com/dotnet/runtime/blob/release/5.0/src/libraries/System.Net.Http/src/System/Net/Http/DiagnosticsHandler.cs#L286

How to disable this behavior is described here: https://github.com/dotnet/aspnetcore/issues/21012#issuecomment-616570453

ASP.NET Core creates an Activity that represents the request by default. This is what tells HttpClient to send an outgoing request id header. You can disable it in a couple of ways:

  • By setting the current activity to null before making the request (Activity.Current = null)
  • By setting the environment variable DOTNET_SYSTEM_NET_HTTP_ENABLEACTIVITYPROPAGATION to "false" or "0".
  • By the AppContext switch System.Net.Http.EnableActivityPropagation to false
flibustier
  • 26
  • 3