Skip to content
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 razor pages and invoking the root path #1729

Open
alanwest opened this issue Nov 16, 2023 · 1 comment
Labels
bug Something isn't working comp:instrumentation.aspnetcore Things related to OpenTelemetry.Instrumentation.AspNetCore

Comments

@alanwest
Copy link
Member

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.

@prajon84
Copy link

Any update on this issue ?

@reyang reyang transferred this issue from open-telemetry/opentelemetry-dotnet May 13, 2024
@reyang reyang added the comp:instrumentation.aspnetcore Things related to OpenTelemetry.Instrumentation.AspNetCore label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working comp:instrumentation.aspnetcore Things related to OpenTelemetry.Instrumentation.AspNetCore
Projects
None yet
Development

No branches or pull requests

3 participants