Application Insights-计算具有相同操作Id的两个事件之间的时间跨度



Application Insights的跟踪部分中有很多事件。我对两件事感兴趣"开始";以及";结束";,它们各自具有与登录集相同的操作Id。有时;结束";事件将不存在,因为我们正在监视的应用程序将出现问题。

为了便于论证,我们可以说我们对以下字段感兴趣:timestamp、eventName、operationId

如何计算时间跨度中所有唯一操作Id的事件对的两个时间戳之间的确切时间?

我最初的想法是从跟踪中获得不同的operationId,其中eventName是";正在开始";。。。但这是我所能做到的,因为我真的不确定如何执行所需的其余操作。(即-计算,并检查"结束"事件是否存在(。

let operations =
traces
| where customDimensions.eventName = "Beginning"
| distinct operationId

如有任何帮助,我们将不胜感激!

编辑:我显然是想错了。我追求的是非唯一操作ID。这将过滤掉缺失的";结束";事件。如果我可以根据这个id将结果合并在一起,那么我将有2个时间戳,我可以对其进行操作

所以,我喝了一些咖啡,花了一些时间思考后才明白。

最终得到:

let a =
traces
| summarize count() by operation_Id;
let b = 
a
| where count_ == 2
| project operation_Id;
let c = 
traces
| where operation_Id in (b)
| join kind = inner(traces) on operation_Id
| order by timestamp,timestamp1
| project evaluatedTime=(timestamp1 - timestamp), operation_Id, timestamp;
c
| where evaluatedTime > timespan(0)
| project seconds=evaluatedTime/time(1s), operation_Id, timestamp

最新更新