Skip to content

Add a way to configure the IHttpRequestIdentifierFeature to read a configurable header #5914

Closed
@sirajmansour

Description

@sirajmansour

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.

Metadata

Metadata

Assignees

Labels

Needs: DesignThis issue requires design work before implementating.affected-fewThis issue impacts only small number of customersarea-hostingIncludes Hostingarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneseverity-minorThis label is used by an internal tool

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions