Skip to content

ASP.NET http.route appears to be incorrect when exception handlers are invoked #5556

@tyler-boyd

Description

@tyler-boyd

Bug Report

List of all OpenTelemetry NuGet
packages
and version that you are
using (e.g. OpenTelemetry 1.0.2):

  • OpenTelemetry 1.7.0
  • OpenTelemetry.Instrumentation.AspNetCore 1.7.0

Runtime version (e.g. net462, net48, netcoreapp3.1, net6.0 etc. You can
find this information from the *.csproj file):

  • net8

Symptom

A clear and concise description of what the bug is.

What is the expected behavior?

http.route should always be populated, regardless of if the route handler threw an exception or not.

What is the actual behavior?

http.route is only populated when there's no exception; the tag is null when an exception occurs.

Reproduce

In lieu of a reproduction repo, I can point to the likely cause, which is a discrepancy between how the metrics instrumentation handles http.route compared to the tracing instrumentation.

  • Metrics:
    // Check the exception handler feature first in case the endpoint was overwritten
    var route = (context.Features.Get<IExceptionHandlerPathFeature>()?.Endpoint as RouteEndpoint ??
    context.GetEndpoint() as RouteEndpoint)?.RoutePattern.RawText;
    if (!string.IsNullOrEmpty(route))
    {
    tags.Add(new KeyValuePair<string, object>(SemanticConventions.AttributeHttpRoute, route));
    }
    , note that it checks context.Features.Get<IExceptionHandlerPathFeature>()?.Endpoint first, falling back to context.GetEndpoint()
  • Tracing:
    var routePattern = (context.Features.Get<IExceptionHandlerPathFeature>()?.Endpoint as RouteEndpoint ??
    context.GetEndpoint() as RouteEndpoint)?.RoutePattern.RawText;
    if (!string.IsNullOrEmpty(routePattern))
    {
    RequestMethodHelper.SetActivityDisplayName(activity, context.Request.Method, routePattern);
    activity.SetTag(SemanticConventions.AttributeHttpRoute, routePattern);
    }
    , note it only checks context.GetEndpoint()

I'd assume the metrics way is correct, but am not positive 🤷‍♂️

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions