Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity.Current is null in Azure function with BlobTrigger

I have an Azure function(V3) that uses BlobTrigger binding and written in C#.

In order to add custom properties in Application Insights RequestTelemetry for it using

        Activity.Current?.AddTag("TraceId", traceId);

I need to access the Activity.Current based on the suggestion from this Stackoverflow answer. However, it didn't work due to Activity.Current is NULL.

My package configuration looks like as follow:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Storage.Blobs" Version="12.9.0" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.14.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.0-beta.2" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.14" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.8" />
    <PackageReference Include="SixLabors.ImageSharp" Version="1.0.3" />
    <PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.1" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

And my function looks like as follow:

        [FunctionName("Create-Thumbnail")]
        public async Task CreateThumbnail([BlobTrigger("input/{name}",  Source = BlobTriggerSource.EventGrid, Connection = "AzureWebJobsStorage")] Stream image,
            IDictionary<string,string> metadata,
            string name,
            ILogger log,
            ExecutionContext context)
        {         
            Activity.Current?.AddTag("TraceId", traceId);
        }

I have been doing research for whole day but failed to find any solution. Does anyone know what could be the issue?

like image 566
codigube Avatar asked Oct 20 '25 13:10

codigube


1 Answers

Currently it can be working in HTTP Trigger Functions that were ending up in the Custom Properties of Requests in application insights are no longer. Refer here

The same Activity.Current value is null issue available in github Azure Function host & Application Insights

The Application Insights .NET SDK uses DiagnosticSource (DiagnosticSourceUsersGuide) and Activity (ActivityUserGuide) steps to collect and correlate telemetry.

Please open an issue in the Functions repo link here.

like image 154
Delliganesh Sevanesan Avatar answered Oct 23 '25 02:10

Delliganesh Sevanesan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!