Skip to content

HostingMetrics: empty "http.route" tags shouldn't be present #62432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Elanis
Copy link

@Elanis Elanis commented Jun 21, 2025

HostingMetrics: empty "http.route" tags shouldn't be present

When pushing metrics to third-party softwares such as prometheus. Having empty-valued labels will cause issues

Description

Microsoft.AspNetCore.Hosting create a metric called http.server.request.duration documented here: https://learn.microsoft.com/en-us/aspnet/core/log-mon/metrics/built-in

One the available labels is http.route which is optional.

Issue:

http.route can be populated with various string such as:

  • path/to/my/route/{id}
  • index
  • api/controller/route
  • <empty string>
  • ...

And it can also be missing.

However, based on the OpenMetrics spec used by Prometheus, empty label values should be treated as if the label was not present.
That means when exporting data to prometheus, we currently create two different metrics (one for http_route= <empty string>, one for the missing http_route), which create a "duplicate sample for timestamp" error when importing data.

Fix:

To fix this issue, I changed the metric labelling so an empty route doesn't create the label, as if the variable was null.

Fixes #62431

@Elanis Elanis requested a review from halter73 as a code owner June 21, 2025 11:04
@github-actions github-actions bot added the area-hosting Includes Hosting label Jun 21, 2025
@Elanis
Copy link
Author

Elanis commented Jun 21, 2025

@dotnet-policy-service agree

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 21, 2025
Copy link
Contributor

Thanks for your PR, @@Elanis. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@Elanis
Copy link
Author

Elanis commented Jun 21, 2025

Feel free to ping me whenever someone in the team have time to review this :)
Also, I don't know what's the usual way to do things here since it's my first contribution, so feel free to guide me.

And finally, if this feature can be backported in .NET 9 I would be extremely happy as it's producing lots of erroneous data in my monitoring stack 😅 (thus why I noticed this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HostingMetrics: empty "http.route" tags shouldn't be present
1 participant