在Application Insights Log Analytics中加入PageViews和Request

时间:2018-05-11 19:32:49

标签: azure-application-insights azure-log-analytics

我想将来自AppInsights浏览器SDK的pageView加入到后端的请求中。我没有看到有意义的外键,是否有一个OOTB?或者我需要编写一些东西来加入它们吗?

要添加上下文,我对cloudRoleInstance(服务器)的pageView持续时间感兴趣,但cloudRoleInstance仅在请求时可用。

我尝试了以下,并没有工作,我supose操作ID是不一样的。

pageViews
| join (requests) on operation_Id

2 个答案:

答案 0 :(得分:0)

您可以按操作ID(operation_Id)加入。

以下是返回特定operation_Id的所有文档的查询:

union *
| where timestamp > ago(1d)
| where operation_Id == "<operation_id>"

enter image description here

答案 1 :(得分:0)

我对同一件事很感兴趣,这就是我最终解决它的方式:

  1. 为服务器的每个响应设置一个“ cloud_RoleInstance” cookie,以便客户端Javascript知道哪个角色实例发送了最后一个响应。
  2. 将TelemetryInitializer添加到客户端Application Insights实例,该实例提取RoleInstance cookie并将其作为数据添加到收集的遥测客户端。

*之所以这样做的原因,而不是像另一个答案所说的那样加入operationId的原因是,因为operationId似乎跨越了服务器上的许多请求,有时甚至是半个小时。也许是因为我们的单页应用程序的设置方式,但是operationId不适用于我。


代码

BaseController.cs :: BeginExecute (我们有自己的BaseController,所有其他控制器都继承自此)

var roleInstanceCookie = requestContext.HttpContext.Response.Cookies.Get("cloud_RoleInstance");
roleInstanceCookie.Value = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.CurrentRoleInstance.Id;
requestContext.HttpContext.Response.Cookies.Set(roleInstanceCookie);

ApplicationInsights.js (其中包含我们的AI代码段,该代码段当前正在使用JS SDK的2.3.1版加载AI)

// ... initialization snippet ...
appInsights.addTelemetryInitializer((envelope) => {
    envelope.data.cloud_RoleInstance = getCookie("cloud_RoleInstance");
});

然后cloud_RoleInstance将出现在Application Insights中的PageViews的customDimensions列中

enter image description here

相关问题