首页 > 解决方案 > Application Insights - 查询集合

问题描述

我正在使用 Serilog 将数据跟踪到 Application Insights。

在自定义属性中,serilog 将故障集合记录为自定义数据,如下所示...

faults.Count 2
faults.0 "SomeFault" 
faults.1 "AnotherFault"

如何使用 Application Insights Analytics 查询语言查询这些属性?

我想报告包含"AnotherFault"不知道索引的任何响应。

标签: azure-application-insights

解决方案


它可以很简单:

search in (CustomEvents) "AnotherFault"

或者,您可以将搜索限制为仅自定义维度:

CustomEvents
| where timestamp > ago(24h)
| where tostring(customDimensions) contains "AnotherFault"

由于字符串包含比较,两者都将对大型数据集产生性能影响,因此了解索引或名称或属性肯定会在这里有所帮助。

另一种方法是执行| mvexpand每个自定义维度并将其展开到自己的行中:

CustomEvents
| where timstamp > ago(24h)
| project customDimensions, usefulField1, usefulField2,....
| mvexpand bagexpansion=array customDimensions
| where customDimensions[1] == "AnotherFault"

通过将其转换为数组,您可以通过通用 [1] 而不是通过知道其名称来访问自定义维度的值,因此您可以在不使用“faults.#”语法的情况下与“AnotherFault”进行完整比较。mvexpand诀窍是在减少内存倍增之前减少您希望看到的字段数量。


推荐阅读