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

HTTP OPTIONS request , transaction name(display name) is shown as request path instead of HTTP route ( template ) in asp.net core api app #2967

Closed
madhub opened this issue Mar 3, 2022 · 2 comments · Fixed by #5026
Labels
bug Something isn't working

Comments

@madhub
Copy link

madhub commented Mar 3, 2022

Bug Report

HTTP OPTIONS request, transaction name(display name) is shown as request path instead of HTTP route ( template ) in asp.net core api app

Expected transaction name(display name) : Todo/{tenantid}/{version}
What is shown is : /todo/456-123-56abc-x134/2022-02-01

It seems to happen for HTTP OPTIONS request ,like browser HTTP OPTIONS pre-flight request to check the CORS.

List of all OpenTelemetry NuGet

packages](https://www.nuget.org/profiles/OpenTelemetry) and version that you are
using (e.g. OpenTelemetry 1.0.2):

ASP.NET Core 3.1 , Windows 10
Zipkin & Console exporter is configured

OTel version

  • OpenTelemetry.Exporter.Zipkin1.1.0
  • OpenTelemetry.Instrumentation.AspNetCore 1.0.0-rc7
  • OpenTelemetry.Extensions.Hosting 1.0.0-rc7
  • System.Diagnostics.DiagnosticSource 5.0.1

Runtime version :

ASP.NET Core 3.1 , Windows 10

Symptom

For HTTP OPTIONS request, transaction name(display name) is shown as request path instead of HTTP route ( template ) in asp.net core api app

What is the expected behavior?

Expected transaction name (display name): Todo/{tenantid}/{version}

What is the actual behavior?

What is shown is : /todo/456-123-56abc-x134/2022-02-01

Reproduce

Any ASP.NET Core 3.1 API app with above packages & send HTTP OPTIONS request ,like browser HTTP OPTIONS pre-flight request to check the CORS.
POST request

curl -v -X POST http://localhost:5000/todo/456-123-56abc-x134/2022-02-01 -d {}

OPTIONS request

curl -v -X OPTIONS http://localhost:5000/todo/456-123-56abc-x134/2022-02-01 -H "Access-Control-Request-Method: POST"   -H "Access-Control-Request-Headers: content-type"   -H "Origin: https://reqbin.com" -d {}

C# Sample

 // curl -v -X OPTIONS http://localhost:5000/todo/456-123-56abc-x134/2022-02-01 -H "Access-Control-Request-Method: POST"   -H "Access-Control-Request-Headers: content-type"   -H "Origin: https://reqbin.com" -d {}
    // curl -v -X POST http://localhost:5000/todo/456-123-56abc-x134/2022-02-01 -d {}
    [Route("[controller]")]
    [ApiController]
    public class TodoController : ControllerBase
    {
        static HttpClient httpClient = new HttpClient();
        private readonly ActivitySource activitySource;
        private readonly ILogger<TodoController> _logger;
        public TodoController(ILogger<TodoController> logger,ActivitySource activitySource)
        {
            this.activitySource = activitySource;
            this._logger = logger;
        }
        [HttpPost]
        [Route("{tenantid}/{version}")]
        public IActionResult Create(string tenantid, string version)
        {
            Console.WriteLine($"{nameof(tenantid)}={tenantid},{nameof(version)}={version}");
            using (activitySource.StartActivity("Calling external Service"))
            {
                _logger.LogInformation("TodoController:Get Calling external service");
                InvokeExternalService();
            }
            return Ok();
        }

        public void InvokeExternalService()
        {

            try
            {
                httpClient.GetStringAsync("http://www.google.com").GetAwaiter().GetResult();
            }
            catch (Exception exp)
            {
                // Console.WriteLine(exp);
                throw;
            }
        }
    }

We will close this issue if:

  • The repro project you share with us is complex. We can't investigate custom
    projects, so don't point us to such, please.
  • If we can not reproduce the behavior you're reporting.

Additional Context

image

image

Add any other context about the problem here.

@marcindruzgala
Copy link

We have api versioning for our endpoints which .net supports so for example: [Route("api/v{apiVersion:apiVersion}/[controller]")] which is being reported as api/v{apiVersion:apiVersion}/users which is not really what we would like to achieve...

In that case it would be actually nice to see api/v1/users as a transaction name

@dhabierre
Copy link

Other thread: #4525

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

Successfully merging a pull request may close this issue.

5 participants