Application Insights 提取嵌套的 CustomDimensions

Application Insights Extract Nested CustomDimensions

我在 Application Insights Analytics 中有一些数据具有动态对象作为自定义维度的 属性。例如:

|        timestamp        |  name   | customDimensions                 | etc |
|-------------------------|---------|----------------------------------|-----|
| 2017-09-11T19:56:20.000 | Spinner | {                                | ... |
                                         MyCustomDimension: "hi"
                                         Properties:
                                             context: "ABC"
                                             userMessage: "Some other"
                                      }

这有意义吗?所以在 customDimensions.

里面有一个 key/value 对

我正在尝试使 context 属性 成为结果中的适当列。所以预期会是:

|        timestamp        |  name   | customDimensions                 | context| etc |
|-------------------------|---------|----------------------------------|--------|-----|
| 2017-09-11T19:56:20.000 | Spinner | {                                | ABC    | ...
                                         MyCustomDimension: "hi"
                                         Properties:
                                             context: "ABC"
                                             userMessage: "Some other"
                                      }

我试过这个:

customEvents | where name == "Spinner" | extend Context = customDimensions.Properties["context"]

还有这个:

customEvents | where name == "Spinner"  | extend Context = customDimensions.Properties.context

但似乎都不起作用。他们在末尾给了我一个名为 "Context" 的列,但该列是空的 - 没有值。

有什么想法吗?

编辑:

添加图片以阐明数据格式:

已编辑为有效答案

customEvents
 | where name == "Spinner"
 | extend Properties = todynamic(tostring(customDimensions.Properties))
 | extend Context = Properties.context

你需要额外的 tostringtodynamic 才能得到你期望的(以及 i 期望的!)

我得到的解释:

Dynamic field "promises" you the upper/outer level of key / value access (this is how you access customDimensions.Properties).

Accessing internal structure of that json depends on the exact format of customDimensions.Properties content. It doesn’t have to be json by itself. Even if it looks like a well structured json, it still may be just a string that is not exactly well formatted json.

所以基本上,默认情况下它不会尝试解析 dynamic/json 块内的字符串,因为它们不想花费大量时间尝试将嵌套内容转换为 json无限。

我仍然认为 extra tostring 不应该在那里被要求,因为 todynamic 应该已经有效地允许字符串和动态,所以我正在检查拥有查询内容的团队是否可以使这一步变得更好。

非常感谢..只是为了扩展约翰的回答。我们需要使用自定义事件来绘制端点的持续时间。这个查询成功了,所以我们可以将持续时间指定为图表中的 Y 轴:

customEvents
 | extend Properties = todynamic(tostring(customDimensions.Properties))
 | extend duration = todouble(todecimal(Properties.duration))
 | project timestamp, name, duration