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

Update to Microsoft.Azure.Functions.Worker.Core version 1.18 breaks Open Telemetry Tracing for .net8 isolated function #2543

Closed
frozenskys opened this issue Jun 19, 2024 · 3 comments · Fixed by #2608
Assignees
Labels
potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug

Comments

@frozenskys
Copy link

Description

We are using the standard OpenTelemetry instrumentation (using the code below) to add tracing to our Azure functions and send these to an Otel collector. This works fine for Worker.Core versions <= 1.17 but updating to any package that has a dependency on Worker.Core >= 1.18 means that we no longer see traces appearing.

Worker.Core 1.17
Worker Core_v1 17

Worker.Core 1.18
Worker Core_v1 18

Steps to reproduce

Create a new .NET8 Isolated HTTP Trigger azure function (make sure it's using Microsoft.Azure.Functions.Worker.Core version <=1.17 i.e. Microsoft.Azure.Functions.Worker meta package version <=1.21)

Add the opentelemetry packages

    <PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
    <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
    <PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />

Add opentelemetry in the program.cs using code similar to below

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.AddOpenTelemetry().WithTracing(tracing =>
        {
            tracing.ConfigureResource(resource => resource.AddService("FunctionAppWithTelemetry"))
                .AddSource("FunctionAppWithTelemetry")
                .AddConsoleExporter();
        });
    })
    .Build();

host.Run();

Add an Activity to the function1.cs

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using System.Diagnostics;

namespace FunctionAppWithTelemetry;

public class Function1
{
    private readonly ILogger<Function1> _logger;
    private ActivitySource _activitySource;

    public Function1(ILogger<Function1> logger)
    {
        _logger = logger;
        _activitySource = new ActivitySource("FunctionAppWithTelemetry");
    }

    [Function("Function1")]
    public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
    {
        using var activity = _activitySource.StartActivity("FunctionAppWithTelemetry.Run");
        return new OkObjectResult("Welcome to Azure Functions!");
    }
}

If you run and make a get call to the function you will see console output of a trace span.
Upgrading the Microsoft.Azure.Functions.Worker to version 1.22 and re-running you will not see any console output from telemetry

@frozenskys frozenskys added the potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug label Jun 19, 2024
@RohitRanjanMS RohitRanjanMS self-assigned this Jun 20, 2024
frozenskys added a commit to frozenskys/Morris.Azure.Functions.OpenTelemetry that referenced this issue Jul 25, 2024
Add Cron and Servicebus Trigger Handlers, Fix some issues with the Http Trigger Handler, and downgrade the azure function packages as there's an issue with current versions around the Opentelemetry context (see Azure/azure-functions-dotnet-worker#2543)
@frozenskys
Copy link
Author

@RohitRanjanMS This issue still seems to be present in the latest version (1.19.0) of Microsoft.Azure.Functions.Worker.Core

@RohitRanjanMS
Copy link
Member

Hi @frozenskys , did you try with trace flag 01?

@frozenskys
Copy link
Author

@RohitRanjanMS So testing further this seems to work if I supply a valid traceparent HTTP header on the call to the function, however my reading of the W3C spec (https://www.w3.org/TR/trace-context/#no-traceparent-received) says I'd expect that if I didn't supply a traceparent that a span should be generated anyway with new trace-id and parent-id values, which doesn't seem to happen in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential-bug Items opened using the bug report template, not yet triaged and confirmed as a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants