Description
I am facing the same dilemma as aspnet/KestrelHttpServer#2153.
Setting the trace identifier on the HttpContext isn't particularly helpful for logging because the request start scope was started before any middleware is called, so all logs use the traceidentifer set by Kestrel.
Basically, we force all incoming requests to our services to have a correlation-id header as we want to track the whole flow coming from the front-end or any other consumers of our APIs. We also prefer using X-Correlation-Id
instead of Request-Id
.
Although it seems a workaround is mentioned there by @davidfowl, i think it is valuable having that option configurable at the early stages of creating the webhost.
It would great to be able to read from a header or (any other delegate/provider). And propagating that change across to HostingApplicationDiagnostics.cs
instead of setting it always to look for Request-Id
header.
Also making the property name in the log name configurable is valuable too as it is also statically set to CorrelationId
as shown in https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Hosting/Internal/HostingLoggerExtensions.cs or RequestId
- for 2.0 - which has the value of the httpcontext.TraceIdentifier that we manually set from our x-correlation-id header.