首页 文章

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

提问于
浏览
3

我创建了一个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}"); 这个日志 . 但是,自定义事件和指标不会记录到应用程序洞察 . 什么想法可能会发生什么?

1 回答

  • 3

    回答你的明确问题:

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

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

    Event found through query

    Metric found through query

    回答你的隐含问题:

    如何使用Application Insights?

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

    • 遥测发送之间存在滞后,您可以在应用洞察门户中看到它 . 实时监控将是一个昂贵的工具 .

    • 过去我遇到了同样的问题,问题是在遥测名称中找不到事件/度量标准名称,但在某处详细说明 . This问题,可能是指它 . 所以我们决定做的是提供更多细节并使用this方法和MetricTelemetry类 .

    • 虽然Application Insights可能看起来令人困惑,但这是一个强大的工具,值得花时间学习更好 .

相关问题