从处理多个应用程序洞察实例的 Azure Monitor 工作簿获取异常详细信息

Get exception details from Azure Monitor Workbook that deals with multiple app insight instances

我正在努力创建一个工作簿,该工作簿提供对多个应用洞察实例的综合视图。我们的解决方案有许多微服务(Azure 函数),每个微服务都有自己的应用洞察实例。本工作簿的目的是通过在单个视图中显示跨应用洞察实例的错误,为整个应用提供健康状态。

我已经使用“故障分析”模板进行了设置。用户可以在顶部 select 不同的应用程序洞察实例,视图将基于此进行过滤。有一个视图显示异常计数与这样的趋势。每个错误可能属于不同的 App Insight 实例。

当您点击一个行项目时,该错误的所有实例都将显示在如下视图中,如下所示

我使用下面的查询来加载它

let row = dynamic({Row});
let req = requests
| where '{Row}' == '{}' or (row.Kind == 'Application' and row.Id 
    == appName) or (row.Kind == 'Request' and row.Id ==    
    strcat(appName, "::", name))
| where success == "False";

 let errors = exceptions
 | where appName == appName 
 | where timestamp between({TimeRange:start}..{TimeRange:end});

 errors
 | join req on operation_Id
 | project operation_Id, itemId, timestamp,requestName=name, 
        exception=type, method, outerMessage, innermostMessage, 
        details, appName

如本 中所述,itemId 可用,我尝试将其 link 到“异常详细信息”视图。请注意,这些错误可能来自许多 App Insight 实例之一,具体取决于在上一个视图中 selected 的内容。

我使用 Link 渲染器和自动渲染器配置了项目 ID 和 appName 列,如下所示。

然而,link 始终指向一个特定的应用程序洞察实例(不是与错误关联的实例),因此不会加载错误。是否可以使用这种技术跨 App Insight 实例加载“详细视图”?如果不是,还有什么其他途径?

看起来 快速阅读代码,如果您itemId 所在的行,它将尝试在查询中使用的资源列表中查找具有相同名称的资源,如果没有,则只取它能找到的第一个?

但我看到你那里有 appName,但我不确定你步骤中的其余配置?您是否还使用了查询中的所有资源?

当应用程序见解为 workspace based 时,每个遥测项目都有一个字段 _ResourceId,其中包含 link 资源,例如

/subscriptions/c8vfbeab-a5a67-4272-aa6e-4c9f4142e962/resourcegroups/rg-my-resource-group/providers/microsoft.insights/components/my-ai-resource

您可以使用 url 的这一部分创建一个深度 link 到具有指定项目 ID 的遥测的 Application Insights 资源的详细信息页面。以此查询为例:

exceptions
| take 1
| extend portalUrl = strcat("https://portal.azure.com/#blade/AppInsightsExtension/BladeRedirect/BladeName/searchV1/ResourceId/", url_encode(_ResourceId), "/BladeInputs/%7B%22tables%22%3A%5B%22availabilityResults%22%2C%22requests%22%2C%22exceptions%22%2C%22pageViews%22%2C%22traces%22%2C%22customEvents%22%2C%22dependencies%22%5D%2C%22timeContextWhereClause%22%3A%22%7C%20where%20timestamp%20%3E%20datetime(%5C%222022-02-12T12%3A55%3A02.739Z%5C%22)%20and%20timestamp%20%3C%20datetime(%5C%222022-03-14T12%3A55%3A02.739Z%5C%22)%22%2C%22filterWhereClause%22%3A%22%7C%20where%20*%20has%20%5C%22a1a20ad1a12ff348a852288a4d9953a5%5C%22%7C%20order%20by%20timestamp%20desc%22%2C%22originalParams%22%3A%7B%22eventTypes%22%3A%5B%7B%22value%22%3A%22availabilityResult%22%2C%22tableName%22%3A%22availabilityResults%22%2C%22label%22%3A%22Availability%22%7D%2C%7B%22value%22%3A%22request%22%2C%22tableName%22%3A%22requests%22%2C%22label%22%3A%22Request%22%7D%2C%7B%22value%22%3A%22exception%22%2C%22tableName%22%3A%22exceptions%22%2C%22label%22%3A%22Exception%22%7D%2C%7B%22value%22%3A%22pageView%22%2C%22tableName%22%3A%22pageViews%22%2C%22label%22%3A%22Page%20View%22%7D%2C%7B%22value%22%3A%22trace%22%2C%22tableName%22%3A%22traces%22%2C%22label%22%3A%22Trace%22%7D%2C%7B%22value%22%3A%22customEvent%22%2C%22tableName%22%3A%22customEvents%22%2C%22label%22%3A%22Custom%20Event%22%7D%2C%7B%22value%22%3A%22dependency%22%2C%22tableName%22%3A%22dependencies%22%2C%22label%22%3A%22Dependency%22%7D%5D%2C%22timeContext%22%3A%7B%22durationMs%22%3A2592000000%7D%2C%22filter%22%3A%5B%5D%2C%22searchPhrase%22%3A%7B%22originalPhrase%22%3A%22", itemId,"%22%2C%22_tokens%22%3A%5B%7B%22conjunction%22%3A%22and%22%2C%22value%22%3A%22a1a20ad1a12ff348a852288a4d9953a5%22%2C%22isNot%22%3Afalse%2C%22kql%22%3A%22%20*%20has%20%5C%22a1a20ad1a12ff348a852288a4d9953a5%5C%22%22%7D%5D%7D%2C%22sort%22%3A%22desc%22%7D%7D")
| project timestamp,  problemId, itemId, portalUrl

如果您创建工作簿并根据上面的查询呈现 table,则必须将 itemId 列修改为 link,如下所示:

单击 itemId 列应该会打开正确的 Application Insights 资源详细信息页面:

现在,我希望这能为您提供足够的线索,通过在您的查询输出中包含深度 link url 来扩展您自己的查询。

为了完整起见,这是完整的工作簿图库模板:

{
  "version": "Notebook/1.0",
  "items": [
    {
      "type": 3,
      "content": {
        "version": "KqlItem/1.0",
        "query": "exceptions\n| take 1\n| extend portalUrl = strcat(\"https://portal.azure.com/#blade/AppInsightsExtension/BladeRedirect/BladeName/searchV1/ResourceId/\", url_encode(_ResourceId), \"/BladeInputs/%7B%22tables%22%3A%5B%22availabilityResults%22%2C%22requests%22%2C%22exceptions%22%2C%22pageViews%22%2C%22traces%22%2C%22customEvents%22%2C%22dependencies%22%5D%2C%22timeContextWhereClause%22%3A%22%7C%20where%20timestamp%20%3E%20datetime(%5C%222022-02-12T12%3A55%3A02.739Z%5C%22)%20and%20timestamp%20%3C%20datetime(%5C%222022-03-14T12%3A55%3A02.739Z%5C%22)%22%2C%22filterWhereClause%22%3A%22%7C%20where%20*%20has%20%5C%22a1a20ad1a12ff348a852288a4d9953a5%5C%22%7C%20order%20by%20timestamp%20desc%22%2C%22originalParams%22%3A%7B%22eventTypes%22%3A%5B%7B%22value%22%3A%22availabilityResult%22%2C%22tableName%22%3A%22availabilityResults%22%2C%22label%22%3A%22Availability%22%7D%2C%7B%22value%22%3A%22request%22%2C%22tableName%22%3A%22requests%22%2C%22label%22%3A%22Request%22%7D%2C%7B%22value%22%3A%22exception%22%2C%22tableName%22%3A%22exceptions%22%2C%22label%22%3A%22Exception%22%7D%2C%7B%22value%22%3A%22pageView%22%2C%22tableName%22%3A%22pageViews%22%2C%22label%22%3A%22Page%20View%22%7D%2C%7B%22value%22%3A%22trace%22%2C%22tableName%22%3A%22traces%22%2C%22label%22%3A%22Trace%22%7D%2C%7B%22value%22%3A%22customEvent%22%2C%22tableName%22%3A%22customEvents%22%2C%22label%22%3A%22Custom%20Event%22%7D%2C%7B%22value%22%3A%22dependency%22%2C%22tableName%22%3A%22dependencies%22%2C%22label%22%3A%22Dependency%22%7D%5D%2C%22timeContext%22%3A%7B%22durationMs%22%3A2592000000%7D%2C%22filter%22%3A%5B%5D%2C%22searchPhrase%22%3A%7B%22originalPhrase%22%3A%22\", itemId,\"%22%2C%22_tokens%22%3A%5B%7B%22conjunction%22%3A%22and%22%2C%22value%22%3A%22a1a20ad1a12ff348a852288a4d9953a5%22%2C%22isNot%22%3Afalse%2C%22kql%22%3A%22%20*%20has%20%5C%22a1a20ad1a12ff348a852288a4d9953a5%5C%22%22%7D%5D%7D%2C%22sort%22%3A%22desc%22%7D%7D\")\n| project timestamp,  problemId, itemId, portalUrl",
        "size": 1,
        "timeContext": {
          "durationMs": 86400000
        },
        "queryType": 0,
        "resourceType": "microsoft.insights/components",
        "gridSettings": {
          "formatters": [
            {
              "columnMatch": "problemId",
              "formatter": 1,
              "formatOptions": {
                "linkColumn": "portalUrl",
                "linkTarget": "Url"
              }
            }
          ]
        }
      },
      "name": "query - 2"
    }
  ],
  "fallbackResourceIds": [
    "/subscriptions/4547474-1a67-4272-aa6e-4c9f4142e269/resourceGroups/rg-resourcegroup-prod/providers/microsoft.insights/components/appi-demo-prod"
  ],
  "$schema": "https://github.com/Microsoft/Application-Insights-Workbooks/blob/master/schema/workbook.json"
}