c# - Azure 函数不会将自定义事件记录到应用程序洞察中

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

我已经创建了服务总线触发的 Azure 函数,并希望在应用程序洞察中记录自定义事件。

 private static string key = TelemetryConfiguration.Active.InstrumentationKey =
            System.Environment.GetEnvironmentVariable(
                "APPINSIGHTS_INSTRUMENTATIONKEY", EnvironmentVariableTarget.Process);

        private static TelemetryClient telemetryClient =
            new TelemetryClient() { InstrumentationKey = key };

        [FunctionName("Function1")]
        public static void Run([ServiceBusTrigger("xxxxx", "xxxxx", AccessRights.Manage, Connection = "SBConnectionKey")]string mySbMsg, ILogger logger, TraceWriter log)
        {
            log.Info($"C# ServiceBus topic trigger function processed message: {mySbMsg}");

            telemetryClient.Context.Cloud.RoleName = "AIFunction";
            logger.LogMetric("test", 123);

            telemetryClient.TrackEvent("Ack123 Recieved");
            telemetryClient.TrackMetric("Test Metric", DateTime.Now.Millisecond);
       }

我只能看到 log.Info($"C# ServiceBus 主题触发函数处理的消息:{mySbMsg}");此日志记录在跟踪中。但自定义事件和指标不会记录到应用程序洞察中。 有什么想法会发生什么吗?

最佳答案

回答您的明确问题:

我发送的遥测数据有什么问题,或者在 Application Insights 门户中的何处可以找到它?

我用几乎相同的代码创建了该函数并进行了测试。您可以分析repo 。我部署了该函数并得到了以下结果:

Event found through query

Metric found through query

回答你隐含的问题:

如何使用 Application Insights?

一开始使用App Insights查询语言很棘手,我发现this简洁的文件很有帮助。使用此监控工具时需要考虑的其他要素:

  1. 发送遥测数据与您在应用程序洞察门户中看到它之间存在延迟。实时监控将是一个昂贵的工具。
  2. 过去我遇到过同样的问题,问题是在遥测名称中找不到事件/指标名称,而是在详细信息中的某处找到。 This问题,可能会提到它。所以我们决定做的是提供更多详细信息和 this 的使用方法和MetricTelemetry类。
  3. 虽然 Application Insights 可能看起来令人困惑,但它是一个强大的工具,值得投入时间来更好地学习。

关于c# - Azure 函数不会将自定义事件记录到应用程序洞察中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52104140/

相关文章:

azure - Spark 可以写入 Azure Datalake Gen2 吗?

azure - "The page cannot be displayed because an internal server error has occurred",Azure 网站,

javascript - Promise Pending 不会解决或拒绝

azure - 通过 PowerShell 创建的 IotHub 设备不显示

azure - Terraform 从托管磁盘镜像创建虚拟机

azure - Azure Function 服务总线输出绑定(bind)错误

c# - 如何使用谷歌翻译 API 翻译单词?

c# - 如何使用 Open XML SDK(XLSX) 在 Excel 中创建数据透视表

c# - 在c#中的任意起始索引上初始化数组

c# - Cron Scheduler 每天午夜 12 点