I noticed that when HttpClient is used in ASP.Net Core web api controller, it adds Request-Id header to the requests it sends. That does not happen when HttpClient is used in e.g. a .Net Core console app.
I presume this is done to implement correlation (or tracking) IDs, but how does it work? What exactly adds this header?
Also how can I remove it? I've implemented my own correlation IDs.
I have stumbled across this problem when all requests issued by RestSharp were also containing Request-Id. The solution mentioned in the comments also worked for me and deserves to be promoted as an answer:
private void DisableCorrelationIds(IServiceCollection services)
{
var module = services.FirstOrDefault(t =>
t.ImplementationFactory?.GetType() == typeof(Func<IServiceProvider, DependencyTrackingTelemetryModule>));
if (module != null)
{
services.Remove(module);
services.AddSingleton<ITelemetryModule>(provider => new DependencyTrackingTelemetryModule
{
SetComponentCorrelationHttpHeaders = false
});
}
}
public void ConfigureServices(IServiceCollection services)
{
// other stuff may come here
DisableCorrelationIds(services);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With