.Net8 in-proc hosts creates an Activity without a source name
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
-
Create a new HTTP Trigger function (in-proc) running on net6
-
Add OpenTelemetry configuration
builder.Services.AddOpenTelemetry().WithTracing(tracerProviderBuilder =>
{
tracerProviderBuilder
.SetResourceBuilder(appResourceBuilder)
.SetSampler<AlwaysOnSampler>()
.AddSource("ServiceName")
.AddOtlpExporter();
});
-
Add a breakpoint after function dispatch, add watch on
Activty.Current=> should be null -
Repeat above steps with net8. Should see something similar to the below
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.
Hi @JessicaA-Auror thanks for update this is occurring exactly on which net 6 or net 6. will check and update.Thanks
@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
I will go ahead and remove the empty activity.
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.