Share via


為 Application Insights Profiler 和快照偵錯工具設定 BYOS

當您使用 Application Insights Profiler快照偵錯工具時,應用程式所產生的成品會透過公用網際網路,預設上傳至 Azure 儲存體帳戶。 針對這些成品和儲存體帳戶,Microsoft 會控制及承擔下列費用:

  • 處理和分析。
  • 待用加密和存留期管理原則。

同時,當您設定自備儲存體帳戶 (BYOS) 時,成品會上傳至僅由您控制及支付以下費用的儲存體帳戶:

  • 待用加密原則和存留期管理原則。
  • 網路存取:

注意

如果您要啟用 Azure Private Link 或客戶自控金鑰,則需要 BYOS。

在本指南中,您將了解如何:

  • 將診斷服務的存取權授與儲存體帳戶。
  • 連結儲存體帳戶和 Application Insights 資源。
  • 了解儲存體帳戶的存取方式。

必要條件

  • 確認您已在與 Application Insights 資源相同的位置建立儲存體帳戶。
  • 如果您已啟用 Private Link,請允許虛擬網路連線到信任的 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.

注意

如果您也使用 Private Link,則需要一個額外的設定,以允許從虛擬網路連線到信任的 Microsoft 服務。 如需詳細資訊,請參閱儲存體網路安全性文件

您有三個選項可用來設定 BYOS,以進行程式碼層級診斷,例如 Profiler 和快照偵錯工具:

  • Azure PowerShell Cmdlet
  • Azure CLI
  • Azure Resource Manager 範本

開始之前,請先安裝 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 和快照偵錯工具設定 BYOS 的常見問題解答。

如果我已啟用 Profiler/快照偵錯工具及 BYOS,資料是否會遷移至我的儲存體帳戶?

否,資料不會移轉。

BYOS 是否會使用待用加密和客戶自控金鑰?

是。 是,詳細情況為:您必須採用 BYOS,才可使用客戶自控金鑰來啟用 Profiler/快照偵錯工具。

BYOS 是否可在與網際網路隔離的環境中運作?

是。 BYOS 可在隔離的網路情況中使用。

是,可以的。

如果我已啟用 BYOS,是否可使用診斷服務儲存體帳戶,來儲存收集的資料?

是,您可以進行此動作,但目前不支援從 BYOS 進行資料移轉。

是。

如何存取我的儲存體帳戶?

  1. 在虛擬機器或 Azure App Service 中執行的代理程式,會將成品 (設定檔、快照集和符號) 上傳至帳戶中的 Blob 容器。

    此流程包含聯絡 Profiler 或快照偵錯工具,以在您的儲存體帳戶中,取得新 Blob 的共用存取簽章權杖。

  2. Profiler 和快照偵錯工具:

    • 分析傳入的 Blob。
    • 將分析結果和記錄檔寫回 Blob 儲存體。

    視可用的計算容量而定,系統可能會在上傳作業完成後隨時進行此流程。

  3. 當您檢視 Profiler 追蹤或快照偵錯工具分析時,服務會從 Blob 儲存體擷取分析結果。

下一步