-
Notifications
You must be signed in to change notification settings - Fork 293
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
[AspNetCoreInstrumentation] Incorrect value for http.route
when using conventional routing
#1730
Comments
I hit this today. Sharing some more concrete examples: I configured my test app same as Alan:
My test app has a
|
I am facing the exact same issue for all requests in net8. As a workaround I found the following: .AddAspNetCoreInstrumentation(
o => {
o.EnrichWithHttpResponse = (activity, response) => {
var template = response.HttpContext.Request.Path;
activity.DisplayName = template;
activity.SetTag("http.route", template);
};
}
) |
This regression needs some attention. I agree with the OP that the http.route attribute is very important. Thanks for the workaround @stevenmccormack |
@DanielLaberge @stevenmccormack |
Any update on this? |
Using both conventional routing and |
Bug
The
http.route
attribute is one of the more important HTTP attributes because users commonly wish to facet their metric and span data onhttp.route
in order to understand the performance characteristics of specific endpoints in their applications.ASP.NET Core apps that use conventional routing are not well supported. With conventional routing, it is common that a single route template matches many distinct routes. For these applications the instrumentation sets
http.route
to the value of the route template and not to a value that represents the actual route invoked. In turn, this means users lose the ability to understand the performance of specific endpoints.This bug was introduced in open-telemetry/opentelemetry-dotnet#5026 to conform with the behavior of ASP.NET Core 8 which natively emits the
http.server.request.duration
metric. We wanted to avoid a surprise change in behavior for users migrating from earlier versions of .NET to .NET 8. Fixing this bug should be done in coordination with the ASP.NET Core team.Reproduce
Run:
The following is abbreviated, but
Program.cs
will look something like:The application's
HomeController
contains multiple actions - e.g.,Index
,Privacy
, etc. Invoking any of these endpoints will result in a metric and span with thehttp.route
attribute set to{controller=Home}/{action=Index}/{id?}
.Suggested fix
Well-known route parameters (e.g.,
controller
,action
) should be replaced by their actual values. Using theHttpContext.GetRouteData()
method is one way to get the actual route parameter values.One potential option would be to apply the fix for .NET 6 and .NET 7 users gated by an environment variable.
The text was updated successfully, but these errors were encountered: