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

Telemetry - use the request path for name of trace #2667

Open
steverash opened this issue Nov 28, 2024 · 6 comments
Open

Telemetry - use the request path for name of trace #2667

steverash opened this issue Nov 28, 2024 · 6 comments
Labels
help wanted We will welcome a contribution Type: Documentation Improvements or additions to documentation
Milestone

Comments

@steverash
Copy link

What should we add or change to make your life better?

When using Yarp and OpenTelemetry with the Aspire dashboard, all requests show in the dashboard with the route match path as the display name. This means that you have to drill into each one to find the request you are looking for. It would be better if they showed the original request path.

Example

Image

Why is this important to you?

A change will enable a more useful experience when viewing telemetry.

@steverash steverash added the Type: Idea This issue is a high-level idea for discussion. label Nov 28, 2024
@MihaZupan
Copy link
Member

@samsp-msft does this look like the intended experience here?
cc: @antonfirsov

@davidfowl
Copy link
Contributor

cc @JamesNK

@JamesNK
Copy link
Member

JamesNK commented Dec 11, 2024

A trace shows the matched route so it's working as intended. But that doesn't create a good experience in this situation.

YARP could improve this by getting the request activity and change the name to the request path. You can use the IHttpActivityFeature which is available from the HttpContext. The feature will be set and an activity available if tracing is enabled.

@MihaZupan
Copy link
Member

But presumably we wouldn't want to do so in YARP for all the same reasons we aren't doing it in ASP.NET to begin with?
Though it is currently more likely to be a worse experience in YARP since the route is often a broad catch-all.

@MihaZupan
Copy link
Member

I don't think changing the default to the full path would be the right answer, there's potentially an infinite amount of different paths that could match a route.
It would be useful if we had a snippet in the docs showing how one can customize this though, e.g. to use route IDs or path instead.
Here: https://microsoft.github.io/reverse-proxy/articles/distributed-tracing.html

Presumably it should be as simple as this (untested)

app.Use((context, next) =>
{
    if (context.Features.Get<IHttpActivityFeature>()?.Activity is { } activity)
    {
        activity.DisplayName = $"{context.Request.Method} {context.GetReverseProxyFeature().Route.Config.RouteId} {context.Request.Path}";
    }

    return next();
});

@MihaZupan MihaZupan added Type: Documentation Improvements or additions to documentation and removed Type: Idea This issue is a high-level idea for discussion. labels Jan 14, 2025
@MihaZupan MihaZupan added this to the Backlog milestone Jan 14, 2025
@MihaZupan MihaZupan added the help wanted We will welcome a contribution label Jan 14, 2025
@steverash
Copy link
Author

I've given the suggestion above a try. I added the app.Use directly before the app.Run call.

However setting the DisplayName seems to have no effect on the dashboard activity name.

To prove whether it was having any effect - I added a tag alongside the setting of the DisplayName - which does seem to come through.

So this code

app.Use((context, next) =>
{
    if (context.Features.Get<IHttpActivityFeature>()?.Activity is { } activity)
    {
        activity.DisplayName = $"{context.Request.Method} {context.Request.Path}";
        activity.AddTag("display.name", $"{context.Request.Method} {context.Request.Path}");
    }
    return next();
});

Gives this in the dashboard
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We will welcome a contribution Type: Documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants