使用 Application Insights 分析实时 Azure 云服务

Application Insights Profiler 也可以部署在以下服务上:

Application Insights Profiler 随 Azure 诊断扩展一同安装。 只需将 Azure 诊断配置为安装 Profiler 并将配置文件发送到 Application Insights 资源即可。

对 Azure 云服务启用 Profiler

  1. 请进行检查,确保使用的是 .NET Framework 4.6.1 或更新版本。 如果使用的是 OS 系列 4,则需要使用启动任务安装 .NET Framework 4.6.1 或更新版本。 默认情况下,OS 系列 5 包含 .NET Framework 的兼容版本。

  2. 将 Application Insights SDK 添加到 Azure 云服务

    云服务 WAD 中附带的探查器中的 bug 已修复。 用于云服务的最新版本的 WAD (1.12.2.0) 适用于所有最新版本的 App Insights SDK。 云服务主机将自动升级 WAD,但不会立即升级。 若要强制升级,可以重新部署服务或重新启动节点。

  3. 使用 Application Insights 跟踪请求:

  4. 配置 Azure 诊断扩展以启用 Profiler:

    a. 找到应用程序角色的 Azure 诊断 diagnostics.wadcfgx 文件,如下所示:

    Location of the diagnostics config file

    如果找不到该文件,请参阅针对 Azure 云服务和虚拟机设置诊断

    b. 添加以下 SinksConfig 部分作为 WadCfg 的子元素:

    <WadCfg>
      <DiagnosticMonitorConfiguration>...</DiagnosticMonitorConfiguration>
      <SinksConfig>
        <Sink name="MyApplicationInsightsProfiler">
          <!-- Replace with your own Application Insights instrumentation key. -->
          <ApplicationInsightsProfiler>00000000-0000-0000-0000-000000000000</ApplicationInsightsProfiler>
        </Sink>
      </SinksConfig>
    </WadCfg>
    

    注意

    如果 diagnostics.wadcfgx 文件中还包含类型为 ApplicationInsights 的其他接收器,则必须匹配以下所有三个检测密钥:

    • 应用程序使用的密钥。
    • ApplicationInsights 接收器使用的密钥。
    • ApplicationInsightsProfiler 接收器使用的密钥。

    可以在 ServiceConfiguration.*.cscfg 文件中找到 ApplicationInsights 接收器使用的实际检测密钥值。 继 Visual Studio 15.5 Azure SDK 版本之后,只有该应用程序和 ApplicationInsightsProfiler 接收器使用的检测密钥才需相互匹配。

  5. 为你的服务部署新的诊断配置,Application Insights Profiler 就可以配置为在该服务上运行了。

注意

对检测密钥引入的支持将于 2025 年 3 月 31 日结束。 检测密钥引入功能将会继续工作,但我们将不再为该功能提供更新或支持。 转换为连接字符串,以利用新功能

后续步骤

  • 生成到应用程序的流量(例如,启动可用性测试)。 然后等待 10 到 15 分钟,这样跟踪就会开始发送到 Application Insights 实例。
  • 请参阅 Azure 门户中的 Profiler 跟踪
  • 若要排查 Profiler 问题,请参阅 Profiler 故障排除