应用程序映射:会审分布式应用程序Application Map: Triage Distributed Applications

应用程序映射可帮助你发现的性能瓶颈或热点失败的所有组件的分布式应用程序。Application Map helps you spot performance bottlenecks or failure hotspots across all components of your distributed application. 在地图上的每个节点表示应用程序组件或其依赖项;并且有运行状况 KPI 和警报状态。Each node on the map represents an application component or its dependencies; and has health KPI and alerts status. 可从任何组件单击以获得更详细的诊断,如 Application Insights 事件。You can click through from any component to more detailed diagnostics, such as Application Insights events. 如果应用使用了 Azure 服务,还可以单击获得 Azure 诊断,如 SQL 数据库顾问建议。If your app uses Azure services, you can also click through to Azure diagnostics, such as SQL Database Advisor recommendations.

组件是什么?What is a Component?

组件是分布式/微服务应用程序的可独立部署的部件。Components are independently deployable parts of your distributed/microservices application. 开发者或操作团队具有代码级可见性,或有权访问由这些应用程序组件生成的遥测。Developers and operations teams have code-level visibility or access to telemetry generated by these application components.

  • 组件与“观察到的”外部依赖项(如 SQL 和 EventHub 等)不同,团队/组织可能无权访问(代码或遥测)。Components are different from "observed" external dependencies such as SQL, EventHub etc. which your team/organization may not have access to (code or telemetry).
  • 组件在任意数目的服务器/角色/容器实例上运行。Components run on any number of server/role/container instances.
  • 组件可以是单独的 Application Insights 检测密钥(即使订阅并不相同),或是向单个 Application Insights 检测密钥报告的不同角色。Components can be separate Application Insights instrumentation keys (even if subscriptions are different) or different roles reporting to a single Application Insights instrumentation key. 预览地图体验显示了组件而不考虑如何设置它们。The preview map experience shows the components regardless of how they are set up.

复合应用程序映射Composite Application Map

你可以跨多个级别的相关应用程序组件中查看完整的应用程序拓扑。You can see the full application topology across multiple levels of related application components. 组件可以是不同的 Application Insights 资源或不同的角色在单个资源。Components could be different Application Insights resources, or different roles in a single resource. 应用映射通过跟踪已安装 Application Insights SDK 的服务器之间进行的任何 HTTP 依赖项调用来查找服务器节点。The app map finds components by following HTTP dependency calls made between servers with the Application Insights SDK installed.

这种体验开头渐进式发现的组件。This experience starts with progressive discovery of the components. 首次加载应用程序映射时,会触发一组查询来发现与此组件相关的组件。When you first load the application map, a set of queries is triggered to discover the components related to this component. 在左上角的按钮将使用更新你的应用程序中的组件数量发现它们。A button at the top-left corner will update with the number of components in your application as they are discovered.

单击"更新映射组件",发现在该点之前的所有组件刷新映射。On clicking "Update map components", the map is refreshed with all components discovered until that point. 这可能要花费一段时间来进行加载,具体取决于应用程序的复杂性。Depending on the complexity of your application, this may take a minute to load.

如果所有组件都是单个的 Application Insights 资源中的角色,则不需要此发现步骤。If all of the components are roles within a single Application Insights resource, then this discovery step is not required. 这样的应用程序的初始负载将具有所有组件。The initial load for such an application will have all its components.

应用程序映射屏幕截图

使用此体验的主要目标之一是能够实现可视化效果具有数百个组件的复杂拓扑。One of the key objectives with this experience is to be able to visualize complex topologies with hundreds of components.

单击以查看相关的见解,转到的性能和失败的该组件的会审体验的任何组件。Click on any component to see related insights and go to the performance and failure triage experience for that component.

浮出控件

调查故障Investigate failures

选择“调查故障” 以启动故障窗格。Select investigate failures to launch the failures pane.

“调查故障”按钮的屏幕截图

故障体验的屏幕截图

调查性能Investigate performance

若要排查性能问题,请选择“调查性能” 。To troubleshoot performance problems, select investigate performance.

“调查性能”按钮的屏幕截图

性能体验的屏幕截图

转到详细信息Go to details

选择“转到详细信息”可探索端到端事务体验,从而可以深入到调用堆栈级别的信息。 Select go to details to explore the end-to-end transaction experience, which can offer views down to the call stack level.

“转到详细信息”按钮的屏幕截图

端到端事务详细信息的屏幕截图

查看日志(分析)View Logs (Analytics)

若要进一步查询和调查应用程序数据,请单击“在日志(分析)中查看”。 To query and investigate your applications data further, click view in Logs (Analytics).

“在 Analytics 中查看”按钮的屏幕截图

分析体验的屏幕截图。

警报Alerts

若要查看活动警报和导致警报触发的基础规则,请选择“警报”。 To view active alerts and the underlying rules that cause the alerts to be triggered, select alerts.

“警报”按钮的屏幕截图

分析体验的屏幕截图

设置云角色名称Set cloud role name

应用程序映射使用云角色名称属性来标识映射上的组件。Application Map uses the cloud role name property to identify the components on the map. Application Insights SDK 会自动将云角色名称属性添加到组件发出的遥测数据。The Application Insights SDK automatically adds the cloud role name property to the telemetry emitted by components. 例如,SDK 会将网站名称或服务角色名称添加到云角色名称属性。For example, the SDK will add a web site name or service role name to the cloud role name property. 但是,在某些情况下,你可能希望替代默认值。However, there are cases where you may want to override the default value. 若要替代云角色名称并更改要在应用程序映射上显示的内容,请如下所示进行操作:To override cloud role name and change what gets displayed on the Application Map:

.NET/.NET Core.NET/.NET Core

按如下所示编写自定义 TelemetryInitializer。Write custom TelemetryInitializer as below.

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;

namespace CustomInitializer.Telemetry
{
    public class MyTelemetryInitializer : ITelemetryInitializer
    {
        public void Initialize(ITelemetry telemetry)
        {
            if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleName))
            {
                //set custom role name here
                telemetry.Context.Cloud.RoleName = "Custom RoleName";
                telemetry.Context.Cloud.RoleInstance = "Custom RoleInstance";
            }
        }
    }
}

ASP.NET 应用:将初始值设定项加载到活动 TelemetryConfigurationASP.NET apps: Load initializer to the active TelemetryConfiguration

在 ApplicationInsights.config 中:In ApplicationInsights.config:

    <ApplicationInsights>
      <TelemetryInitializers>
        <!-- Fully qualified type name, assembly name: -->
        <Add Type="CustomInitializer.Telemetry.MyTelemetryInitializer, CustomInitializer"/>
        ...
      </TelemetryInitializers>
    </ApplicationInsights>

ASP.NET Web 应用程序的另一种方法是在代码中(例如在 Global.aspx.cs 中)实例化初始值设定项:An alternate method for ASP.NET Web apps is to instantiate the initializer in code, for example in Global.aspx.cs:

 using Microsoft.ApplicationInsights.Extensibility;
 using CustomInitializer.Telemetry;

    protected void Application_Start()
    {
        // ...
        TelemetryConfiguration.Active.TelemetryInitializers.Add(new MyTelemetryInitializer());
    }

备注

使用 ApplicationInsights.config 或使用 TelemetryConfiguration.Active 添加初始值设定项对于 ASP.NET Core 应用程序无效。Adding initializer using ApplicationInsights.config or using TelemetryConfiguration.Active is not valid for ASP.NET Core applications.

ASP.NET Core 应用:将初始值设定项加载到 TelemetryConfigurationASP.NET Core apps: Load initializer to the TelemetryConfiguration

对于 ASP.NET Core 应用程序,添加新的 TelemetryInitializer 是通过将其添加到依赖项注入容器来完成的,如下所示。For ASP.NET Core applications, adding a new TelemetryInitializer is done by adding it to the Dependency Injection container, as shown below. 这是在 Startup.cs 类的 ConfigureServices 方法中完成的。This is done in ConfigureServices method of your Startup.cs class.

 using Microsoft.ApplicationInsights.Extensibility;
 using CustomInitializer.Telemetry;
 public void ConfigureServices(IServiceCollection services)
{
    services.AddSingleton<ITelemetryInitializer, MyTelemetryInitializer>();
}

Node.jsNode.js

var appInsights = require("applicationinsights");
appInsights.setup('INSTRUMENTATION_KEY').start();
appInsights.defaultClient.context.tags["ai.cloud.role"] = "your role name";
appInsights.defaultClient.context.tags["ai.cloud.roleInstance"] = "your role instance";

Node.js 的替代方法Alternate method for Node.js

var appInsights = require("applicationinsights");
appInsights.setup('INSTRUMENTATION_KEY').start();

appInsights.defaultClient.addTelemetryProcessor(envelope => {
    envelope.tags["ai.cloud.role"] = "your role name";
    envelope.tags["ai.cloud.roleInstance"] = "your role instance"
});

JavaJava

从 Application Insights Java SDK 2.5.0 开始,可以通过将 <RoleName> 添加到 ApplicationInsights.xml 文件来指定云角色名称,例如Starting with Application Insights Java SDK 2.5.0, you can specify the cloud role name by adding <RoleName> to your ApplicationInsights.xml file, e.g.

<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" schemaVersion="2014-05-30">
   <InstrumentationKey>** Your instrumentation key **</InstrumentationKey>
   <RoleName>** Your role name **</RoleName>
   ...
</ApplicationInsights>

如果你通过 Application Insights Spring Boot 入门版使用 Spring Boot,则唯一需要执行的更改是在 application.properties 文件中为应用程序设置自定义名称。If you use Spring Boot with the Application Insights Spring Boot starter, the only required change is to set your custom name for the application in the application.properties file.

spring.application.name=<name-of-app>

Spring Boot 入门版会自动将云角色名称分配给你为 spring.application.name 属性输入的值。The Spring Boot starter will automatically assign cloud role name to the value you enter for the spring.application.name property.

客户端/浏览器端 JavaScriptClient/browser-side JavaScript

appInsights.queue.push(() => {
appInsights.addTelemetryInitializer((envelope) => {
  envelope.tags["ai.cloud.role"] = "your role name";
  envelope.tags["ai.cloud.roleInstance"] = "your role instance";
});
});

了解应用程序映射上下文中的云角色名称Understanding cloud role name within the context of the Application Map

以下包含多个云角色名称的应用程序映射可帮助你加深对云角色名称的理解:As far as how to think about cloud role name, it can be helpful to look at an Application Map that has multiple cloud role names present:

应用程序映射屏幕截图

在上面的应用程序映射中,绿框中的每个名称是云角色名称值,它们反映了此特定分布式应用程序的不同方面。In the Application Map above each of the names in green boxes are cloud role name values for different aspects of this particular distributed application. 因此,此应用的角色由 AuthenticationacmefrontendInventory ManagementPayment Processing Worker Role 组成。So for this app its roles consist of: Authentication, acmefrontend, Inventory Management, a Payment Processing Worker Role.

对于此应用,其中的每个云角色名称也代表具有自身检测密钥的唯一 Application Insights 资源。In the case of this app each of those cloud role names also represents a different unique Application Insights resource with their own instrumentation keys. 由于此应用程序的所有者有权访问这四个不同 Application Insights 资源中的每一个,因此,应用程序映射可将基础关系的映射拼接到一起。Since the owner of this application has access to each of those four disparate Application Insights resources, Application Map is able to stitch together a map of the underlying relationships.

   [Description("Name of the role the application is a part of. Maps directly to the role name in azure.")]
    [MaxStringLength("256")]
    705: string      CloudRole = "ai.cloud.role";
    
    [Description("Name of the instance where the application is running. Computer name for on-premises, instance name for Azure.")]
    [MaxStringLength("256")]
    715: string      CloudRoleInstance = "ai.cloud.roleInstance";

或者,云角色实例可帮助实现以下方案:尽管云角色名称会告知问题出现在 Web 前端中的某个位置,但你可能在多个负载均衡的服务器中运行 Web 前端,因此,能够通过 Kusto 查询下钻到更深的层并了解问题是影响所有 Web 前端服务器/实例还是只影响其中的一个服务器/实例可能极其重要。Alternatively, cloud role instance can be helpful for scenarios where cloud role name tells you the problem is somewhere in your web front-end, but you might be running your web front-end across multiple load-balanced servers so being able to drill in a layer deeper via Kusto queries and knowing if the issue is impacting all web front-end servers/instances or just one can be extremely important.

另一个方案是,应用在容器化环境中运行,仅仅了解单个服务器可能无法获得足够的信息来找出给定的问题,因此需要替代云角色实例的值。A scenario where you might want to override the value for cloud role instance could be if your app is running in a containerized environment where just knowing the individual server might not be enough information to locate a given issue.

有关如何使用遥测数据初始化表达式替代云角色名称属性的详细信息,请参阅添加属性:ITelemetryInitializerFor more information about how to override the cloud role name property with telemetry initializers, see Add properties: ITelemetryInitializer.

故障排除Troubleshooting

如果无法让应用程序映射按预期方式工作,请尝试以下步骤:If you're having trouble getting Application Map to work as expected, try these steps:

常规General

  1. 请确保你使用的是官方支持的 SDK。Make sure you're using an officially supported SDK. 不受支持的/社区 SDK 可能不支持关联。Unsupported/community SDKs might not support correlation.

    有关受支持的 SDK 的列表,请参考此文章Refer to this article for a list of supported SDKs.

  2. 将所有组件都升级到最新 SDK 版本。Upgrade all components to the latest SDK version.

  3. 如果将 Azure Functions 与 C# 一起使用,请升级到 Functions V2If you're using Azure Functions with C#, upgrade to Functions V2.

  4. 确认云角色名称已正确配置。Confirm cloud role name is correctly configured.

  5. 如果缺少某个依赖项,请确保它在自动收集的依赖项列表中。If you're missing a dependency, make sure it's in the list of auto-collected dependencies. 如果不在其中,也可以使用某个跟踪依赖项调用手动跟踪它。If not, you can still track it manually with a track dependency call.

映射中存在过多的节点Too many nodes on the map

应用程序映射为请求遥测中的每个唯一云角色名称构造一个应用程序节点,并为依赖项遥测中的类型、目标和云角色名称的每个唯一组合构造一个依赖项节点。Application Map constructs an application node for each unique cloud role name present in your request telemetry and a dependency node for each unique combination of type, target, and cloud role name in your dependency telemetry. 如果遥测中包含 10,000 个以上的节点,则应用程序映射无法提取所有的节点和链接,因此映射是不完整的。If there are more than 10,000 nodes in your telemetry, Application Map will not be able to fetch all the nodes and links, so your map will be incomplete. 如果发生这种情况,查看映射时会显示一条警告消息。If this happens, a warning message will appear when viewing the map.

此外,应用程序映射最多仅支持一次性呈现的 1000 个独立未分组节点。In addition, Application Map only supports up to 1000 separate ungrouped nodes rendered at once. 应用程序映射将具有相同类型和调用方的依赖项分组到一起,因此可降低了视觉复杂性。但是,如果遥测包含过多的唯一云角色名称或过多的依赖项类型,则这种分组并不足够,并且映射无法呈现。Application Map reduces visual complexity by grouping dependencies together that have the same type and callers, but if your telemetry has too many unique cloud role names or too many dependency types, that grouping will be insufficient, and the map will be unable to render.

若要解决此问题,需要更改检测,以正确设置云角色名称、依赖项类型和依赖项目标字段。To fix this, you'll need to change your instrumentation to properly set the cloud role name, dependency type, and dependency target fields.

  • 依赖项目标应代表依赖项的逻辑名称。Dependency target should represent the logical name of a dependency. 在许多情况下,它相当于依赖项的服务器或资源名称。In many cases, it’s equivalent to the server or resource name of the dependency. 例如,对于 HTTP 依赖项,其目标将设置为主机名。For example, in the case of HTTP dependencies it is set to the hostname. 依赖项目标不应包含会在不同的请求中发生变化的唯一 ID 或参数。It should not contain unique IDs or parameters that change from one request to another.

  • 依赖项类型应代表依赖项的逻辑类型。Dependency type should represent the logical type of a dependency. 例如,HTTP、 SQL 或 Azure Blob 就是典型的依赖项类型。For example, HTTP, SQL or Azure Blob are typical dependency types. 它不应包含唯一 ID。It should not contain unique IDs.

  • 上面的部分介绍了云角色名称的用途。The purpose of cloud role name is described in the above section.

门户反馈Portal feedback

若要提供反馈,请使用反馈选项。To provide feedback, use the feedback option.

MapLink-1 图

后续步骤Next steps