监视 Azure 应用服务性能Monitor Azure App Service performance

现在,可以比过去更轻松地针对 Azure 应用服务中运行的基于 .NET 和.NET Core 的 Web 应用程序启用监视。Enabling monitoring on your .NET and .NET Core based web applications running on Azure App Services is now easier than ever. 以前需要手动安装某个站点扩展,而现在应用服务映像中默认会内置最新的扩展/代理。Whereas previously you needed to manually install a site extension, the latest extension/agent is now built into the app service image by default. 本文逐步讲解如何启用 Application Insights 监视,并提供有关如何自动完成大规模部署的初步指导。This article will walk you through enabling Application Insights monitoring as well as provide preliminary guidance for automating the process for large-scale deployments.

Note

通过“开发工具” > “扩展”手动添加 Application Insights 站点扩展的功能已弃用。 Manually adding an Application Insights site extension via Development Tools > Extensions is deprecated. 此扩展安装方法依赖于每个新版本的手动更新。This method of extension installation was dependent on manual updates for each new version. 扩展的最新稳定版现在会预装在应用服务映像中。The latest stable release of the extension is now preinstalled as part of the App Service image. 这些文件位于 d:\Program Files (x86)\SiteExtensions\ApplicationInsightsAgent 中,每发布一个稳定版本,它们都会自动更新。The files are located in d:\Program Files (x86)\SiteExtensions\ApplicationInsightsAgent and are automatically updated with each stable release. 如果在下文中遵循基于代理的说明启用监视,系统会自动删除已弃用的扩展。If you follow the agent based instructions to enable monitoring below, it will automatically remove the deprecated extension for you.

启用 Application InsightsEnable Application Insights

可通过两种方法为 Azure 应用服务托管的应用程序启用应用程序监视:There are two ways to enable application monitoring for Azure App Services hosted applications:

  • 基于代理的应用程序监视 (ApplicationInsightsAgent)。Agent-based application monitoring (ApplicationInsightsAgent).

    • 这是启用监视的最简单方法,无需完成任何高级配置。This method is the easiest to enable, and no advanced configuration is required. 这种监视通常称为“运行时”监视。It is often referred to as "runtime" monitoring. 对于 Azure 应用服务,我们建议至少启用此级别的监视,然后可根据具体的方案,评估是否需要通过手动检测来启用更高级的监视。For Azure App Services we recommend at a minimum enabling this level of monitoring, and then based on your specific scenario you can evaluate whether more advanced monitoring through manual instrumentation is needed.
  • 安装 Application Insights SDK 以通过代码手动检测应用程序Manually instrumenting the application through code by installing the Application Insights SDK.

Note

如果同时检测到了基于代理的监视和基于手动 SDK 的检测,则只会遵循手动检测设置,If both agent based monitoring and manual SDK based instrumentation is detected only the manual instrumentation settings will be honored. 目的是防止发送重复数据。This is to prevent duplicate data from sent. 有关详细信息,请查看下面的故障排除部分To learn more about this check out the troubleshooting section below.

启用基于代理的监视 (.NET)Enable agent-based monitoring .NET

Note

不支持 APPINSIGHTS_JAVASCRIPT_ENABLED 和 urlCompression 的组合。the combination of APPINSIGHTS_JAVASCRIPT_ENABLED and urlCompression is not supported. 有关详细信息,请参阅故障排除部分中的说明。For more info see the explanation in the troubleshooting section.

  1. 在应用服务的 Azure 控制面板中,选择“Application Insights”。 Select Application Insights in the Azure control panel for your app service.

    在“设置”下选择“Application Insights”

    • 除非已为此应用设置了 Application Insights 资源,否则请选择创建新资源。Choose to create a new resource, unless you already set up an Application Insights resource for this application.

      Note

      当单击“确定” 来创建新资源时,将提示你应用监视设置When you click OK to create the new resource you will be prompted to Apply monitoring settings. 选择“继续” 会将新的 Application Insights 资源链接到你的应用服务,这样做还会触发应用服务的重新启动Selecting Continue will link your new Application Insights resource to your app service, doing so will also trigger a restart of your app service.

      检测 Web 应用

  2. 指定要使用哪些资源后,可以选择 Application Insights 根据平台为应用程序收集数据的方式。After specifying which resource to use, you can choose how you want application insights to collect data per platform for your application. ASP.NET 应用监视默认已启用,它提供两种不同级别的集合。ASP.NET app monitoring is on-by-default with two different levels of collection.

    根据平台选择选项

    • .NET 基本集合 级别提供基本的单实例 APM 功能。.NET Basic collection level offers essential single-instance APM capabilities.

    • .NET 建议集合 级别:.NET Recommended collection level:

      • 添加 CPU、内存和 I/O 使用情况趋势。Adds CPU, memory, and I/O usage trends.
      • 跨请求/依赖关系边界关联微服务。Correlates micro-services across request/dependency boundaries.
      • 收集使用情况趋势,并启用从可用性结果到事务的关联。Collects usage trends, and enables correlation from availability results to transactions.
      • 收集未经主机进程处理的异常。Collects exceptions unhandled by the host process.
      • 提高使用采样时,负载下的 APM 指标准确性。Improves APM metrics accuracy under load, when sampling is used.
  3. 若要配置采样等设置(以前可以通过 applicationinsights.config 文件进行控制),现在可以通过应用程序设置使用相应的前缀来与这些设置交互。To configure settings like sampling, which you could previously control via the applicationinsights.config file you can now interact with those same settings via Application settings with a corresponding prefix.

    • 例如,若要更改初始采样百分比,可以创建名为 MicrosoftAppInsights_AdaptiveSamplingTelemetryProcessor_InitialSamplingPercentage、值为 100 的应用程序设置。For example, to change the initial sampling percentage, you can create an Application setting of: MicrosoftAppInsights_AdaptiveSamplingTelemetryProcessor_InitialSamplingPercentage and a value of 100.

    • 有关受支持自适应采样遥测处理器设置的列表,可以参阅代码相关的文档For the list of supported adaptive sampling telemetry processor settings, you can consult the code and associated documentation.

启用基于代理的监视 (.NET Core)Enable agent-based monitoring .NET Core

支持以下 .NET Core 版本:ASP.NET Core 2.0、ASP.NET Core 2.1、ASP.NET Core 2.2The following versions of .NET Core are supported: ASP.NET Core 2.0, ASP.NET Core 2.1, ASP.NET Core 2.2

基于代理/扩展的监视目前不支持面向 .NET Core 的完整框架、独立部署和 ASP.NET Core 3.0。Targeting the full framework from .NET Core, self-contained deployment, and ASP.NET Core 3.0 are currently not supported with agent/extension based monitoring. (在上述所有方案中,都可通过代码进行手动检测。)(Manual instrumentation via code will work in all of the previous scenarios.)

  1. 在应用服务的 Azure 控制面板中,选择“Application Insights”。 Select Application Insights in the Azure control panel for your app service.

    在“设置”下选择“Application Insights”

    • 除非已为此应用设置了 Application Insights 资源,否则请选择创建新资源。Choose to create a new resource, unless you already set up an Application Insights resource for this application.

      Note

      当单击“确定” 来创建新资源时,将提示你应用监视设置When you click OK to create the new resource you will be prompted to Apply monitoring settings. 选择“继续” 会将新的 Application Insights 资源链接到你的应用服务,这样做还会触发应用服务的重新启动Selecting Continue will link your new Application Insights resource to your app service, doing so will also trigger a restart of your app service.

      检测 Web 应用

  2. 指定要使用哪些资源后,可以选择 Application Insights 根据平台为应用程序收集数据的方式。After specifying which resource to use, you can choose how you want Application Insights to collect data per platform for your application. 对于 .NET Core 2.0、2.1 和 2.2,.NET Core 提供“建议的集合”或“已禁用”。 .NET Core offers Recommended collection or Disabled for .NET Core 2.0, 2.1, and 2.2.

    根据平台选择选项

启用客户端监视 (.NET)Enable client-side monitoring .NET

可以选择为 ASP.NET 启用客户端监视。Client-side monitoring is opt-in for ASP.NET. 若要启用客户端监视:To enable client-side monitoring:

  • 选择“设置”>“应用程序设置”。 Select Settings >** **Application settings****
    • 在“应用程序设置”下,添加新的应用设置名称Under Application settings, add a new app setting name and value:

      名称:APPINSIGHTS_JAVASCRIPT_ENABLEDName: APPINSIGHTS_JAVASCRIPT_ENABLED

      值:trueValue: true

    • 保存设置并重新启动应用。Save the settings and Restart your app.

应用程序设置 UI 的屏幕截图

若要禁用客户端监视,请从“应用程序设置”中删除关联的键值对,或将值设置为 false。To disable client-side monitoring either remove the associated key value pair from the Application settings, or set the value to false.

启用客户端监视 (.NET Core)Enable client-side monitoring .NET Core

对于使用“建议的集合”的 .NET Core 应用,默认已启用客户端监视,无论是否存在应用设置“APPINSIGHTS_JAVASCRIPT_ENABLED”。 Client-side monitoring is enabled by default for .NET Core apps with Recommended collection, regardless of whether the app setting 'APPINSIGHTS_JAVASCRIPT_ENABLED' is present.

如果出于某种原因想要禁用客户端监视:If for some reason you would like to disable client-side monitoring:

  • 选择“设置” > “应用程序设置”。 Select Settings > Application settings
    • 在“应用程序设置”下,添加新的应用设置名称Under Application settings, add a new app setting name and value:

      名称:APPINSIGHTS_JAVASCRIPT_ENABLEDname: APPINSIGHTS_JAVASCRIPT_ENABLED

      值:falseValue: false

    • 保存设置并重新启动应用。Save the settings and Restart your app.

应用程序设置 UI 的屏幕截图

自动监视Automate monitoring

若要在 Application Insights 中启用遥测数据收集,只需设置“应用程序设置”:In order to enable telemetry collection with Application Insights, only the Application settings need to be set:

应用服务应用程序设置和可用的 Application Insights 设置

应用程序设置定义Application settings definitions

应用设置名称App setting name 定义Definition ValueValue
ApplicationInsightsAgent_EXTENSION_VERSIONApplicationInsightsAgent_EXTENSION_VERSION 用于控制运行时监视的主扩展。Main extension, which controls runtime monitoring. ~2
XDT_MicrosoftApplicationInsights_ModeXDT_MicrosoftApplicationInsights_Mode (仅限默认模式)已启用基本功能以确保最佳性能。In default mode only, essential features are enabled in order to insure optimal performance. defaultrecommendeddefault or recommended.
InstrumentationEngine_EXTENSION_VERSIONInstrumentationEngine_EXTENSION_VERSION 控制是否要启用二进制重写引擎 InstrumentationEngineControls if the binary-rewrite engine InstrumentationEngine will be turned on. 此设置会对性能以及冷启动/启动时间造成影响。This setting has performance implications and impacts cold start/startup time. ~1
XDT_MicrosoftApplicationInsights_BaseExtensionsXDT_MicrosoftApplicationInsights_BaseExtensions 控制是否要随依赖项调用一起捕获 SQL 和 Azure 表文本。Controls if SQL & Azure table text will be captured along with the dependency calls. 性能警告:此设置需要 InstrumentationEnginePerformance warning: this setting requires the InstrumentationEngine. ~1

使用 Azure 资源管理器配置应用服务应用程序设置App Service Application settings with Azure Resource Manager

可以使用 Azure 资源管理器模板来管理和配置应用服务的应用程序设置。Application settings for App Services can be managed and configured with Azure Resource Manager templates. 使用 Azure 资源管理器自动化部署新的应用服务资源或修改现有资源的设置时,可以使用此方法。This method can be used when deploying new App Service resources with Azure Resource Manager automation, or for modifying the settings of existing resources.

下面是应用服务的应用程序设置 JSON 基本结构:The basic structure of the application settings JSON for an app service is below:

      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]"
          ],
          "tags": {
            "displayName": "Application Insights Settings"
          },
          "properties": {
            "key1": "value1",
            "key2": "value2"
          }
        }
      ]

模板可帮助使用为 Application Insights 配置的应用程序设置创建一个 Azure 资源管理器模板示例,具体而言,从第 238 行开始的节用于创建此模板。For an example of an Azure Resource Manager template with Application settings configured for Application Insights, this template can be helpful, specifically the section starting on line 238.

若要使用配置的所有默认 Application Insights 设置创建 Azure 资源管理器模板,请像在启用了 Application Insights 的情况下创建新的 Web 应用时一样开始操作。To create an Azure Resource Manager template with all the default Application Insights settings configured, begin the process as if you were going to create a new Web App with Application Insights enabled.

选择“自动化选项” Select Automation options

应用服务 Web 应用创建菜单

此选项将使用配置的全部所需设置生成最新的 Azure 资源管理器模板。This option generates the latest Azure Resource Manager template with all required settings configured.

应用服务 Web 应用模板

下面是一个示例,请将 AppMonitoredSite 的所有实例替换为你的站点名称:Below is a sample, replace all instances of AppMonitoredSite with your site name:

{
    "resources": [
        {
            "name": "[parameters('name')]",
            "type": "Microsoft.Web/sites",
            "properties": {
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference('microsoft.insights/components/AppMonitoredSite', '2015-05-01').InstrumentationKey]"
                        },
                        {
                            "name": "ApplicationInsightsAgent_EXTENSION_VERSION",
                            "value": "~2"
                        }
                    ]
                },
                "name": "[parameters('name')]",
                "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
                "hostingEnvironment": "[parameters('hostingEnvironment')]"
            },
            "dependsOn": [
                "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
                "microsoft.insights/components/AppMonitoredSite"
            ],
            "apiVersion": "2016-03-01",
            "location": "[parameters('location')]"
        },
        {
            "apiVersion": "2016-09-01",
            "name": "[parameters('hostingPlanName')]",
            "type": "Microsoft.Web/serverfarms",
            "location": "[parameters('location')]",
            "properties": {
                "name": "[parameters('hostingPlanName')]",
                "workerSizeId": "[parameters('workerSize')]",
                "numberOfWorkers": "1",
                "hostingEnvironment": "[parameters('hostingEnvironment')]"
            },
            "sku": {
                "Tier": "[parameters('sku')]",
                "Name": "[parameters('skuCode')]"
            }
        },
        {
            "apiVersion": "2015-05-01",
            "name": "AppMonitoredSite",
            "type": "microsoft.insights/components",
            "location": "China East 2",
            "properties": {
                "ApplicationId": "[parameters('name')]",
                "Request_Source": "IbizaWebAppExtensionCreate"
            }
        }
    ],
    "parameters": {
        "name": {
            "type": "string"
        },
        "hostingPlanName": {
            "type": "string"
        },
        "hostingEnvironment": {
            "type": "string"
        },
        "location": {
            "type": "string"
        },
        "sku": {
            "type": "string"
        },
        "skuCode": {
            "type": "string"
        },
        "workerSize": {
            "type": "string"
        },
        "serverFarmResourceGroup": {
            "type": "string"
        },
        "subscriptionId": {
            "type": "string"
        }
    },
    "$schema": "https://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0"
}

Note

该模板将在“默认”模式下生成应用程序设置。The template will generate application settings in “default” mode. 此模式的性能已经过优化,不过,可以修改该模板,以激活所需的任何功能。This mode is performance optimized, though you can modify the template to activate whichever features you prefer.

通过 PowerShell 启用Enabling through PowerShell

若要通过 PowerShell 启用应用程序监视,只需更改基础的应用程序设置。In order to enable the application monitoring through PowerShell, only the underlying application settings need to be changed. 以下示例为资源组“AppMonitoredRG”中名为“AppMonitoredSite”的网站启用应用程序监视,并将数据配置为发送到“012345678-abcd-ef01-2345-6789abcd”检测密钥。Below is a sample, which enables application monitoring for a website called "AppMonitoredSite" in the resource group "AppMonitoredRG", and configures data to be sent to the "012345678-abcd-ef01-2345-6789abcd" instrumentation key.

Note

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

$app = Get-AzWebApp -ResourceGroupName "AppMonitoredRG" -Name "AppMonitoredSite" -ErrorAction Stop
$newAppSettings = @{} # case-insensitive hash map
$app.SiteConfig.AppSettings | %{$newAppSettings[$_.Name] = $_.Value} #preserve non Application Insights Application settings.
$newAppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"] = "012345678-abcd-ef01-2345-6789abcd"; # enable the ApplicationInsightsAgent
$newAppSettings["ApplicationInsightsAgent_EXTENSION_VERSION"] = "~2"; # enable the ApplicationInsightsAgent
$app = Set-AzWebApp -AppSettings $newAppSettings -ResourceGroupName $app.ResourceGroup -Name $app.Name -ErrorAction Stop

升级监视扩展/代理Upgrade monitoring extension/agent

从版本 2.8.9 及更高版本升级Upgrading from versions 2.8.9 and up

从版本 2.8.9 的升级会自动发生,无需额外的操作。Upgrading from version 2.8.9 happens automatically, without any additional actions. 新的监视位将在后台传送到目标应用服务,应用程序重启时,会拾取这些位。The new monitoring bits are delivered in the background to the target app service, and on application restart they will be picked up.

若要检查正在运行的扩展版本,请访问 http://yoursitename.scm.azurewebsites.net/ApplicationInsightsTo check which version of the extension you are running visit http://yoursitename.scm.azurewebsites.net/ApplicationInsights

URL 路径 http://yoursitename.scm.azurewebsites.net/ApplicationInsights 的屏幕截图

从版本 1.0.0 - 2.6.5 升级Upgrade from versions 1.0.0 - 2.6.5

从版本 2.8.9 开始,将使用预装的站点扩展。Starting with version 2.8.9 the pre-installed site extension is used. 如果使用更低的版本,可通过两种方法之一进行更新:If you are an earlier version, you can update via one of two ways:

  • 通过门户启用扩展进行升级Upgrade by enabling via the portal. (即使已安装 Azure 应用服务的 Application Insights 扩展,UI 也只会显示“启用”按钮。 (Even if you have the Application Insights extension for Azure App Service installed, the UI shows only Enable button. 在幕后,旧的专用站点扩展将被删除。)Behind the scenes, the old private site extension will be removed.)

  • 通过 PowerShell 升级Upgrade through PowerShell:

    1. 设置应用程序设置以启用预装的站点扩展 ApplicationInsightsAgent。Set the application settings to enable the pre-installed site extension ApplicationInsightsAgent. 请参阅通过 PowerShell 启用See Enabling through powershell.
    2. 手动删除名为“Azure 应用服务的 Application Insights 扩展”的专用站点扩展。Manually remove the private site extension named Application Insights extension for Azure App Service.

如果已从低于 2.5.1 的版本完成升级,请检查是否已从应用程序 bin 文件夹中删除了 ApplicationInsigths dll。参阅故障排除步骤If the upgrade is done from a version prior to 2.5.1, check that the ApplicationInsigths dlls are removed from the application bin folder see troubleshooting steps.

故障排除Troubleshooting

下面是我们针对 Azure 应用服务中运行的基于 .NET 和 .NET Core 的应用程序的基于扩展/代理的监视提供的分步故障排除指南。Below is our step-by-step troubleshooting guide for extension/agent based monitoring for .NET and .NET Core based applications running on Azure App Services.

Note

仅支持通过基于手动 SDK 的检测在 Azure 应用服务中使用 Java 和 Node.js 应用程序,因此,以下步骤不适用于这些方案。Java and Node.js applications are only supported on Azure App Services via manual SDK based instrumentation and therefore the steps below do not apply to these scenarios.

  1. 通过 ApplicationInsightsAgent 检查应用程序是否受监视。Check that the application is monitored via ApplicationInsightsAgent.

    • 检查 ApplicationInsightsAgent_EXTENSION_VERSION 应用设置是否设置为值“~2”。Check that ApplicationInsightsAgent_EXTENSION_VERSION app setting is set to a value of "~2".
  2. 确保应用程序符合监视要求。Ensure that the application meets the requirements to be monitored.

    • 浏览到 https://yoursitename.scm.azurewebsites.net/ApplicationInsightsBrowse to https://yoursitename.scm.azurewebsites.net/ApplicationInsights

    https://yoursitename.scm.azurewebsites/applicationinsights 结果页的屏幕截图

    • 确认 Application Insights Extension StatusPre-Installed Site Extension, version 2.8.12.1527, is running.Confirm that the Application Insights Extension Status is Pre-Installed Site Extension, version 2.8.12.1527, is running.

    • 确认状态源存在并类似于:Status source D:\home\LogFiles\ApplicationInsights\status\status_RD0003FF0317B6_4248_1.jsonConfirm that the status source exists and looks like: Status source D:\home\LogFiles\ApplicationInsights\status\status_RD0003FF0317B6_4248_1.json

      • 如果不存在类似的值,则表示应用程序当前未运行或不受支持。If a similar value is not present, it means the application is not currently running or is not supported. 为确保应用程序运行,请尝试手动访问应用程序 URL/应用程序终结点,以提供运行时信息。To ensure that the application is running, try manually visiting the application url/application endpoints, which will allow the runtime information to become available.
    • 确认 IKeyExiststrueConfirm that IKeyExists is true

      • 如果为 false,请将“APPINSIGHTS_INSTRUMENTATIONKEY”和 ikey guid 添加到应用程序设置。If it is false, add `APPINSIGHTS_INSTRUMENTATIONKEY with your ikey guid to your application settings.
    • 确认 AppAlreadyInstrumentedAppContainsDiagnosticSourceAssemblyAppContainsAspNetTelemetryCorrelationAssembly 没有任何对应的条目。Confirm that there are no entries for AppAlreadyInstrumented, AppContainsDiagnosticSourceAssembly, and AppContainsAspNetTelemetryCorrelationAssembly.

      • 如果存在其中的任何条目,请从应用程序中删除以下包:Microsoft.ApplicationInsightsSystem.Diagnostics.DiagnosticSourceMicrosoft.AspNet.TelemetryCorrelationIf any of these entries exist, remove the following packages from your application: Microsoft.ApplicationInsights, System.Diagnostics.DiagnosticSource, and Microsoft.AspNet.TelemetryCorrelation.

下表更详细地解释了这些值的含义、其根本原因和建议的修复方法:The table below provides a more detailed explanation of what these values mean, their underlying causes, and recommended fixes:

问题值Problem Value 说明Explanation 解决方法Fix
AppAlreadyInstrumented:true 此值表示扩展已检测到 SDK 的某个功能已在应用程序中存在,因此将会回退。This value indicates that the extension detected that some aspect of the SDK is already present in the Application, and will back-off. 原因可能是引用了 System.Diagnostics.DiagnosticSourceMicrosoft.AspNet.TelemetryCorrelationMicrosoft.ApplicationInsightsIt can be due to a reference to System.Diagnostics.DiagnosticSource, Microsoft.AspNet.TelemetryCorrelation, or Microsoft.ApplicationInsights 删除引用。Remove the references. 某中的某些引用是从特定的 Visual Studio 模板默认添加的,而旧版 Visual Studio 可能会添加对 Microsoft.ApplicationInsights 的引用。Some of these references are added by default from certain Visual Studio templates, and older versions of Visual Studio may add references to Microsoft.ApplicationInsights.
AppAlreadyInstrumented:true 如果应用程序面向 .NET Core 2.1 或 2.2 并引用 Microsoft.AspNetCore.All 元包,则它会引入 Application Insights,因此扩展将会回退。If the application is targeting .NET Core 2.1 or 2.2, and refers to Microsoft.AspNetCore.All meta-package, then it brings in Application Insights, and extension will back-off. 建议 .NET Core 2.1、2.2 客户改用 Microsoft.AspNetCore.App 元包。Customers on .NET Core 2.1,2.2 are recommended to use Microsoft.AspNetCore.App meta-package instead.
AppAlreadyInstrumented:true 出现此值的原因还可能是前一部署的应用文件夹中存在上述 dll。This value can also be caused by the presence of the above dlls in the app folder from a previous deployment. 清除应用文件夹,以确保删除这些 dll。Clean the app folder to ensure that these dlls are removed.
AppContainsAspNetTelemetryCorrelationAssembly: true 此值表示扩展已检测到对应用程序中的 Microsoft.AspNet.TelemetryCorrelation 的引用,因此将会回退。This value indicates that extension detected references to Microsoft.AspNet.TelemetryCorrelation in the application, and will back-off. 删除引用。Remove the reference.
AppContainsDiagnosticSourceAssembly**:true 此值表示扩展已检测到对应用程序中的 System.Diagnostics.DiagnosticSource 的引用,因此将会回退。This value indicates that extension detected references to System.Diagnostics.DiagnosticSource in the application, and will back-off. 删除引用。Remove the reference.
IKeyExists:false 此值表示 AppSetting 中不存在检测密钥 APPINSIGHTS_INSTRUMENTATIONKEYThis value indicates that the instrumentation key is not present in the AppSetting, APPINSIGHTS_INSTRUMENTATIONKEY. 可能的原因:可能意外删除了这些值,忘记了在自动化脚本中设置这些值,等等。Possible causes: The values may have been accidentally removed, forgot to set the values in automation script, etc. 确保该设置在应用服务的应用程序设置中存在。Make sure the setting is present in the App Service application settings.

不支持 APPINSIGHTS_JAVASCRIPT_ENABLED 和 urlCompressionAPPINSIGHTS_JAVASCRIPT_ENABLED and urlCompression is not supported

如果在对内容进行编码的情况下使用 APPINSIGHTS_JAVASCRIPT_ENABLED=true,可能会出现如下所示的错误:If you use APPINSIGHTS_JAVASCRIPT_ENABLED=true in cases where content is encoded, you might get errors like:

  • 500 URL 重写错误500 URL rewrite error
  • 发生 500.53 URL 重写模块错误,并出现消息“对 HTTP 响应的内容进行编码(gzip)时,无法应用出站重写规则”。500.53 URL rewrite module error with message Outbound rewrite rules cannot be applied when the content of the HTTP response is encoded ('gzip').

这是因为 APPINSIGHTS_JAVASCRIPT_ENABLED 应用程序设置指定为 true,同时存在内容编码。This is due to the APPINSIGHTS_JAVASCRIPT_ENABLED application setting being set to true and content-encoding being present at the same time. 目前不支持此方案。This scenario is not supported yet. 解决方法是从应用程序设置中删除 APPINSIGHTS_JAVASCRIPT_ENABLED。The workaround is to remove APPINSIGHTS_JAVASCRIPT_ENABLED from your application settings. 遗憾的是,这意味着,如果仍然需要客户端/浏览器端 JavaScript 检测,则需要对网页使用手动 SDK 引用。Unfortunately this means that if client/browser-side JavaScript instrumentation is still required, manual SDK references are needed for your webpages. 请遵照说明使用 JavaScript SDK 进行手动检测。Please follow the instructions for manual instrumentation with the JavaScript SDK.

有关 Application Insights 代理/扩展的最新信息,请查看发行说明For the latest information on the Application Insights agent/extension, check out the release notes.

后续步骤Next steps