应用程序见解提取嵌套的CustomDimensions

Sea*_*ish 14 azure-application-insights ms-app-analytics

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

|        timestamp        |  name   | customDimensions                 | etc |
|-------------------------|---------|----------------------------------|-----|
| 2017-09-11T19:56:20.000 | Spinner | {                                | ... |
                                         MyCustomDimension: "hi"
                                         Properties:
                                             context: "ABC"
                                             userMessage: "Some other"
                                      }
Run Code Online (Sandbox Code Playgroud)

那有意义吗?所以customDimensions中的键/值对.

我试图将该context属性调出为结果中的适当列.所以预期会是:

|        timestamp        |  name   | customDimensions                 | context| etc |
|-------------------------|---------|----------------------------------|--------|-----|
| 2017-09-11T19:56:20.000 | Spinner | {                                | ABC    | ...
                                         MyCustomDimension: "hi"
                                         Properties:
                                             context: "ABC"
                                             userMessage: "Some other"
                                      }
Run Code Online (Sandbox Code Playgroud)

我试过这个:

customEvents | where name == "Spinner" | extend Context = customDimensions.Properties["context"]
Run Code Online (Sandbox Code Playgroud)

还有这个:

customEvents | where name == "Spinner"  | extend Context = customDimensions.Properties.context
Run Code Online (Sandbox Code Playgroud)

但似乎都不起作用.他们给我一个名为"Context"的列,但列是空的 - 没有值.

有任何想法吗?

编辑:

添加了用于说明数据格式的图片:

应用洞察数据

Joh*_*ner 18

编辑到工作回答:

customEvents
 | where name == "Spinner"
 | extend Properties = todynamic(tostring(customDimensions.Properties))
 | extend Context = Properties.context
Run Code Online (Sandbox Code Playgroud)

你需要一个额外的,tostringtodynamic在这里得到你期望的(和期望的!)

给出的解释是:

动态字段"承诺"您键/值访问的上/外级别(这是您访问customDimensions.Properties的方式).

访问该json的内部结构取决于customDimensions.Properties内容的确切格式.它本身不一定是json.即使它看起来像一个结构良好的json,它仍然可能只是一个不完全格式化json的字符串.

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

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


Ric*_*yle 5

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

customEvents
 | extend Properties = todynamic(tostring(customDimensions.Properties))
 | extend duration = todouble(todecimal(Properties.duration))
 | project timestamp, name, duration
Run Code Online (Sandbox Code Playgroud)