将 Application Insights 数据与自定义数据源相关联Correlating Application Insights data with custom data sources

Application Insights 收集多种不同的数据类型:异常、跟踪、页面视图等。Application Insights collects several different data types: exceptions, traces, page views, and others. 虽然通常情况下这对调查应用程序的性能、可靠性和使用情况来说已足够,但有时候,将存储在 Application Insights 中的数据与其他完全自定义的数据集相关联会很有用。While this is often sufficient to investigate your application’s performance, reliability, and usage, there are cases when it is useful to correlate the data stored in Application Insights to other completely custom datasets.

下述情况可能需要自定义数据:Some situations where you might want custom data include:

  • 数据扩充或查找表:例如,在提供服务器名称的同时,补充提供服务器的所有者以及服务器所在的实验室位置Data enrichment or lookup tables: for example, supplement a server name with the owner of the server and the lab location in which it can be found
  • 与非 Application Insights 数据源相关联:例如,将网店购买数据与购买履行服务的信息相关联,确定寄送时间估算的准确度如何Correlation with non-Application Insights data sources: for example, correlate data about a purchase on a web-store with information from your purchase-fulfillment service to determine how accurate your shipping time estimates were
  • 完全自定义数据:我们的许多客户喜欢支持 Application Insights 的 Azure Monitor 日志平台的查询语言和性能,希望使用它来查询与 Application Insights 根本不相关的数据。Completely custom data: many of our customers love the query language and performance of the Azure Monitor log platform that backs Application Insights, and want to use it to query data that is not at all related to Application Insights. 例如,在进行智能家居安装的过程中根据此处所述跟踪太阳能板的性能。For example, to track the solar panel performance as part of a smart home installation as outlined here.

如何将自定义数据与 Application Insights 数据相关联How to correlate custom data with Application Insights data

由于 Application Insights 由强大的 Azure Monitor 日志平台提供支持,因此我们可以充分利用 Azure Monitor 来引入数据。Since Application Insights is backed by the powerful Azure Monitor log platform, we are able to use the full power of Azure Monitor to ingest the data. 然后,我们会使用“join”运算符来编写查询,将此自定义数据与 Azure Monitor 日志中提供的数据相关联。Then, we will write queries using the “join” operator that will correlate this custom data with the data available to us in Azure Monitor logs.

引入数据Ingesting data

在此部分,我们会讨论如何将数据引入 Azure Monitor 日志中。In this section, we will review how to get your data into Azure Monitor logs.

如果还没有 Log Analytics 工作区,请预配一个新的,只需根据这些说明操作并包括“创建工作区”步骤即可。If you don’t already have one, provision a new Log Analytics workspace by following these instructions through and including the “create a workspace” step.

开始将日志数据发送到 Azure Monitor。To start sending log data into Azure Monitor. 存在多个选项:Several options exist:

  • 对于同步机制,可以直接调用数据收集器 API,也可以使用逻辑应用连接器 - 只需查找“Azure Log Analytics”并选取“发送数据”选项即可:For a synchronous mechanism, you can either directly call the data collector API or use our Logic App connector – simply look for “Azure Log Analytics” and pick the “Send Data” option:

    “选择操作”的屏幕截图

  • 对于异步选项,请使用数据收集器 API 来生成处理管道。For an asynchronous option, use the Data Collector API to build a processing pipeline. 有关详细信息,请参阅此文See this article for details.

关联数据Correlating data

Application Insights 基于 Azure Monitor 日志平台。Application Insights is based on the Azure Monitor log platform. 因此,我们可以使用跨资源联接将已引入到 Azure Monitor 中的任何数据与 Application Insights 数据相关联。We can therefore use cross-resource joins to correlate any data we ingested into Azure Monitor with our Application Insights data.

例如,可以将实验室库存和位置引入名为“myLA”的 Log Analytics 工作区的名为“LabLocations_CL”的表中。For example, we can ingest our lab inventory and locations into a table called “LabLocations_CL” in a Log Analytics workspace called “myLA”. 然后,如果我们需要查看在名为“myAI”的 Application Insights 应用中跟踪的请求,并将处理请求的计算机名称与存储在前述自定义表中的这些计算机的位置相关联,则可在 Application Insights 或 Azure Monitor 上下文中运行以下查询:If we then wanted to review our requests tracked in Application Insights app called “myAI” and correlate the machine names that served the requests to the locations of these machines stored in the previously mentioned custom table, we can run the following query from either the Application Insights or Azure Monitor context:

app('myAI').requests
| join kind= leftouter (
    workspace('myLA').LabLocations_CL
    | project Computer_S, Owner_S, Lab_S
) on $left.cloud_RoleInstance == $right.Computer

后续步骤Next Steps