dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.44k stars 10.02k forks source link

Allow removal or alteration of framework-added metric tags. #57831

Open Wraith2 opened 1 month ago

Wraith2 commented 1 month ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

I have a multi-tenant system where I am starting to record metrics. There are some important tags that I need to add to the framework provided http.server.request.duration such as user, tenant. I can do this via the IHttpMetricsTagsFeature which provides a Tags collection.

What I can't do it prevent the addition of, or remove after their addition, of framework provided tags like url.scheme or network.protocol.version which have no value to me. These tags seem to be added very late in the lifecycle of the request so when I have access to the IHttpMetricsTagsFeature.Tags through middleware the framework added tags are not present.

In the opentelemetry aspnet (not core) instrumentation there is a callback available which is called once tags have been added and the metric is about to be dispatched. This pattern is ideal. The opentelemetry aspnetcore instrumentation does not have this callback because the metric is now raised by the framework.

Describe the solution you'd like

I would like to have a callback method that I can use to edit the tags on the framework-provided http.server.request.duration event allowing me to remove unwanted tags.

Additional context

The tags can be removed if you are using the otelcol-contrib collector to route data from your app to the destination. This costs resources that could be better spent. It would be better not to generate unwanted information to start with.

amcasey commented 1 month ago

FYI @JamesNK