迁移到基于工作区的 Application Insights 资源Migrate to workspace-based Application Insights resources

本指南将指导你完成将经典 Application Insights 资源迁移到基于工作区的资源的过程。This guide will walk you through the process of migrating a classic Application Insights resource to a workspace-based resource. 基于工作区的资源支持 Application Insights 与 Log Analytics 之间的完全集成。Workspace-based resources support full integration between Application Insights and Log Analytics. 基于工作区的资源将 Application Insights 遥测数据发送到一个公用 Log Analytics 工作区,这样你就能够访问 Azure Monitor 的最新功能,同时将应用程序、基础结构和平台日志置于单一的合并位置中。Workspace-based resources send Application Insights telemetry to a common Log Analytics workspace, which allows you to access the latest features of Azure Monitor while keeping application, infrastructure, and platform logs in a single consolidated location.

基于工作区的资源允许跨资源进行常用的 Azure 基于角色的访问控制 (Azure RBAC),不再需要跨应用/工作区进行查询。Workspace-based resources enables common Azure role-based access control (Azure RBAC) across your resources, and eliminates the need for cross-app/workspace queries.

新功能New capabilities

基于工作区的 Application Insights 使得你可以利用 Azure Monitor 和 Log Analytics 的所有最新功能,其中包括:Workspace-based Application Insights allows you to take advantage of all the latest capabilities of Azure Monitor and Log Analytics including:

  • 客户管理的密钥 (CMK) 为你的数据提供静态加密,并提供只有你有权访问的加密密钥。Customer-Managed Keys (CMK) provides encryption at rest for your data with encryption keys that only you have access to.
  • 使用产能预留层可以节省 25% 的成本(与即用即付价格相比)。Capacity Reservation tiers enable you to save as much as 25% compared to the Pay-As-You-Go price.
  • 可以通过 Log Analytics 流引入提高数据引入速度。Faster data ingestion via Log Analytics streaming ingestion.

迁移过程Migration process

迁移到基于工作区的资源时,不会将任何数据从经典资源的存储传输到新的基于工作区的存储。When you migrate to a workspace-based resource, no data is transferred from your classic resource's storage to the new workspace-based storage. 而选择迁移则会将新数据的写入位置更改为 Log Analytics 工作区,同时保留对经典资源数据的访问权限。Choosing to migrate will instead change the location where new data is written to a Log Analytics workspace while preserving access to your classic resource data.

你的经典资源数据将持久保存,并受针对经典 Application Insights 资源的保留设置制约。Your classic resource data will persist and be subject to the retention settings on your classic Application Insights resource. 在迁移后引入的所有新数据会受关联的 Log Analytics 工作区的保留设置制约,该工作区还支持按数据类型确定的不同保留设置All new data ingested post migration will be subject to the retention settings of the associated Log Analytics workspace, which also supports different retention settings by data type. 迁移过程是永久性的,无法撤消。The migration process is permanent, and cannot be reversed. 将资源迁移到基于工作区的 Application Insights 后,它将始终是基于工作区的资源。Once you migrate a resource to workspace-based Application Insights, it will always be a workspace-based resource. 但是,在迁移后,可以根据需要随时更改目标工作区。However, once you migrate you are able to change the target workspace as often as needed.

备注

基于工作区的 Application Insights 资源的数据引入和保留操作通过数据所在的 Log Analytics 工作区计费Data ingestion and retention for workspace-based Application Insights resources are billed through the Log Analytics workspace where the data is located. 如果在迁移之前选择了将引入经典 Application Insights 资源的数据保留 90 天以上,则数据保留将继续通过该 Application Insights 资源计费。If you’ve selected data retention greater than 90 days on data ingested into the Classic Application Insights resource prior to migration, data retention will continue to be billed to through that Application Insights resource. 详细了解基于工作区的 Application Insights 资源的计费。Learn more about billing for workspace-based Application Insights resources.

如果不需要迁移现有资源,但是想要创建新的基于工作区的 Application Insights 资源,请使用基于工作区的资源创建指南If you don't need to migrate an existing resource, and instead want to create a new workspace-based Application Insights resource use the workspace-based resource creation guide.

先决条件Pre-requisites

  • 一个 Log Analytics 工作区,且其访问控制模式需要设为“use resource or workspace permissions”设置。A Log Analytics workspace with the access control mode set to the use resource or workspace permissions setting.

  • 基于工作区的资源不支持连续导出,必须禁用此功能。Continuous export is not supported for workspace-based resources and must be disabled. 迁移完成后,可以使用诊断设置配置到存储帐户的数据存档或到 Azure 事件中心的流式传输。Once the migration is complete, you can use diagnostic settings to configure data archiving to a storage account or streaming to Azure Event Hub.

  • 在你的 Log Analytics 工作区的“常规” > “使用情况和预估成本” > “数据保留”下检查当前保留设置。 Check your current retention settings under General > Usage and estimated costs > Data Retention for your Log Analytics workspace. 此设置会影响迁移 Application Insights 资源后新引入数据的存储时间。This setting will impact how long any new ingested data is stored once you migrate your Application Insights resource. 如果你目前存储 Application Insights 数据的时间超过默认的 90 天,想要保留这个较长的保留期,则可能需要调整工作区保留设置。If you currently store Application Insights data for longer than the default 90 days and want to retain this larger retention period, you may need to adjust your workspace retention settings.

迁移资源Migrate your resource

本部分将指导你完成将经典 Application Insights 资源迁移到新的基于工作区的资源类型的过程。This section will walk you through the process of migrating a classic Application Insights resource to the new workspace-based resource type.

  1. 在 Application Insights 资源的左侧菜单栏中的“配置”标题下选择“属性”。From your Application Insights resource, select Properties under the Configure heading in the left-hand menu bar.

    在红色框中突出显示的属性

  2. 选择 Migrate to Workspace-basedSelect Migrate to Workspace-based.

    “迁移资源”按钮

  3. 选择要用来存储将来引入的所有 Application Insights 遥测数据的 Log Analytics 工作区。Choose the Log Analytics Workspace where you want all future ingested Application Insights telemetry to be stored.

    迁移向导 UI,其中显示了用于选择目标工作区的选项

迁移资源后,可在“概述”窗格中看到相应的工作区信息:Once your resource is migrated, you will see the corresponding workspace info in the Overview pane:

工作区名称

单击蓝色链接文本会转到关联的 Log Analytics 工作区,你可以在其中利用新的统一工作区查询环境。Clicking the blue link text will take you to the associated Log Analytics workspace where you can take advantage of the new unified workspace query environment.

了解日志查询Understanding log queries

我们仍然针对 Application Insights 体验中的 Application Insights 经典资源查询、工作簿和基于日志的警报提供完全的后向兼容性。We still provide full backwards compatibility for your Application Insights classic resource queries, workbooks, and log-based alerts within the Application Insights experience.

若要根据新的基于工作区的表结构/架构编写查询,必须先导航到 Log Analytics 工作区。To write queries against the new workspace-based table structure/schema, you must first navigate to your Log Analytics workspace.

从工作区中的 Log Analytics UI 直接进行查询时,你只会看到迁移后引入的数据。When you query directly from the Log Analytics UI within your workspace, you will only see the data that is ingested post migration. 若要在统一查询体验中查看经典 Application Insights 数据和迁移后引入的新数据,请从迁移后的 Application Insights 资源中使用“日志(分析)”查询视图。To see both your classic Application Insights data + new data ingested after migration in a unified query experience use the Logs (Analytics) query view from within your migrated Application Insights resource.

编程化资源迁移Programmatic resource migration

Azure CLIAzure CLI

若要访问预览版 Application Insights Azure CLI 命令,首先需要运行以下命令:To access the preview Application Insights Azure CLI commands, you first need to run:

 az extension add -n application-insights

如果不运行 az extension add 命令,则会看到一条错误消息,指出:az : ERROR: az monitor: 'app-insights' is not in the 'az monitor' command group. See 'az monitor --help'.If you don't run the az extension add command, you will see an error message that states: az : ERROR: az monitor: 'app-insights' is not in the 'az monitor' command group. See 'az monitor --help'.

现在,可以运行以下命令来创建 Application Insights 资源:Now you can run the following to create your Application Insights resource:

az monitor app-insights component update --app
                                         --resource-group
                                         [--ingestion-access {Disabled, Enabled}]
                                         [--kind]
                                         [--query-access {Disabled, Enabled}]
                                         [--retention-time]
                                         [--workspace]

示例Example

az monitor app-insights component update --app your-app-insights-resource-name -g your_resource_group --workspace "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/test1234/providers/microsoft.operationalinsights/workspaces/test1234555"

有关此命令的完整 Azure CLI 文档,请参阅 Azure CLI 文档For the full Azure CLI documentation for this command, consult the Azure CLI documentation.

Azure PowerShellAzure PowerShell

PowerShell 命令 Update-AzApplicationInsights 当前不支持将经典 Application Insights 资源迁移到基于工作区的资源。The Update-AzApplicationInsights PowerShell command does not currently support migrating a classic Application Insights resource to workspace-based. 若要使用 PowerShell 创建基于工作区的资源,可以使用以下 Azure 资源管理器模板,并使用 PowerShell 进行部署。To create a workspace-based resource with PowerShell, you can use the Azure Resource Manager templates below and deploy with PowerShell.

Azure 资源管理器模板Azure Resource Manager templates

模板文件Template file

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string"
        },
        "type": {
            "type": "string"
        },
        "regionId": {
            "type": "string"
        },
        "tagsArray": {
            "type": "object"
        },
        "requestSource": {
            "type": "string"
        },
        "workspaceResourceId": {
            "type": "string"
        }
    },
    "resources": [
        {
            "name": "[parameters('name')]",
            "type": "microsoft.insights/components",
            "location": "[parameters('regionId')]",
            "tags": "[parameters('tagsArray')]",
            "apiVersion": "2020-02-02-preview",
            "properties": {
                "ApplicationId": "[parameters('name')]",
                "Application_Type": "[parameters('type')]",
                "Flow_Type": "Redfield",
                "Request_Source": "[parameters('requestSource')]",
                "WorkspaceResourceId": "[parameters('workspaceResourceId')]"
            }
        }
    ]
}

参数文件Parameters file

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "type": {
            "value": "web"
        },
        "name": {
            "value": "customresourcename"
        },
        "regionId": {
            "value": "chinaeast2"
        },
        "tagsArray": {
            "value": {}
        },
        "requestSource": {
            "value": "Custom"
        },
        "workspaceResourceId": {
            "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my_resource_group/providers/microsoft.operationalinsights/workspaces/myworkspacename"
        }
    }
}

修改关联的工作区Modifying the associated workspace

创建基于工作区的 Application Insights 资源后,可以修改关联的 Log Analytics 工作区。Once a workspace-based Application Insights resource has been created, you can modify the associated Log Analytics Workspace.

从 Application Insights 资源窗格中,选择“属性” > “更改工作区” > “Log Analytics 工作区”。 From within the Application Insights resource pane, select Properties > Change Workspace > Log Analytics Workspaces.

疑难解答Troubleshooting

访问模式Access mode

错误消息: 所选工作区配置为基于工作区的访问模式。某些 APM 功能可能会受影响。请选择其他工作区或在工作区设置中允许基于资源的访问权限。可以使用 CLI 解决此错误。Error message: The selected workspace is configured with workspace-based access mode. Some APM features may be impacted. Select another workspace or allow resource-based access in the workspace settings. You can override this error by using CLI.

为了使基于工作区的 Application Insights 资源正常运行,你需要将目标 Log Analytics 工作区的访问控制模式更改为资源或工作区权限设置。In order for your workspace-based Application Insights resource to operate properly you need to change the access control mode of your target Log Analytics workspace to the resource or workspace permissions setting. 此设置位于 Log Analytics 工作区 UI 中的“属性” > “访问控制模式”下。This setting is located in the Log Analytics workspace UI under Properties > Access control mode. 有关详细说明,请参阅 Log Analytics 配置访问控制模式指南For detailed instructions, consult the Log Analytics configure access control mode guidance. 如果访问控制模式设置为独占的“需要工作区权限”设置,则通过门户迁移体验进行的迁移会保持被阻止状态。If your access control mode is set to the exclusive Require workspace permissions setting, migration via the portal migration experience will remain blocked.

如果由于安全原因而无法为当前目标工作区更改访问控制模式,建议你创建新的用于迁移的 Log Analytics 工作区。If you cannot change the access control mode for security reasons for your current target workspace, we recommend creating a new Log Analytics workspace to use for the migration.

连续导出Continuous export

错误消息: 在继续操作之前,需要禁用连续导出。迁移后,请使用“诊断设置”进行导出。Error message: Continuous Export needs to be disabled before continuing. After migration, use Diagnostic Settings for export.

基于工作区的资源不支持旧版连续导出功能。The legacy continuous export functionality is not supported for workspace-based resources. 在迁移之前,需要禁用连续导出。Prior to migrating you need to disable continuous export.

  1. 在 Application Insights 资源视图的“配置”标题下,选择“连续导出”。From your Application Insights resource view, under the Configure heading select Continuous Export.

    “连续导出”菜单项

  2. 选择“禁用”。Select Disable.

    连续导出禁用按钮

  • 选择“禁用”后,可以导航回迁移 UI。Once you have selected disable, you can navigate back to the migration UI. 如果“编辑连续导出”页提示你的设置不会保存,你可以针对此提示选择“确定”,因为它与禁用/启用连续导出无关。If the edit continuous export page prompts you that your settings won't be saved, you can select ok for this prompt as it does not pertain to disabling/enabling continuous export.

  • 将 Application Insights 资源成功迁移到基于工作区的资源后,可以使用“诊断设置”来替换连续导出过去提供的功能。Once you have successfully migrated your Application Insights resource to workspace-based, you can use Diagnostic settings to replace the functionality that continuous export used to provide. 请从你的 Application Insights 资源中选择“诊断设置” > “添加诊断设置”。 Select Diagnostic settings > add diagnostic setting from within your Application Insights resource. 可以选择所有表,或是要存档到存储帐户或流式传输到 Azure 事件中心的表的子集。You can select all tables, or a subset of tables to archive to a storage account, or to stream to an Azure Event Hub. 有关诊断设置的详细指南,请参阅 Azure Monitor 诊断设置指南For detailed guidance on diagnostic settings, refer to the Azure Monitor diagnostic settings guidance.

保留设置Retention settings

警告消息:你的自定义 Application Insights 保留设置不会应用于发送到工作区的数据。你需要单独重新配置此设置。Warning Message: Your customized Application Insights retention settings will not apply to data sent to the workspace. You will need to reconfigure this separately.

在迁移之前无需进行任何更改,但此消息提醒你当前的 Application Insights 保留设置未设置为默认的 90 天保留期。You don't have to make any changes prior to migrating, but this message is to alert you that your current Application Insights retention settings are not set to the default 90-day retention period. 此警告消息表示,你可能需要在迁移和开始引入新数据之前修改 Log Analytics 工作区的保留设置。This warning message means you may want to modify the retention settings for your Log Analytics workspace prior to migrating and starting to ingest new data.

你可以在 Log Analytics UI 的“常规” > “使用情况和预估成本” > “数据保留”下检查 Log Analytics 的当前保留设置。 You can check your current retention settings for Log Analytics under General > Usage and estimated costs > Data Retention from within the Log Analytics UI. 此设置会影响迁移 Application Insights 资源后新引入数据的存储时间。This setting will impact how long any new ingested data is stored once you migrate your Application Insights resource.

后续步骤Next steps