Add IHttpMetricsTagsFeature and IConnectionMetricsTagsFeature #47493
Labels
api-approved
API was approved in API review, it can be implemented
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Uh oh!
There was an error while loading. Please reload this page.
Background and Motivation
ASP.NET Core hosting counters record the number of current requests and duration. There isn't a way for a framework, middleware or app to enrich these counters with tags per-request. For example, ASP.NET Core might want to add a tag to the HTTP server metrics that specifies whether there was an unhandled exception with that request.
This issue outlines an ASP.NET Core feature for adding tags to metrics. It's similar to the existing
IHttpActivityFeature
. For an example of enriching the request activity with tags, see Activity Enrichment in ASP.NET Core 6.0.Proposed API
Implementations are internal. Features are automatically set on the
HttpContext
orTransportConnection
if metrics is enabled (aka someone is listening).Usage Examples
The feature is used by frameworks, middleware or apps when they want to enrich HTTP metrics counters (or connection counters) with extra tags. In the sample below, middleware catches unhandled exceptions, then uses the feature to add the exception type name to metrics.
ASP.NET Core hosting uses the feature when recording counters.
Alternative Designs
One feature could be used for HTTP request and connection.
I believe that approach means it wouldn't be possible to get the connection metrics tags feature from a request, because the request feature of the same type would always be returned.
Risks
The text was updated successfully, but these errors were encountered: