Search code examples
.netazure-functionsnewrelicopen-telemetry

Azure function .net 7, open telemetry - traces not exporting to new relic


We have a .net 7 azure function app (code example below) and we want to get telemetry information out of it. I have successfully got logging and metrics exporting to new relic. But no trace informtion is avaliable (in new relic there are no span's). looking at the console output there is trace information but no open telemetry entries to send it to new relic,however there is for logging and metrics.

all configuration has been done in the program.cs and within the function1.cs is a httptrigger which attempted to access the trace contex, and do some logging etc.

to call the function:

http://localhost:7256/api/Function1

Demo Project Source Code

To get it running:

Rename the local.settings.json.example to local.settings.json and add a new relic api key to this key: Telemetry:Otlp:Headers

Observations:

Within the Function1.cs on the http trigger when calling Activity.Current its null, I was expecting it to be populated and it to have a TraceId.


Solution

  • Glancing at your code, things look correct. However, the telemetry you automatically get depends on whether your Azure Function is hosted in-process or in an isolated process.

    services.AddOpenTelemetry()
        .WithTracing(builder =>
        {
            builder
    
                // When an Azure Function is hosted in-process
                // this instrumentation will be invoked and create
                // a root span. This is only true for Http Triggers, I believe.
                //
                // When hosted in an isolated process this instrumentation
                // will not do anything. You must manually instrument your
                // function.
                .AddAspNetCoreInstrumentation()
        });
    

    See my comment on this GitHub issue for a suggestion on how to manually instrument your function in case you are running it in an isolated process.