Skip to content

Empty "http.route" tags should be set to "/" #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

Merged
merged 7 commits into from
Aug 19, 2025

Conversation

Elanis
Copy link
Contributor

@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
Contributor 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
@Elanis
Copy link
Contributor 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)

@JamesNK JamesNK self-requested a review June 23, 2025 23:10
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jul 1, 2025
@Elanis
Copy link
Contributor Author

Elanis commented Jul 11, 2025

(This PR is awaiting further discussions in #62431 )

@Elanis Elanis force-pushed the hosting-metrics-empty-http-route branch from e9b92c4 to c70dbcb Compare July 29, 2025 19:14
@Elanis
Copy link
Contributor Author

Elanis commented Jul 29, 2025

Rebased on latest main, and applied changed decided in #62431

@Elanis Elanis changed the title HostingMetrics: empty "http.route" tags shouldn't be present HostingMetrics: empty "http.route" tags should be set to "/" Jul 29, 2025
@JamesNK JamesNK added this to the 10.0-rc1 milestone Aug 19, 2025
@JamesNK JamesNK force-pushed the hosting-metrics-empty-http-route branch from a6af20f to afa7fa2 Compare August 19, 2025 13:25
@JamesNK
Copy link
Member

JamesNK commented Aug 19, 2025

@Elanis I rebased and updated the routing metric to be consistent.

@JamesNK JamesNK changed the title HostingMetrics: empty "http.route" tags should be set to "/" Empty "http.route" tags should be set to "/" Aug 19, 2025
@Elanis
Copy link
Contributor Author

Elanis commented Aug 19, 2025

Thanks!

@sebastienros sebastienros merged commit b773125 into dotnet:main Aug 19, 2025
29 checks passed
@sebastienros
Copy link
Member

/backport to release/10.0-rc1

Copy link
Contributor

Started backporting to release/10.0-rc1: https://github.com/dotnet/aspnetcore/actions/runs/17082938754

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 pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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