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

为 Application Insights Profiler 和 Snapshot Debugger 配置 BYOS

当你使用 Application Insights ProfilerSnapshot Debugger 时,默认情况下,应用程序生成的项目将通过公共 Internet 上传到 Azure 存储帐户。 对于这些项目和存储帐户,Microsoft 控制并承担以下费用:

  • 处理和分析。
  • 静态加密和生存期管理策略。

同时,配置自己的存储帐户 (BYOS) 时,项目将上传到只有你控制和支付以下费用的存储帐户中:

  • 静态加密策略和生存期管理策略。
  • 网络访问。

备注

如果要启用 Azure 专用链接或客户管理的密钥,则需要 BYOS。

本指南介绍如何:

  • 向诊断服务授予对你的存储帐户的访问权限。
  • 将存储帐户链接到你的 Application Insights 资源。
  • 了解如何访问存储帐户。

先决条件

  • 验证你是否已在与 Application Insights 资源相同的位置创建了存储帐户。
  • 如果启用了专用链接,请允许从你的虚拟网络连接到我们的受信任的 Microsoft 服务。

向诊断服务授予对你的存储帐户的访问权限

BYOS 存储帐户链接到 Application Insights 资源。 首先,通过存储帐户中的访问控制 (IAM) 页将 Storage Blob Data Contributor 角色授予名为 Diagnostic Services Trusted Storage Access 的 Microsoft Entra 应用程序。

  1. 选择“访问控制 (IAM)”。

  2. 选择“添加”>“添加角色分配”,打开“添加角色分配”页面 。

  3. 分配以下角色。

    设置
    角色 存储 Blob 数据参与者
    将访问权限分配到 用户、组或服务主体
    成员 诊断服务受信任的存储访问

    Screenshot that shows the Add role assignment page in the Azure portal.

    分配后,可以在“角色分配”部分下看到该角色。 Screenshot that shows the IAM screen after Role assignments.

注意

如果你还使用了专用链接,则还需要完成一项配置,以允许从你的虚拟网络连接到我们的受信任 Microsoft 服务。 有关详细信息,请参阅存储网络安全文档

有三个选项可用于为代码级诊断(如 Profiler 和 Snapshot Debugger)配置 BYOS:

  • Azure PowerShell cmdlet
  • Azure CLI
  • Azure 资源管理器模板

在开始之前,请安装 Azure PowerShell 4.2.0 或更高版本

  1. 安装 Application Insights PowerShell 扩展。

    Install-Module -Name Az.ApplicationInsights -Force
    
  2. 使用 Azure 帐户订阅登录。

    Connect-AzAccount -Subscription "{subscription_id}"
    

    有关如何登录的详细信息,请参阅 Connect-AzAccount 文档

  3. 删除已链接到 Application Insights 资源的任何之前的存储帐户。

    模式:

    Get-AzApplicationInsights -ResourceGroupName "{resource_group_name}" -Name "{application_insights_name}" | Remove-AzApplicationInsightsLinkedStorageAccount
    

    示例:

    Get-AzApplicationInsights -ResourceGroupName "byos-test" -Name "byos-test-westus2-ai" | Remove-AzApplicationInsightsLinkedStorageAccount
    
  4. 将你的存储帐户连接到 Application Insights 资源。

    模式:

    $storageAccount = Get-AzStorageAccount -ResourceGroupName "{resource_group_name}" -Name "{storage_account_name}"
    Get-AzApplicationInsights -ResourceGroupName "{resource_group_name}" -Name "{application_insights_name}" | New-AzApplicationInsightsLinkedStorageAccount -LinkedStorageAccountResourceId $storageAccount.Id
    

    示例:

    $storageAccount = Get-AzStorageAccount -ResourceGroupName "byos-test" -Name "byosteststoragewestus2"
    Get-AzApplicationInsights -ResourceGroupName "byos-test" -Name "byos-test-westus2-ai" | New-AzApplicationInsightsLinkedStorageAccount -LinkedStorageAccountResourceId $storageAccount.Id
    

疑难解答

本部分提供有关配置 BYOS 时常见问题的故障排除提示。

场景:不支持模板架构“{schema_uri}”

收到类似于以下示例的错误:

New-AzResourceGroupDeployment : 11:53:49 AM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'Template schema
'https://schema.management.azure.com/schemas/2020-01-01/deploymentTemplate.json#' is not supported. Supported versions are
'2014-04-01-preview,2015-01-01,2018-05-01,2019-04-01,2019-08-01'. Please see https://aka.ms/arm-template for usage details.'.

解决方案

  • 确保模板的 $schema 属性有效。 它必须遵循此模式:

    https://schema.management.azure.com/schemas/{schema_version}/deploymentTemplate.json#
    
  • 确保模板的 schema_version 在有效值的范围内:2014-04-01-preview, 2015-01-01, 2018-05-01, 2019-04-01, 2019-08-01

场景:在位置“{location}”处找不到任何已注册的资源提供程序

收到类似于以下示例的错误:

New-AzResourceGroupDeployment : 6:18:03 PM - Resource microsoft.insights/components 'byos-test-westus2-ai' failed with message '{
  "error": {
    "code": "NoRegisteredProviderFound",
    "message": "No registered resource provider found for location 'westus2' and API version '2020-03-01-preview' for type 'components'. The supported api-versions are '2014-04-01,
2014-08-01, 2014-12-01-preview, 2015-05-01, 2018-05-01-preview'. The supported locations are ', eastus, southcentralus, northeurope, westeurope, southeastasia, westus2, uksouth,
canadacentral, centralindia, japaneast, australiaeast, koreacentral, francecentral, centralus, eastus2, eastasia, westus, southafricanorth, northcentralus, brazilsouth, switzerlandnorth,
australiasoutheast'."
  }
}'

解决方案

  • 确保资源 microsoft.insights/componentsapiVersion2015-05-01
  • 确保资源 linkedStorageAccountapiVersion2020-03-01-preview

场景:存储帐户位置应与 Application Insights 组件位置匹配

收到类似于以下示例的错误:

New-AzResourceGroupDeployment : 1:01:12 PM - Resource microsoft.insights/components/linkedStorageAccounts 'byos-test-centralus-ai/serviceprofiler' failed with message '{
  "error": {
    "code": "BadRequest",
    "message": "Storage account location should match AI component location",
    "innererror": {
      "trace": [
        "System.ArgumentException"
      ]
    }
  }
}'

解决方案

确保 Application Insights 资源的位置与存储帐户的位置相同。

常见问题

本部分提供有关为 Profiler 和 Snapshot Debugger 配置 BYOS 的常见问题的解答。

如果我启用了 Profiler/Snapshot Debugger 和 BYOS,我的数据会迁移到我的存储帐户吗?

不会。

BYOS 是否兼容静态加密和客户管理的密钥?

是的。 准确地说,BYOS 是启用 Profiler/Snapshot Debugger 和客户管理的密钥的要求。

BYOS 是否可在与 Internet 隔离的环境中工作?

是的。 BYOS 是隔离网络方案的要求。

是的,有可能。

如果我启用了 BYOS,可以重新使用诊断服务存储帐户来存储我收集的数据吗?

是的,你可以,但我们目前不支持从你的 BYOS 迁移数据。

是的。

如何访问我的存储帐户?

  1. 在虚拟机或 Azure 应用服务中运行的代理会将项目(配置文件、快照和符号)上传到你的帐户中的 Blob 容器。

    此过程涉及到联系 Profiler 或 Snapshot Debugger,以获取一个共享访问签名令牌,用于访问存储帐户中的新 Blob。

  2. Profiler 或 Snapshot Debugger:

    • 分析传入的 Blob。
    • 将分析结果和日志文件写回 Blob 存储。

    根据可用的计算容量,此过程可能在上传后随时发生。

  3. 查看 Profiler 跟踪或 Snapshot Debugger 分析时,服务将从 Blob 存储提取分析结果。

后续步骤