-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Description
Background and Motivation
The Open Telemetry HTTP server semantic conventions records required and optional data to include with metrics measurements. A recommended tag is the route match by the HTTP request. For example, an HTTP request to app.MapGet("product/{id}", () => ...)
would have the route product/{id}
.
The route is available in ASP.NET Core on the matched endpoint in the RouteEndpoint.RoutePattern. However, HTTP metrics are run in Microsoft.AspNetCore.Hosting
. That code doesn't have access to RouteEndpoint
, which is in Microsoft.AspNetCore.Routing
, because of layering.
Two possible solutions:
- Move
RouteEndpoint
,RoutePattern
, and all its dependencies toMicrosoft.AspNetCore.Http.Abstractions
and type forward. Then hosting can check if the matched endpoint is aRouteEndpoint
and access the route. However, the route pattern is quite a lot of code to move. - Or, add new diagnostics metadata to
Microsoft.AspNetCore.Http.Abstractions
. The metadata has a property with a string version of the pattern. Hosting diagnostics can then get the metadata from the endpoint, and use whatever text value is present.
Proposed API
namespace Microsoft.AspNetCore.Http.Metadata;
+ public interface IRouteDiagnosticsMetadata
+ {
+ string Route { get; }
+ }
Usage Examples
if (context.MetricsEnabled)
{
var route = httpContext.GetEndpoint()?.Metadata.GetMetadata<IRouteDiagnosticsMetadata>()?.Route;
_metrics.RequestEnd(
httpContext.Request.Protocol,
httpContext.Request.Scheme,
httpContext.Request.Method,
httpContext.Request.Host,
route,
httpContext.Response.StatusCode,
startTimestamp,
currentTimestamp);
}
Alternative Designs
See description.
Risks
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions