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

现在,可以比过去更轻松地针对 Azure 应用服务中运行的基于 ASP.NET 和 ASP.NET Core 的 Web 应用程序启用监视。Enabling monitoring on your ASP.NET and ASP.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.


通过“开发工具” > “扩展”手动添加 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.

    • 此方法的可自定义性要高得多,但需要添加 Application Insights SDK NuGet 包中的一个依赖项This approach is much more customizable, but it requires adding a dependency on the Application Insights SDK NuGet packages. 使用此方法还需要自行管理对最新版本的包的更新。This method, also means you have to manage the updates to the latest version of the packages yourself.

    • 如果需要发出自定义 API 调用来跟踪基于代理的监视在默认情况下不会捕获的事件/依赖项,则需要使用此方法。If you need to make custom API calls to track events/dependencies not captured by default with agent-based monitoring, you would need to use this method. 有关详细信息,请查看 自定义事件和指标的 API 一文。Check out the API for custom events and metrics article to learn more. 对于基于 Linux 的工作负荷,这也是当前唯一支持的选项。This is also currently the only supported option for Linux based workloads.


如果同时检测到了基于代理的监视和基于手动 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 being sent. 有关详细信息,请查看下面的故障排除部分To learn more about this, check out the troubleshooting section below.

启用基于代理的监视Enable agent-based monitoring


不支持 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.


      当单击“确定”来创建新资源时,将提示你 应用监视设置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.

    屏幕截图显示 Application Insights 站点扩展页面,其中选择了“创建新资源”。

下面是针对每个路由收集的数据的摘要:Below is a summary of data collected for each route:

数据Data ASP.NET 基本集合ASP.NET Basic Collection ASP.NET 建议集合ASP.NET Recommended collection
添加 CPU、内存和 I/O 使用情况趋势Adds CPU, memory, and I/O usage trends Yes Yes
收集使用情况趋势,并启用从可用性结果到事务的关联Collects usage trends, and enables correlation from availability results to transactions Yes Yes
收集未经主机进程处理的异常Collects exceptions unhandled by the host process Yes Yes
提高使用采样时,负载下的 APM 指标准确性Improves APM metrics accuracy under load, when sampling is used Yes Yes
跨请求/依赖项边界关联微服务Correlates micro-services across request/dependency boundaries 否(仅单实例 APM 功能)No (single-instance APM capabilities only) Yes
  1. 若要配置采样等设置(以前可以通过 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.

启用客户端监视Enable client-side monitoring

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

  • “设置”>“配置” Settings > Configuration
    • 在“应用程序设置”下,创建“新建应用程序设置”:Under Application settings, create a new application setting:


      值:trueValue: true

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

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

自动监视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. 性能警告:应用程序冷启动时间将会受到影响。Performance warning: application cold start up time will be affected. 此设置需要 InstrumentationEngineThis 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": "APPLICATIONINSIGHTS_CONNECTION_STRING",
                            "value": "[reference('microsoft.insights/components/AppMonitoredSite', '2015-05-01').ConnectionString]"
                            "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'))]",
            "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": ""

通过 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.


本文进行了更新,以便使用新的 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"; # set the Application Insights instrumentation key
$newAppSettings["APPLICATIONINSIGHTS_CONNECTION_STRING"] = "InstrumentationKey=012345678-abcd-ef01-2345-6789abcd"; # set the Application Insights connection string
$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.chinacloudsites.cn/ApplicationInsightsTo check which version of the extension you are running visit http://yoursitename.scm.chinacloudsites.cn/ApplicationInsights

URL 路径 http://yoursitename.scm.chinacloudsites.cn/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.


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


监视 Java 应用程序的建议方法是在不更改代码的情况下使用自动检测。The recommended approach to monitor Java applications is to use the auto-instrumentation without changing the code. 请按照 Application Insights Java 3.0 代理指南进行操作。Please follow the guidelines for Application Insights Java 3.0 agent.

  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.chinacloudsites.cn/ApplicationInsightsBrowse to https://yoursitename.scm.chinacloudsites.cn/ApplicationInsights

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

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

    • 如果未运行,请遵照启用 Application Insights 监视的说明If it is not running, follow the enable Application Insights monitoring instructions

    • 确认状态源存在并类似于: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

    • 确认 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.
      • 仅适用于 ASP.NET Core 应用:在应用程序引用任何 Application Insights 包时(例如,如果你先前已使用 ASP.NET Core SDK 检测(或尝试检测)应用),则启用应用服务集成可能不会生效,并且数据可能不会显示在 Application Insights 中。For ASP.NET Core apps only: in case your application refers to any Application Insights packages, for example if you have previously instrumented (or attempted to instrument) your app with the ASP.NET Core SDK, enabling the App Service integration may not take effect and the data may not appear in Application Insights. 若要解决此问题,请在门户中打开“与 Application Insights SDK 互操作”,你将开始在 Application Insights 中看到数据To fix the issue, in portal turn on "Interop with Application Insights SDK" and you will start seeing the data in Application Insights


      此功能处于预览阶段This functionality is in preview


      即使 Application Insights SDK 被最初使用或尝试使用,现在仍将使用无代码方法发送数据。The data is now going to be sent using codeless approach even if Application Insights SDK was originally used or attempted to be used.


      如果应用程序使用 Application Insights SDK 发送任何遥测,则将禁用此类遥测 - 也就是说,自定义遥测(如果有,例如任何 Track*() 方法)和任何自定义设置(如采样)都将被禁用。If the application used Application Insights SDK to send any telemetry, such telemetry will be disabled - in other words, custom telemetry - if any, such as for example any Track*() methods, and any custom settings, such as sampling, will be disabled.

不支持 PHP 和 WordPressPHP and WordPress are not supported

不支持 PHP 和 WordPress 站点。PHP and WordPress sites are not supported. 目前没有官方支持的 SDK/代理可用于在服务器端监视这些工作负荷。There is currently no officially supported SDK/agent for server-side monitoring of these workloads. 但是,可以通过将客户端 javascript 添加到网页,使用 JavaScript SDK 在 PHP 或 WordPress 站点上手动检测客户端事务。However, manually instrumenting client-side transactions on a PHP or WordPress site by adding the client-side JavaScript to your web pages can be accomplished by using the JavaScript SDK.

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

问题值Problem Value 说明Explanation FixFix
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 如果应用程序面向 ASP.NET Core 2.1 或 2.2,此值表示扩展已检测到 SDK 的某个功能已在应用程序中存在,因此将会回退If the application is targeting ASP.NET Core 2.1 or 2.2, this value indicates that the extension detected that some aspect of the SDK is already present in the Application, and 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. 此外,在门户中打开“与 Application Insights SDK 互操作”(请参阅上面的说明)。In addition, turn on "Interop with Application Insights SDK" in portal (see the instructions above).
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. 检查本地应用的 bin 目录和应用服务的 wwwroot 目录。Check both your local app's bin directory, and the wwwroot directory on the App Service. (检查应用服务 Web 应用的 wwwroot 目录:高级工具(Kudu) > 调试控制台 > CMD > home\site\wwwroot)。(To check the wwwroot directory of your App Service web app: Advanced Tools (Kudu) > Debug console > CMD > home\site\wwwroot).
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. 对于 ASP.NET,删除引用。For ASP.NET 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.

用 Web 应用部署的默认网站不支持自动客户端监视Default website deployed with web apps does not support automatic client-side monitoring

使用 ASP.NETASP.NET Core 运行时在 Azure 应用服务中创建 Web 应用时,该应用会部署单个静态 HTML 页面作为入门网站。When you create a web app with the ASP.NET or ASP.NET Core runtimes in Azure App Services it deploys a single static HTML page as a starter website. 该静态网页还会在 IIS 中加载 ASP.NET 托管 Web 部件。The static webpage also loads a ASP.NET managed web part in IIS. 这使得能够测试无代码服务器端监视,但不支持自动客户端监视。This allows for testing codeless server-side monitoring, but does not support automatic client-side monitoring.

如果你希望在 Azure 应用服务 Web 应用中测试 ASP.NET 或 ASP.NET Core 的无代码服务器和客户端监视,建议遵循创建 ASP.NET Core Web 应用创建 ASP.NET Framework Web 应用官方指南,然后按照当前文章中的说明来启用监视。If you wish to test out codeless server and client-side monitoring for ASP.NET or ASP.NET Core in a Azure App Services web app we recommend following the official guides for creating a ASP.NET Core web app and creating an ASP.NET Framework web app and then use the instructions in the current article to enable monitoring.

连接字符串和检测密钥Connection string and instrumentation key

使用无代码监视时,只需要连接字符串。When codeless monitoring is being used, only the connection string is required. 但是,我们仍然建议设置检测密钥,以便在执行手动检测时保持与旧版 SDK 的后向兼容性。However, we still recommend setting the instrumentation key to preserve backwards compatibility with older versions of the SDK when manual instrumentation is being performed.

发行说明Release notes

有关最新的更新和 bug 修复,请参阅发行说明For the latest updates and bug fixes consult the release notes.

后续步骤Next steps