Skip to content

Activity.Current null in Azure Function when using the latest version of System.Diagnostics.DiagnosticSource #7278

Closed
@johannesoenema

Description

@johannesoenema

When using Activity.Current to add custom tags to request telemetry, we encounter the problem that Activity.Current is null. We have currently not a way to add custom telemetry to request. The following code will not work with the latest version of System.Diagnostics.DiagnosticSource:

[FunctionName(nameof(Function1))]
public static void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer)
{
    Activity.Current.AddTag("Test", "Test");
}

Information

  • TargetFramework: 3.1
  • Microsoft.NET.Sdk.Functions 3.0.11
  • System.Diagnostics.DiagnosticSource 4.7.1

Repro steps

We use EFCore.BulkExtensions which has a dependency on version 4.7.1 of System.Diagnostics.DiagnosticSource and because of that Activity.Current isn't working anymore. See repro here: https://github.com/johannesoenema/ActivityIssue

Also very weird, Activity.Current is null according to the code, but in the debug window it isn't null...
image

Expected behavior

Activity.Current is not null.

Actual behavior

Activity.Current is null.

Known workarounds

Downgrading to version 4.6 of System.Diagnostics.DiagnosticSource:

<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0">
   <NoWarn>NU1605</NoWarn>
</PackageReference>

Of course we prefer to use latest version of packages.

Related information

This issue is already described in another issue #5014. Because it is a separate issue from the original issue, I open a new one as suggested.

@brettsam suggested that this change (removing System.Diagnostics.DiagnosticSource from the unification) could be related: #4941

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions