-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issuesTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Describe the bug
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.
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
9.0
Anything else?
No response
Activity
MackinnonBuck commentedon Jun 23, 2025
@JamesNK, should we not be adding the
http.route
attribute when it's empty?JamesNK commentedon Jun 23, 2025
Is it valid to have an empty string here? I think
app.MapGet("", () => "Hello world")
would match the site route.Need to test. If empty string is a valid route in ASP.NET Core then maybe we turn empty string into
http.route=/
.JamesNK commentedon Jun 23, 2025
I confirmed that an empty string for MapGet does work and matches the root of the web app.
Also the OpenTelemetry spec says that attribute values with an empty string are meaningful: https://opentelemetry.io/docs/specs/otel/common/
Elanis commentedon Jun 24, 2025
Hm, so OTEL and Prometheus don't agree on this...
I didn't find this before, thanks for digging!
This still poses an issue, but a more complex than I thought 😅
halter73 commentedon Jun 26, 2025
I'm pretty sure an empty route is valid and exactly equivalent to "/", so I agree this is what we should do. The safest thing is probably to only do this for metrics, but I think this could be normalized even during RouteEndpoint creation without much impact.
Elanis commentedon Jun 27, 2025
I believe this a good way to solve this issue yes!
It looks like I get this empty HTTP route only on my razor-based projects, and not on webapi projects, so that's probably the root route indeed.
Elanis commentedon Jul 11, 2025
Hi!
I'm up to update the PR ( #62432 ) when you agree on a solution, I guess it still needs some further discussions, but feel free to @ me once you agreed on a solution, I'll be happy to write it and make this bug disappear :)
sebastienros commentedon Jul 29, 2025
@Elanis I believe @JamesNK and @halter73 agree with using
/
when the route is empty. Do you want to update your PR with that behavior, it would still be able to make it for the next release.Elanis commentedon Jul 29, 2025
Done :)
HostingMetrics: empty "http.route" tags should be set to "/"
[release/10.0-rc1] Empty "http.route" tags should be set to "/" (#63336)