Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.47k stars 4.8k forks source link

[BUG] AzureMonitorExporter shows unexpected operation name #41650

Open TimothyMothra opened 9 months ago

TimothyMothra commented 9 months ago

Library name and version

Azure.Monitor.OpenTelemetry.Exporter

Describe the bug

The Name and Operation Name are inconsistent depending on type of routing, configuration, and net framework.

This is in part due to the data provided by the OpenTelemetry.Instrumentation.AspNetCore library, where the configured pattern is used as the value of http.route. This is a known issue in that library: https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1730

Expected behavior

The operation name should be reported as GET /{Controller}/{Action}/{id}

Actual behavior

Instead the operation name will contain the pattern with the default route GET {controller=Home}/{action=Index}/{id?} Or will display the actual URL GET /Customer/Get/001

Reproduction Steps

This can be reproduced in an MVC app configured like this:

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

When using Asp.Net Core Routing rules, our Exporter is currently recording the full pattern as the Operation Name. This means that requests to different Controllers or Actions will show identical Operation Names, as shown in this screenshot.

Screenshot 2024-01-25 115910

My test app has a HomeController and CustomerController. Regardless which controller is invoked, The url.path shows the correct Controller/Action. The http.route shows the configured pattern.

Environment

No response

TimothyMothra commented 9 months ago

We determined that the fix needs to come from .NET & the OpenTelemetry Instrumentation library. Our team is tracking this item and we'll work with the other teams to get this resolved.