opentelemetry-dotnet-contrib icon indicating copy to clipboard operation
opentelemetry-dotnet-contrib copied to clipboard

Support for Enrich when using WithMetrics

Open zulander1 opened this issue 1 year ago • 2 comments

Component

OpenTelemetry.Instrumentation.AspNetCore

Is your feature request related to a problem?

No response

What is the expected behavior?

When using AddAspNetCoreInstrumentation, there is no way to add Enrich using WithMetrics (as described here). It would be nice to have the possibility to update the activity so we can change the route according. My issue is that I am using version control and all the metrics are send out as "/api/v{version:apiVersion}" for the route name

 builder.Services.AddOpenTelemetry().WithMetrics(opts => opts

    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("A"))
    .AddAspNetCoreInstrumentation()
    .AddRuntimeInstrumentation()
    .AddPrometheusExporter()
  );

Updating the activity would allow us to change the route name from GET /api/v{version:apiVersion}/ to GET /api/v1/ I am using NET 8 with minimal API

Which alternative solutions or features have you considered?

Update the route automatically as describe there here

Additional context

No response

zulander1 avatar Nov 18 '24 04:11 zulander1

Maybe https://learn.microsoft.com/en-us/aspnet/core/log-mon/metrics/metrics?view=aspnetcore-8.0#enrich-the-aspnet-core-request-metric can solve your problem.

splitt3r avatar Dec 01 '24 10:12 splitt3r

@splitt3r it is not possible to modify the built-in http.route

zulander1 avatar Dec 12 '24 23:12 zulander1