Description
Bug
The http.route
attribute is one of the more important HTTP attributes because users commonly wish to facet their metric and span data on http.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:
dotnet new razor
The following is abbreviated, but Program.cs
will look something like:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
var app = builder.Build();
app.UseRouting();
app.MapRazorPages();
app.Run();
The application contains multiple pages - e.g., Index
, Privacy
, etc. The Index
page is the default page - i.e., when invoking the root path /
the Index page will be returned and http.route
attribute will be omitted.
Suggested fix
Well-known route parameters (e.g., page
) should be used instead of the route template. Using the HttpContext.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.