[AspNetCoreInstrumentation] Incorrect value for http.route
when using razor pages and invoking the root path
#1729
Labels
bug
Something isn't working
comp:instrumentation.aspnetcore
Things related to OpenTelemetry.Instrumentation.AspNetCore
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.For ASP.NET Core apps that use razor pages the route template is used to populate the
http.route
attribute. This is suitable in most cases except for when invoking the root path which will return the default page (e.g.,http://localhost/
). In this scenario,http.route
is omitted. In turn, this limits the ability for users to understand the performance of invoking the default page.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 contains multiple pages - e.g.,
Index
,Privacy
, etc. TheIndex
page is the default page - i.e., when invoking the root path/
the Index page will be returned andhttp.route
attribute will be omitted.Suggested fix
Well-known route parameters (e.g.,
page
) should be used instead of the route template. 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: