带有BlobTrigger的Azure函数中的Activity.Current为空 [英] Activity.Current is null in Azure function with BlobTrigger

查看:50
本文介绍了带有BlobTrigger的Azure函数中的Activity.Current为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Azure函数(V3),它使用BlobTrigger绑定并用C#编写。

要在Application Insights中为其添加自定义属性,请使用

        Activity.Current?.AddTag("TraceId", traceId);
我需要根据Stackoverflow answer中的建议访问Activity.Current。但是,由于Activity.Current is NULL无法正常工作。

我的包配置如下:

<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>

我的函数如下:

        [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);
        }

我研究了一整天,但没有找到任何解决方案。有人知道可能是什么问题吗?

推荐答案

多亏了这一点GitHub issue,我在将系统诊断源代码降级到版本4.6后才设法使其正常工作

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

这篇关于带有BlobTrigger的Azure函数中的Activity.Current为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆