c# - 在 Azure 函数中将事件作为参数传递时,TelemetryClient.StartOperation 始终失败

标签 c# .net azure azure-functions azure-application-insights

我有一个使用 BlobTrigger 的简单 Azure 函数,并且希望使用 Application Insights SDK 来处理自定义遥测。

    [FunctionName("Create-Thumbnail")]
    [StorageAccount("AzureWebJobsStorage")]
    public static void CreateThumbnail([BlobTrigger("input/{name}")] Stream image,
        [Blob("output/{name}", FileAccess.Write)] Stream imageSmall,
        ILogger log)
    {
        var requestActivity = new Activity("Create-Thumbnail");
        requestActivity.SetParentId("SOME PARENT ID");

        var newConfig = TelemetryConfiguration.CreateDefault();
        TelemetryClient telemetryClient = new TelemetryClient(newConfig);
        var requestOperation = telemetryClient.StartOperation<RequestTelemetry>(requestActivity);
        
        ...

        telemetryClient.StopOperation(requestOperation);

    }

但是,这总是失败并出现以下错误:

Method not found: 'Microsoft.ApplicationInsights.Extensibility.IOperationHolder`1<!!0> Microsoft.ApplicationInsights.TelemetryClientExtensions.StartOperation(Microsoft.ApplicationInsights.TelemetryClient, System.Diagnostics.Activity)'.

根据此 GitHub 问题:https://github.com/Azure/azure-functions-core-tools/issues/2399 ,可以通过恢复到2.14.0来解决。不过,我已经尝试了 2.8.1 之前的所有版本。它们都不起作用。

传递字符串而不是 Activity 确实有效。

var requestOperation = telemetryClient.StartOperation<RequestTelemetry>("Create-Thumbnail");

但我需要传递 Activity 来配置更多上下文。

有谁知道可能是什么问题吗?

最佳答案

根据我的搜索,我发现 this document它说

There is a Functions-specific version of the Application Insights SDK that you can use to send custom telemetry data from your functions to Application Insights: Microsoft.Azure.WebJobs.Logging.ApplicationInsights

所以我按照示例代码进行了测试,但是这个包的最新稳定版本(3.0.27)会返回与你相同的错误,但是当我更改为v3.0.25时,错误消失了。

关于c# - 在 Azure 函数中将事件作为参数传递时,TelemetryClient.StartOperation 始终失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68060827/

相关文章:

azure - CosmosDB ReadOnly Keys 引发授权错误

azure - Azure 门户上的 "Reset publish profile"按钮有什么作用?

c# - 枚举的值(value)

用于查找竞争条件/死锁的 C#/.NET 分析工具

c# - CancellationTokenSource或AutoResetEvent

.net - 设计长期运行、资源密集型 Web 服务的建议

java - NServiceBus 和 Java 集成

c# - 这个的正则表达式是什么?

c# - 如何从图像中获取前 5 种最常用的 RGB 颜色?

python - Azure Devops Rest API 授权 header 不起作用