在 Application Insights 分析中,如何查询受特定异常影响的用户百分比?

In Application Insights analytics how to query what percent of users are impacted by specific exception?

我使用这个查询来显示异常:

exceptions
| where application_Version == "xyz"
| summarize count_=count(itemCount), impactedUsers=dcount(user_Id) by problemId, type, method, outerMessage, innermostMessage
| order by impactedUsers 

如何查询受特定异常影响的用户百分比?

我将通过此查询检查所有用户:

customEvents
| where application_Version == "xyz" 
| summarize dcount(user_Id) 

你几乎已经有了你所拥有的,你只需要将两者联系起来:

  1. 使用let + toscalar 将查询结果定义为数字
  2. 在你的查询中引用它(我使用 *1.0 强制它是一个浮点数,否则你得到 0,并使用 round 得到 2 位小数,根据需要调整它)

进行查询:

let totalUsers = toscalar(customEvents
 | where application_Version == "xyz" 
 | summarize dcount(user_Id));
 exceptions
 | where application_Version == "xyz"
 | summarize count_=count(itemCount), 
      impactedUsers=dcount(user_Id), 
      percent=round(dcount(user_Id)*1.0/totalUsers*100.0,2) 
   by problemId, type, method, outerMessage, innermostMessage
 | order by impactedUsers