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

Minimal API trace missing http.route tag #4192

Closed
andreasuvoss opened this issue Feb 15, 2023 · 1 comment
Closed

Minimal API trace missing http.route tag #4192

andreasuvoss opened this issue Feb 15, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@andreasuvoss
Copy link

andreasuvoss commented Feb 15, 2023

Bug Report

Packages used:

  • OpenTelemetry.Exporter.Console 1.4.0-rc.4
  • OpenTelemetry.Extensions.Hosting 1.4.0-rc.4
  • OpenTelemetry.Instrumentation.AspNetCore 1.0.0-rc9.13

Runtime versions:

  • net6.0
  • net7.0

Symptom

The resulting trace from calling an endpoint mapped using Minimal Api does not contain the http.route tag, however the tag is present when calling an endpoint defined in a classic controller.

What is the expected behavior?

The trace contains the tag http.route for endpoints created with the Minimal API syntax.

Activity.Tags:
    ....
    http.route: works/{id:int}
    ....

What is the actual behavior?

The trace does not contain the http.route tag for endpoints created with the Minimal API syntax.

Reproduce

With the code below call endpoint /does-not-work/1234 and observe that http.route is not present among the tags in the console output. Do the same for /works/1234 and observe that the http.route tag is present among the tags in the console output.

using Microsoft.AspNetCore.Mvc;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();

builder.Services.AddOpenTelemetry().WithTracing(b =>
{
    var resourceBuilder = ResourceBuilder.CreateDefault()
        .AddService("MinimalExample", null, "0.0.1");
    b.SetResourceBuilder(resourceBuilder)
        .AddAspNetCoreInstrumentation()
        .AddConsoleExporter();
});

var app = builder.Build();

app.MapControllers();

app.MapGet("/does-not-work/{id:int}", (int id) => "Trace without http.route");

app.Run();

[ApiController]
public class TestController : ControllerBase
{
    [HttpGet]
    [Route("/works/{id:int}")]
    public IActionResult GetTest(int id)
    {
        return Ok();
    }
}
<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.4.0-rc.4" />
      <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.4.0-rc.4" />
      <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.13" />
    </ItemGroup>
</Project>

Additional Context

I have looked a bit into the source of OpenTelemetry.Instrumentation.AspNetCore and it seems like the OnMvcBeforeActionEvent never occurs when calling the endpoint created with Minimap API syntax. All other expected tags seem to be present.

The issue seems to be the same with both net6.0 and net7.0.

@andreasuvoss andreasuvoss added the bug Something isn't working label Feb 15, 2023
@vishweshbankwar
Copy link
Member

Thanks for reporting. The issue is already being tracked with #3461. Closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants