排查启用或查看 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 profiling data for two minutes each hour. 当你在“配置 Application Insights Profiler”窗格中选择“立即配置文件”按钮时,它也会收集数据 。It also collects data when you select the Profile Now button in the Configure Application Insights Profiler pane. 但是,仅当可将分析数据附加到运行 Profiler 期间所发生的请求时,才会上传分析数据。But 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. 如果你认为 Profiler 应该运行并捕获跟踪,但“性能”窗格中并未显示这些信息,则可以检查 Profiler 的运行方式:If you think Profiler should be running and capturing traces, but they're not displayed in the Performance pane, you can check 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 自定义事件,则表示 Profiler 已将一个跟踪附加到请求,你可以从“Application Insights 性能”窗格查看该跟踪。If the ServiceProfilerSample custom event is displayed, it means that Profiler attached a trace to a request and you can view the trace in the Application Insights Performance pane.

      如果未显示遥测数据,则 Profiler 未运行。If no telemetry is displayed, Profiler is not running. 要进行故障排除,请参阅本文后面的特定应用类型的故障排除部分。To troubleshoot, see the troubleshooting sections for your specific app type later in this article.

      搜索 Profiler 遥测数据

  2. 如果在 Profiler 运行时发出了请求,请确保应用程序中已启用 Profiler 的组件可以处理该请求。If there were requests while Profiler ran, make sure that the requests are handled by the part of your application that has Profiler enabled. 虽然应用程序有时包括多个组件,但只对一部分组件启用了 Profiler。Although applications sometimes consist of multiple components, Profiler is enabled for only some of the components. “配置 Application Insights Profiler”窗格会显示已上传跟踪的组件。The Configure Application Insights Profiler pane displays the components that have uploaded traces.

要检查的其他事项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 have not 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 threads are associated with a request and they are operating in parallel. 在这种情况下,总线程时间就会超过已用时间。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 ascertain the critical 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
    APPINSIGHTS_PROFILERFEATURE_VERSIONAPPINSIGHTS_PROFILERFEATURE_VERSION 1.0.01.0.0
    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 详细信息”窗格。

如果你不明白 Profiler 为何不能正常工作,可以下载日志并将其发送给我们的团队 serviceprofilerhelp@microsoft.com 以获取帮助。If you can't figure out why Profiler isn't working for you, you can download the log and send it to our team for assistance, serviceprofilerhelp@microsoft.com.

手动安装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
    APPINSIGHTS_PROFILERFEATURE_VERSIONAPPINSIGHTS_PROFILERFEATURE_VERSION 1.0.01.0.0
    DiagnosticServices_EXTENSION_VERSIONDiagnosticServices_EXTENSION_VERSION ~3~3

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

目前,最多可以对同一服务计划中运行的 4 个 Azure Web 应用和部署槽启用 Profiler。Currently, you can enable Profiler on a maximum of four Azure web apps and deployment slots that are running in the same service plan. 如果在一个应用服务计划中运行的 Web 应用超过四个,则 Profiler 可能会引发 Microsoft.ServiceProfiler.Exceptions.TooManyETWSessionException。If you have more than four web apps running in one app service plan, Profiler might throw a Microsoft.ServiceProfiler.Exceptions.TooManyETWSessionException. Profiler 为每个 Web 应用单独运行,并尝试为每个应用启动 Windows 事件跟踪 (ETW) 会话。Profiler runs separately for each web app and attempts to start an Event Tracing for Windows (ETW) session for each app. 但是,可以同时处于活动状态的 ETW 会话数量有限。But a limited number of ETW sessions can be active at one time. 如果 Profiler webjob 报告活动探查会话太多,请将一些 Web 应用移到另一服务计划。If the Profiler webjob reports too many active profiling sessions, 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 DevOps 部署管道运行 Web 部署,则会发生此错误。This error occurs if you run Web Deploy from scripts or from the Azure DevOps deployment pipeline. 解决方法是将以下附加部署参数添加到 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 (1.12.2.0) 适用于所有最新版本的 App Insights SDK。The latest version of WAD (1.12.2.0) 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, do the following three things:

  1. 首先,检查部署的 Azure 诊断配置的内容是否符合预期。First, check to see whether the contents of the Azure Diagnostics configuration that are deployed are 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:

    c:\WindowsAzure\logs\Plugins\Microsoft.Azure.Diagnostics.PaaSDiagnostics\1.11.3.12\DiagnosticsPlugin.log
    

    对于云服务:For Cloud Services:

    c:\logs\Plugins\Microsoft.Azure.Diagnostics.PaaSDiagnostics\1.11.3.12\DiagnosticsPlugin.log  
    
  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:

    C:\ProgramData\ApplicationInsightsProfiler\config.json
    

    对于云服务:for Cloud Services:

    D:\ProgramData\ApplicationInsightsProfiler\config.json
    
  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 usually here:

    C:\WindowsAzure\Logs\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.17.0.6\ApplicationInsightsProfiler
    

    对于云服务:For Cloud Services:

    C:\Logs\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.17.0.6\ApplicationInsightsProfiler
    

    如果当应用程序接收请求时 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,则可能需要编辑规则以允许应用程序与 Application Insights Profiler 服务进行通信。If your application connects to the Internet via a proxy or a firewall, you may need to edit the rules to allow your application to communicate with the Application Insights Profiler service. Application Insights Profiler 使用的 IP 包含在 Azure Monitor 服务标记中。The IPs used by Application Insights Profiler are included in the Azure Monitor service tag.