azure-functions-host icon indicating copy to clipboard operation
azure-functions-host copied to clipboard

.Net8 in-proc hosts creates an Activity without a source name

Open JessicaA-Auror opened this issue 1 year ago • 4 comments

When upgrading an http triggered in-proc function to net8, the host runtime is now creating a new Activity without a Source Name. This is a change in behaviour that breaks telemetry. This changes otel by adding a new parent activity. Additionally the activity cannot be subscribe to due to not having a source name. When exporting otel, this looks like an empty root span.

A similar issue looks to have be recently fixed in isolated function see here: https://github.com/Azure/azure-functions-dotnet-worker/issues/2733

Repro steps

  1. Create a new HTTP Trigger function (in-proc) running on net6

  2. Add OpenTelemetry configuration

  builder.Services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>
          {
              tracerProviderBuilder
                  .SetResourceBuilder(appResourceBuilder)
                  .SetSampler<AlwaysOnSampler>()
                  .AddSource("ServiceName")
                  .AddOtlpExporter();
          });
  1. Add a breakpoint after function dispatch, add watch on Activty.Current => should be null

  2. Repeat above steps with net8. Should see something similar to the below

Image

Expected Behaviour

Expected behaviour is not having the host create a current activity. If host is required to create activities then a source name is required to be able to subscribe to it. This results in missing spans in our otel telemetry after export.

Known workarounds

We've temporarily patched this by setting Activty.Current to null before starting a root activity.

JessicaA-Auror avatar Oct 24 '24 21:10 JessicaA-Auror

Hi @JessicaA-Auror thanks for update this is occurring exactly on which net 6 or net 6. will check and update.Thanks

bhagyshricompany avatar Oct 29 '24 08:10 bhagyshricompany

@JessicaA-Auror I don't think this is functions specific. I believe this is a BCL change between .net6 and .net8. You are specifically seeing an operation from AspNetCore. Have you tried using OTels AspNetCore instrumentation package? I believe they do some work to shim this: https://www.nuget.org/packages/OpenTelemetry.Instrumentation.AspNetCore

jviau avatar Oct 30 '24 21:10 jviau

I will go ahead and remove the empty activity.

RohitRanjanMS avatar Apr 25 '25 05:04 RohitRanjanMS

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

If you are not the original author (@JessicaA-Auror) and believe this issue is not stale, please comment with /bot not-stale and I will not close it.