Description
Ask:
An ability to extract some useful route/request metadata about the request inside HttpMessageHandlers/DelegatingHandlers.
Currently in AspNetCore the routing component provide applications the ability to get route metadata for incoming HTTP requests. This let application and library developers to utilize this information in custom middlewares. A similar capability however lacks in the HttpClient framework as there is no way for a handler in pipeline to determine the route of the request.
Scenario
Currently we write telemetry libraries for consumption by 100s of services in our org. These telemetry libraries automatically captures and emit telemetry about incoming and outgoing http requests. When capturing metrics to monitor service health and gain useful insights the captured metrics need to be able to narrow down the problems by the requests (if certain requests are impacted or all requests are impacted) or by the target service to which the requests are made, so one can see which of the target service is unhealthy.
For the incoming requests the telemetry middlewares can extract the route information from route metadata provided by endpoint routing, however for outgoing requests delegating handlers don't have access to any such information. They only have access to the full URL which can't be used when capturing metrics becuase URLs might have parameters which leads to every URL being different at which point it just becomes not useful.
Currently everywhere services have to write their custom logics or library developers provide hooks for services to provide such information. Because at that point service developers have no way to get this information easily they need to resort to using regular expressions to match the URL with some set of list of routes. This regular expression matching becomes extremely inefficient. So, the ask is for dotnet runtime to include some efficient mechanism to extract the route information and possibility some additional metadata like a friendly name of the target service where the http client is making request to.
What we have
As part of telemetry libraries we have created our own solution to let services configure and register metadata with us when they configure our telemetry libraries. Our libraries then performs the matching of requests against routes (in a more efficient manner without involving regexes) to extract the metadata so it can be included in the telemetry.
We would like to see an efficient solution from dotnet runtime itself which can provide metadata about outgoing requests to these delegating handlers.