Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
432 stars 184 forks source link

Tracing is broken when AspNetCore integration is used #2875

Open lmolkova opened 3 days ago

lmolkova commented 3 days ago

Description

I configure ASP.NET Core integration along with OTel in the following way

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(s => s.AddOpenTelemetry()
        .WithTracing(t => t
                .AddSource("testme")
                .AddAspNetCoreInstrumentation()
                .AddHttpClientInstrumentation())
    .UseFunctionsWorkerDefaults()
    .UseOtlpExporter())
    .Build();

and enable host telemetry with

"telemetryMode": "openTelemetry"

In my function code I create another activity

[Function("Function1")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
    using var act = test.StartActivity("THIS IS A TEST");
    _logger.LogInformation("C# HTTP trigger function processed a request.");

    var response = req.CreateResponse(HttpStatusCode.OK);
    response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

    await response.WriteStringAsync("Welcome to Azure Functions!");

    return response;
}

What I get:

Image

I.e.

What I expect

Steps to reproduce

Related to https://github.com/Azure/azure-functions-dotnet-worker/issues/2733

jviau commented 2 days ago

Are you using AspNetCore integration here?

lmolkova commented 2 days ago

Yes, it's configured in ConfigureFunctionsWebApplication()

jviau commented 2 days ago

This is a known issue we are working on for AspNetCore integration. We have AspNetCore and Functions pipelines both creating their own activity to track this work and those two pipelines are disjointed, causing the correlation issue.

lmolkova commented 2 days ago

Awesome, feel free to close if it's a duplicate