我创建了一个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日志。但是,自定义事件和指标不会记录到应用程序洞察。什么想法可能会发生什么?
回答你的明确问题:
我发送的遥测或在Application Insights Portal中找到它的地方有什么问题?
我用几乎相同的代码创建了函数并进行了测试。你可以分析repo。我部署了该功能并得到了以下结果:
回答你的隐含问题:
如何使用Application Insights?
一开始使用App Insights查询语言很棘手,我发现this简洁文件很有帮助。使用此监视工具时需要考虑的其他因素: