你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure 应用服务中为 .NET 应用启用快照调试器

快照调试器当前支持按 Windows 服务计划在 Azure 应用服务上运行的 ASP.NET 和 ASP.NET Core 应用。

注意

建议在使用 Snapshot Debugger 时在“基本”服务层级或更高服务层级上运行应用程序。 对于大多数应用程序,“免费”和“共享”服务层没有足够的内存或磁盘空间来保存快照。 消耗层级当前不可用于 Snapshot Debugger。

启用快照调试器

预安装 Snapshot Debugger 作为应用程序服务运行时的一部分,但需启用它才能获得适用于应用服务应用的快照。 若要为应用启用 Snapshot Debugger,请遵循下面的说明:

备注

如果使用的是 .NET Core 预览版,或者应用程序引用了 Application Insights SDK(通过依赖程序集直接或间接),请按照为其他环境启用 Snapshot Debugger 的说明进行操作,将 Microsoft.ApplicationInsights.SnapshotCollector NuGet 包包含在应用程序中。

注意

Application Insights Snapshot Debugger 的无代码安装遵循 .NET Core 支持策略。 有关支持的运行时的详细信息,请参阅 .Net Core 支持策略

部署 .NET 应用后:

  1. 转到应用服务的 Azure 控制面板。

  2. 转到“设置”>“Application Insights”页。

    Screenshot showing the Enable App Insights on App Services portal.

  3. 按页面中的说明创建新资源,或者选择现有 App Insights 资源,以便监视应用。

  4. 将 Snapshot Debugger 开关切换到“启用”。

    Screenshot showing how to add App Insights site extension.

  5. 现已使用应用服务应用设置启用了快照调试器。

    Screenshot showing App Setting for Snapshot Debugger.

如果你在运行另一种类型的 Azure 服务,则下面提供了用于在其他受支持平台上启用 Snapshot Debugger 的说明:

为其他云启用 Snapshot Debugger

目前唯一需要修改终结点的区域 Azure 政府和通过 Application Insights 连接字符串由世纪互联运营的 Microsoft Azure

连接字符串属性 美国政府云 中国云
SnapshotEndpoint https://snapshot.monitor.azure.us https://snapshot.monitor.azure.cn

若要详细了解其他连接替代,请参阅 Application Insights 文档

为快照引入启用 Microsoft Entra 身份验证

Application Insights Snapshot Debugger 支持快照引入进行 Microsoft Entra 身份验证。 这意味着,要引入应用程序的所有快照,你的应用程序必须经过身份验证并向 Snapshot Debugger 代理提供所需的应用程序设置。

到目前为止,只有当你的应用程序中使用 Application Insights Profiler 来引用和配置 Microsoft Entra ID 时,Snapshot Debugger 才支持 Microsoft Entra 身份验证。

要为快照引入启用 Microsoft Entra ID,请执行以下操作:

  1. 创建你要用于对 Application Insights 资源进行身份验证的托管标识并将其添加到你的应用服务。

    1. 对于系统分配的托管标识,请参阅以下文档

    2. 对于用户分配的托管标识,请参阅以下文档

  2. 在 Application Insights 资源中配置并启用 Microsoft Entra ID。 有关详细信息,请参阅以下文档

  3. 添加以下应用程序设置,用于让 Snapshot Debugger 代理知道要使用哪个托管标识:

对于系统分配的标识:

应用设置
APPLICATIONINSIGHTS_AUTHENTICATION_STRING Authorization=AD

对于用户分配的标识:

应用设置
APPLICATIONINSIGHTS_AUTHENTICATION_STRING Authorization=AD;ClientID={用户分配的标识的客户端 ID}

禁用快照调试器

若要禁用 Snapshot Debugger,请重复执行启用步骤。 但是,请将 Snapshot Debugger 开关切换到“禁用”。

Azure 资源管理器模板

对于 Azure 应用服务,可在 Azure 资源管理器模板中设置应用设置,以启用 Snapshot Debugger 和 Profiler。 例如:

{
  "apiVersion": "2015-08-01",
  "name": "[parameters('webSiteName')]",
  "type": "Microsoft.Web/sites",
  "location": "[resourceGroup().location]",
  "dependsOn": [
    "[variables('hostingPlanName')]"
  ],
  "tags": { 
    "[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName')))]": "empty",
    "displayName": "Website"
  },
  "properties": {
    "name": "[parameters('webSiteName')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "appsettings",
      "type": "config",
      "dependsOn": [
        "[parameters('webSiteName')]",
        "[concat('AppInsights', parameters('webSiteName'))]"
      ],
      "properties": {
        "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', concat('AppInsights', parameters('webSiteName'))), '2014-04-01').InstrumentationKey]",
        "APPINSIGHTS_PROFILERFEATURE_VERSION": "1.0.0",
        "APPINSIGHTS_SNAPSHOTFEATURE_VERSION": "1.0.0",
        "DiagnosticServices_EXTENSION_VERSION": "~3",
        "ApplicationInsightsAgent_EXTENSION_VERSION": "~2"
      }
    }
  ]
},

不支持的场景

可以在下面找到不支持 Snapshot Collector 的场景:

方案 副作用 建议
在应用程序 (.csproj) 中直接使用 Snapshot Collector SDK 并且已启用高级选项“互操作”。 本地 Application Insights SDK(包括 Snapshot Collector 遥测)将丢失,并且将没有快照可用。
应用程序在启动 System.ArgumentException: telemetryProcessorTypedoes not implement ITelemetryProcessor. 时可能会崩溃
详细了解 Application Insights 功能“互操作”。
如果使用高级选项“互操作”,请使用无代码 Snapshot Collector 注入(通过 Azure 门户启用)。

后续步骤

  • 为应用程序生成可触发异常的流量。 然后等待 10 到 15 分钟,这样快照就会发送到 Application Insights 实例。
  • 请参见 Azure 门户中的快照
  • 排查 Snapshot Debugger 问题时如需帮助,请参阅 Snapshot Debugger 故障排除