Azure功能未将自定义事件记录到应用程序洞察中

问题描述 投票:3回答:1

我创建了一个Service Bus触发的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 topic trigger function processed message: {mySbMsg}");this日志。但是,自定义事件和指标不会记录到应用程序洞察。什么想法可能会发生什么?

c# azure azure-functions azure-application-insights
1个回答
3
投票

回答你的明确问题:

我发送的遥测或在Application Insights Portal中找到它的地方有什么问题?

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

Event found through query

Metric found through query

回答你的隐含问题:

如何使用Application Insights?

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

  1. 遥测发送之间存在滞后,您可以在应用洞察门户中看到它。实时监控将是一个昂贵的工具。
  2. 在过去,我遇到了同样的问题,问题是在遥测的名称中找不到事件/度量标准名称,但在某处详细说明。 This问题,可能是指它。所以我们决定做的是更多细节和使用this方法和MetricTelemetry类。
  3. 虽然Application Insights可能看起来令人困惑,但这是一个强大的工具,值得花时间学习更好。
© www.soinside.com 2019 - 2024. All rights reserved.