排查启用或查看 Application Insights Profiler 时遇到的问题Troubleshoot problems enabling or viewing Application Insights Profiler


在 Azure 应用服务中对 ASP.NET Core 应用运行探查器时有一个 bug。There is a bug running profiler for ASP.NET Core apps on Azure App Service. 我们有一个修补程序,但部署需要几周时间。We have a fix, but it will take a few weeks to deploy. 可以按照此处的说明将 Application Insights SDK 添加到应用程序来解决此 bug。You can work around the bug by adding the Application Insights SDK to your application with instructions here.

常规故障排除General troubleshooting

仅当在运行 Profiler 期间对应用程序发出了请求时,才上传配置文件Profiles are uploaded only if there are requests to your application while Profiler is running

Azure Application Insights Profiler 每小时会收集两分钟的数据。Azure Application Insights Profiler collects data for two minutes each hour. 当你在“配置 Application Insights Profiler”窗格中选择“立即分析”按钮时,它也会收集数据 。It can also collect data when you select the Profile Now button in the Configure Application Insights Profiler pane.


但是,仅当可将分析数据附加到运行 Profiler 期间所发生的请求时,才会上传分析数据。The profiling data is uploaded only when it can be attached to a request that happened while Profiler was running.

Profiler 将跟踪消息和自定义事件写入到 Application Insights 资源。Profiler writes trace messages and custom events to your Application Insights resource. 可以通过这些事件来查看 Profiler 的运行方式:You can use these events to see how Profiler is running:

  1. 搜索由 Profiler 发送到 Application Insights 资源的跟踪消息和自定义事件。Search for trace messages and custom events sent by Profiler to your Application Insights resource. 可以使用此搜索字符串查找相关的数据:You can use this search string to find the relevant data:

    stopprofiler OR startprofiler OR upload OR ServiceProfilerSample

    下图显示了两个从两个 AI 资源中进行搜索的示例:The following image displays two examples of searches from two AI resources:

    • 在左侧,应用程序在 Profiler 运行时不接收请求。At the left, the application isn't receiving requests while Profiler is running. 此消息说明,由于没有发生活动,上传操作已取消。The message explains that the upload was canceled because of no activity.

    • 在右侧,Profiler 已启动,并在检测到它运行期间发生的请求时发送了自定义事件。At the right, Profiler started and sent custom events when it detected requests that happened while Profiler was running. 如果显示了 ServiceProfilerSample 自定义事件,则表示已捕获某个配置文件,并且该配置文件显示在“Application Insights 性能”窗格中。If the ServiceProfilerSample custom event is displayed, it means that a profile was captured and its available in the Application Insights Performance pane.

      如果未显示任何记录,则表明 Profiler 未运行。If no records are displayed, Profiler isn't running. 要进行故障排除,请参阅本文后面的特定应用类型的故障排除部分。To troubleshoot, see the troubleshooting sections for your specific app type later in this article.

      搜索 Profiler 遥测数据

要检查的其他事项Other things to check

  • 确保应用在 .NET Framework 4.6 上运行。Make sure that your app is running on .NET Framework 4.6.
  • 如果 Web 应用是 ASP.NET Core 应用程序,则必须至少运行 ASP.NET Core 2.0。If your web app is an ASP.NET Core application, it must be running at least ASP.NET Core 2.0.
  • 如果要查看的数据的期限超过了好几周,请尝试限制时间筛选器并重试。If the data you're trying to view is older than a couple of weeks, try limiting your time filter and try again. 七天后将删除跟踪。Traces are deleted after seven days.
  • 确保代理或防火墙未阻止对 https://gateway.azureserviceprofiler.net 的访问。Make sure that proxies or a firewall haven't blocked access to https://gateway.azureserviceprofiler.net.
  • 免费或共享应用服务计划不支持 Profiler。Profiler isn't supported on free or shared app service plans. 如果你正在使用这些计划之一,请尝试扩展至其中一个基本计划,并且 Profiler 应开始工作。If you're using one of those plans, try scaling up to one of the basic plans and Profiler should start working.

并行线程的重复计算Double counting in parallel threads

在某些情况下,堆栈查看器中的总时间指标大于请求的持续时间。In some cases, the total time metric in the stack viewer is more than the duration of the request.

当两个或更多个并行线程与某个请求相关联时,可能会发生这种情况。This situation might occur when two or more parallel threads are associated with a request. 在这种情况下,总线程时间就会超过已用时间。In that case, the total thread time is more than the elapsed time.

一个线程可能会等待另一个线程完成。One thread might be waiting on the other to be completed. 查看器会尝试检测此情况并省略不相关的等待时间。The viewer tries to detect this situation and omits the uninteresting wait. 这样,它会倾向于显示过多信息,而不是省略关键信息。In doing so, it errs on the side of displaying too much information rather than omit what might be critical information.

如果看到跟踪中出现并行线程,请确定哪些线程处于等待状态,以便可以查明请求的热路径。When you see parallel threads in your traces, determine which threads are waiting so that you can identify the hot path for the request.

通常情况下,快速进入等待状态的线程只是在等待其他线程完成。Usually, the thread that quickly goes into a wait state is simply waiting on the other threads. 请专注于其他线程,忽略等待中线程花费的时间。Concentrate on the other threads, and ignore the time in the waiting threads.

配置文件查看器中的错误报告Error report in the profile viewer

在门户中提交支持票证。Submit a support ticket in the portal. 请务必包含错误消息中的相关性 ID。Be sure to include the correlation ID from the error message.

排查 Azure 应用服务中的 Profiler 问题Troubleshoot Profiler on Azure App Service

要使 Profiler 正常工作:For Profiler to work properly:

  • Web 应用服务计划必须属于“基本”层或更高层。Your web app service plan must be Basic tier or higher.

  • Web 应用必须已启用 Application Insights。Your web app must have Application Insights enabled.

  • Web 应用必须具有以下应用设置:Your web app must have the following app settings:

    应用设置App Setting Value
    APPINSIGHTS_INSTRUMENTATIONKEYAPPINSIGHTS_INSTRUMENTATIONKEY Application Insights 资源的 iKeyiKey for your Application Insights resource
    DiagnosticServices_EXTENSION_VERSIONDiagnosticServices_EXTENSION_VERSION ~3~3
  • ApplicationInsightsProfiler3 webjob 必须正在运行。The ApplicationInsightsProfiler3 webjob must be running. 若要检查 webjob:To check the webjob:

    1. 转到 KuduGo to Kudu.

    2. 在“工具”菜单中,选择“WebJobs 仪表板” 。In the Tools menu, select WebJobs Dashboard.
      “WebJobs”窗格随即打开。The WebJobs pane opens.

      屏幕截图显示了 WebJobs 窗格,其中显示了作业的名称、状态和上次运行时间。

    3. 若要查看 webjob 的详细信息(包括日志),请选择“ApplicationInsightsProfiler3”链接。To view the details of the webjob, including the log, select the ApplicationInsightsProfiler3 link.
      “连续 WebJob 详细信息”窗格随即打开。The Continuous WebJob Details pane opens.

      屏幕截图显示了“连续 WebJob 详细信息”窗格。

检查诊断服务站点扩展的“状态”页Check the Diagnostic Services site extension' Status Page

如果 Profiler 是通过门户中的 Application Insights 窗格启用的,则它是由诊断服务站点扩展启用的。If Profiler was enabled through the Application Insights pane in the portal, it was enabled by the Diagnostic Services site extension.

可以转到以下 URL 来查看此扩展的“状态”页:https://{site-name}.scm.chinacloudsites.cn/DiagnosticServicesYou can check the Status Page of this extension by going to the following url: https://{site-name}.scm.chinacloudsites.cn/DiagnosticServices


“状态”页链接的域将因云而异。The domain of the Status Page link will vary depending on the cloud. 此域将与应用服务的 Kudu 管理站点相同。This domain will be the same as the Kudu management site for App Service.

此“状态”页显示 Profiler 和 Snapshot Collector 代理的安装状态。This Status Page shows the installation state of the Profiler and Snapshot Collector agents. 如果出现意外错误,则会显示该错误,并显示如何修复该错误。If there was an unexpected error, it will be displayed and show how to fix it.

你可以使用应用服务的 Kudu 管理站点获取此“状态”页的基 URL:You can use the Kudu management site for App Service to get the base url of this Status Page:

  1. 在 Azure 门户中,打开应用服务应用程序。Open your App Service application in the Azure portal.
  2. 选择“高级工具”或搜索“Kudu” 。Select Advanced Tools, or search for Kudu.
  3. 选择“转到”。Select Go.
  4. 进入 Kudu 管理站点后,在 URL 中追加以下 /DiagnosticServices 并按 Enter。Once you are on the Kudu management site, in the URL, append the following /DiagnosticServices and press enter. 它最终将如下所示:https://<kudu-url>/DiagnosticServicesIt will end like this: https://<kudu-url>/DiagnosticServices

它会显示类似于以下内容的“状态”页:诊断服务“状态”页It will display a Status Page similar like the below: Diagnostic Services Status Page

手动安装Manual installation

配置 Profiler 时,将对 Web 应用的设置进行更新。When you configure Profiler, updates are made to the web app's settings. 如果你的环境有此要求,则可以手动应用更新。If your environment requires it, you can apply the updates manually. 例如,应用程序在适用于 PowerApps 的 Web 应用环境中运行。An example might be that your application is running in a Web Apps environment for PowerApps. 若要手动应用更新,请执行以下操作:To apply updates manually:

  1. 在“Web 应用控制”窗格中,打开“设置” 。In the Web App Control pane, open Settings.

  2. 将“.NET Framework 版本”设置为“v4.6” 。Set .NET Framework version to v4.6.

  3. 将“Always On”设置为“打开” 。Set Always On to On.

  4. 创建以下应用设置:Create these app settings:

    应用设置App Setting Value
    APPINSIGHTS_INSTRUMENTATIONKEYAPPINSIGHTS_INSTRUMENTATIONKEY Application Insights 资源的 iKeyiKey for your Application Insights resource
    DiagnosticServices_EXTENSION_VERSIONDiagnosticServices_EXTENSION_VERSION ~3~3

活动分析会话太多Too many active profiling sessions

最多可以为同一服务计划中运行的四个 Web 应用启用 Profiler。You can enable Profiler on a maximum of four Web Apps that are running in the same service plan. 如果你的 Web 应用超过四个,则 Profiler 可能会引发 Microsoft.ServiceProfiler.Exceptions.TooManyETWSessionException。If you've more than four, Profiler might throw a Microsoft.ServiceProfiler.Exceptions.TooManyETWSessionException. 若要解决此问题,请将一些 Web 应用移到其他服务计划中。To solve it, move some web apps to a different service plan.

部署错误:目录不为空“D:\home\site\wwwroot\App_Data\jobs”Deployment error: Directory Not Empty 'D:\home\site\wwwroot\App_Data\jobs'

如果在已启用 Profiler 的情况下将 Web 应用重新部署到 Web 应用资源,可能会看到如下消息:If you're redeploying your web app to a Web Apps resource with Profiler enabled, you might see the following message:

目录不为空“D:\home\site\wwwroot\App_Data\jobs”Directory Not Empty 'D:\home\site\wwwroot\App_Data\jobs'

如果通过脚本或通过 Azure Pipelines 运行 Web 部署,则会发生此错误。This error occurs if you run Web Deploy from scripts or from the Azure Pipelines. 解决方法是将以下附加部署参数添加到 Web 部署任务:The solution is to add the following additional deployment parameters to the Web Deploy task:

-skip:Directory='.*\\App_Data\\jobs\\continuous\\ApplicationInsightsProfiler.*' -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data\\jobs\\continuous$' -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data\\jobs$'  -skip:skipAction=Delete,objectname='dirPath',absolutepath='.*\\App_Data$'

这些参数将删除 Application Insights Profiler 所用的文件夹,并取消阻止重新部署进程。These parameters delete the folder that's used by Application Insights Profiler and unblock the redeploy process. 它们不影响当前运行的 Profiler 实例。They don't affect the Profiler instance that's currently running.

如何确定 Application Insights Profiler 是否正在运行?How do I determine whether Application Insights Profiler is running?

Profiler 在 Web 应用中以连续 Web 作业的形式运行。Profiler runs as a continuous webjob in the web app. 可以在 Azure 门户中打开 Web 应用资源。You can open the web app resource in the Azure portal. 在“WebJobs”窗格中,查看 ApplicationInsightsProfiler 的状态 。In the WebJobs pane, check the status of ApplicationInsightsProfiler. 如果探查器未运行,请打开“日志”获取详细信息。If it isn't running, open Logs to get more information.

对 VM 和云服务进行故障排除Troubleshoot VMs and Cloud Services

云服务 WAD 中附带的探查器中的 bug 已修复。The bug in the profiler that ships in the WAD for Cloud Services has been fixed. 用于云服务的最新版本的 WAD ( 适用于所有最新版本的 App Insights SDK。The latest version of WAD ( for Cloud Services works with all recent versions of the App Insights SDK. 云服务主机将自动升级 WAD,但不会立即升级。Cloud Service hosts will upgrade WAD automatically, but it isn't immediate. 若要强制升级,可以重新部署服务或重新启动节点。To force an upgrade, you can redeploy your service or reboot the node.

若要查看 Azure 诊断是否正确配置了 Profiler,请执行以下步骤:To see whether Profiler is configured correctly by Azure Diagnostics, follow the below steps:

  1. 验证所部署的 Azure 诊断配置的内容是否符合你的预期。Verify that the content of the Azure Diagnostics configuration deployed is what you expect.

  2. 其次,确保 Azure 诊断在 Profiler 命令行上传递正确的 iKey。Second, make sure that Azure Diagnostics passes the proper iKey on the Profiler command line.

  3. 最后,检查 Profiler 日志文件,以查看 Profiler 是否已运行但返回了错误。Third, check the Profiler log file to see whether Profiler ran but returned an error.

若要检查用于配置 Azure 诊断的设置:To check the settings that were used to configure Azure Diagnostics:

  1. 登录到虚拟机 (VM),然后打开位于此位置的日志文件。Sign in to the virtual machine (VM), and then open the log file at this location. 此插件版本在你的计算机上可能会更高。The plugin version may be newer on your machine.

    对于 VM:For VMs:


    对于云服务:For Cloud Services:

  2. 在该文件中,可以搜索字符串“WadCfg”,找到传递给 VM 用于配置 Azure 诊断的设置。In the file, you can search for the string WadCfg to find the settings that were passed to the VM to configure Azure Diagnostics. 可以检查 Profiler 接收器使用的 iKey 是否正确。You can check to see whether the iKey used by the Profiler sink is correct.

  3. 检查用于启动 Profiler 的命令行。Check the command line that's used to start Profiler. 用于启动 Profiler 的参数位于以下文件中。The arguments that are used to launch Profiler are in the following file. (驱动器可能是 C: 或 D: 并且可能会隐藏目录。)(The drive could be c: or d: and the directory may be hidden.)

    对于 VM:For VMs:


    对于云服务:for Cloud Services:

  4. 确保 Profiler 命令行中的 iKey 是正确的。Make sure that the iKey on the Profiler command line is correct.

  5. 使用上述 config.json 文件中的路径检查 Profiler 日志文件 BootstrapN.log。Using the path found in the preceding config.json file, check the Profiler log file, called BootstrapN.log. 它将显示表示 Profiler 正在使用的设置的调试信息。It displays the debug information that indicates the settings that Profiler is using. 此外,还将显示来自 Profiler 的状态和错误消息。It also displays status and error messages from Profiler.

    对于 VM,该文件通常位于此处:For VMs, the file is here:


    对于云服务:For Cloud Services:


    如果当应用程序接收请求时 Profiler 正在运行,则会显示以下消息:“检测到来自 iKey 的活动”。If Profiler is running while your application is receiving requests, the following message is displayed: Activity detected from iKey.

    上传跟踪时,会显示以下消息:“开始上传跟踪”。When the trace is being uploaded, the following message is displayed: Start to upload trace.

编辑网络代理或防火墙规则Edit network proxy or firewall rules

如果应用程序通过代理或防火墙连接到 Internet,则可能需要更新规则才能与 Profiler 服务通信。If your application connects to the Internet via a proxy or a firewall, you may need to update the rules to communicate with the Profiler service.

Application Insights Profiler 使用的 IP 包含在 Azure Monitor 服务标记中。The IPs used by Application Insights Profiler are included in the Azure Monitor service tag. 有关详细信息,请参阅服务标记文档For more information, see Service Tags documentation.