You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用KQL从Azure Application Insights的customDimensions列提取嵌套数组属性并生成指定格式输出?

如何在KQL中展开customDimensions内的Error List数组并关联外层属性?

针对你这个需求,我们可以通过KQL的几个核心函数组合来实现,以下是完整的查询语句,我会一步步给你解释每个部分的作用,方便新手理解:

exceptions
| project customDimensions
// 解析并提取外层的固定属性,同时把字符串格式的Error List转成动态数组
| extend 
  "File Name" = customDimensions["File Name"],
  "Correlation ID" = customDimensions["Correlation ID"],
  ErrorList = parse_json(customDimensions["Error List"])
// 把ErrorList数组拆成单独的行,同时保留外层属性
| mv-expand ErrorList
// 从展开的每个Error对象中提取Function Name和Code
| extend 
  "Function Name" = ErrorList["Function Name"],
  Code = ErrorList["Code"]
// 筛选出需要的列,和你期望的输出列名保持一致
| project "File Name", "Correlation ID", "Function Name", Code

关键步骤说明:

  • parse_json():因为customDimensions里的Error List是字符串形式的JSON数组,KQL默认识别不了,所以用这个函数把它转换成动态(dynamic)类型,这样后续才能对数组进行操作。
  • mv-expand:这是实现“数组拆分行”的核心函数,它会把数组中的每个元素单独生成一行,同时自动保留当前行的其他属性(也就是File Name和Correlation ID),完美实现你要的“每个错误条目关联外层属性”的需求。
  • extend:用来从JSON对象中提取指定键的值,不管是外层的customDimensions还是展开后的ErrorList对象,都可以通过["键名"]的方式获取对应的值。

运行这个查询后,就能得到和你期望完全一致的结构化表格输出了。

内容的提问来源于stack exchange,提问作者Sid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 22:22:34