我已经创建了服务总线触发的 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 。我部署了该函数并得到了以下结果:
回答你隐含的问题:
如何使用 Application Insights?
一开始使用App Insights查询语言很棘手,我发现this简洁的文件很有帮助。使用此监控工具时需要考虑的其他要素:
- 发送遥测数据与您在应用程序洞察门户中看到它之间存在延迟。实时监控将是一个昂贵的工具。
- 过去我遇到过同样的问题,问题是在遥测名称中找不到事件/指标名称,而是在详细信息中的某处找到。 This问题,可能会提到它。所以我们决定做的是提供更多详细信息和 this 的使用方法和MetricTelemetry类。
- 虽然 Application Insights 可能看起来令人困惑,但它是一个强大的工具,值得投入时间来更好地学习。
关于c# - Azure 函数不会将自定义事件记录到应用程序洞察中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52104140/