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

Application Insights - Calculate timespan between two events that have the same operation Id?

我在 Application Insights 的跟踪部分中有很多事件。我对“开始”和“结束”这两个事件感兴趣,它们在登录时都具有相同的操作 ID。 有时“结束”事件不存在 - 因为我们正在监视的应用程序会出现问题。

我们可以说,为了论证我们有这些我们感兴趣的字段:timestamp、eventName、operationId

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

我最初的想法是从跟踪中获取不同的 operationIds,其中 eventName 是“Beginning”...但就我所知,因为我不确定如何执行其余操作必需的。 (即 - 计算,并检查“结束”事件是否存在)。

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

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

编辑:我显然在想这一切都是错误的。我所追求的是非唯一的 operationIds。这将过滤掉丢失的“结束”事件。 如果我可以基于该 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