基于工作区的 Application Insights 资源Workspace-based Application Insights resources

基于工作区的资源支持 Application Insights 与 Log Analytics 之间的完全集成。Workspace-based resources support full integration between Application Insights and Log Analytics. 你现在可以选择将 Application Insights 遥测数据发送到一个公用 Log Analytics 工作区,这样就可以全权访问 Log Analytics 的所有功能,同时将应用程序、基础结构和平台日志置于单一的合并位置中。You can now choose to send your Application Insights telemetry to a common Log Analytics workspace, which allows you full access to all the features of Log Analytics while keeping application, infrastructure, and platform logs in a single consolidated location.

这样还可以跨资源实现公用的 Azure 基于角色的访问控制 (Azure RBAC),并且不再需要跨应用/工作区的查询。This also allows for common Azure role-based access control (Azure RBAC) across your resources, and eliminates the need for cross-app/workspace queries.

备注

基于工作区的 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 资源的计费。Learn more about billing for workspace-based Application Insights resources.

新功能New capabilities

基于工作区的 Application Insights 使得你可以利用 Azure Monitor 和 Log Analytics 的最新功能,其中包括:Workspace-based Application Insights allows you to take advantage of 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.

创建基于工作区的资源Create workspace-based resource

登录 Azure 门户,并创建 Application Insights 资源:Sign in to the Azure portal, and create an Application Insights resource:

基于工作区的 Application Insights 资源Workspace-based Application Insights resource

如果你还没有现有的 Log Analytics 工作区,请参阅 Log Analytics 工作区创建文档If you don't already have an existing Log Analytics Workspace, consult the Log Analytics workspace creation documentation.

创建资源后,可在“概览”窗格中看到相应的工作区信息:Once your resource is created, 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.

备注

我们仍然针对 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 query/view against the new workspace-based table structure/schema you must first navigate to your Log Analytics workspace. 从 Application Insights 窗格中选择“日志(分析)”即可访问经典 Application Insights 查询体验。Selecting Logs (Analytics) from within the Application Insights panes will give you access to the classic Application Insights query experience.

复制连接字符串Copy the connection string

连接字符串用于标识要与遥测数据关联的资源。The connection string identifies the resource that you want to associate your telemetry data with. 它还允许你修改可供你的资源将其用作遥测目标的终结点。It also allows you to modify the endpoints your resource will use as a destination for your telemetry. 你需要复制连接字符串,并将其添加到应用程序的代码或环境变量中。You will need to copy the connection string and add it to your application's code or to an environment variable.

监视配置Monitoring configuration

创建基于工作区的 Application Insights 资源后,配置监视相对简单。Once a workspace-based Application Insights resource has been created, configuring monitoring is relatively straightforward.

基于代码的应用程序监视Code-based application monitoring

对于基于代码的应用程序监视,只需安装合适的 Application Insights SDK,并将其指向新建资源的检测密钥或连接字符串。For code-based application monitoring, you would just install the appropriate Application Insights SDK and point it to the instrumentation key or connection string to your newly created resource.

若要详细了解如何设置 Application Insights SDK 以进行基于代码的监视,请参阅特定于语言/框架的文档:For detailed documentation on setting up an Application Insights SDK for code-based monitoring consult the language/framework specific documentation:

无代码监视和 Visual Studio 资源创建Codeless monitoring and Visual Studio resource creation

对于 Azure Functions 和 Azure 应用服务等服务的无代码监视,还需要先创建基于工作区的 Application Insights 资源,然后在监视配置阶段指向该资源。For codeless monitoring of services like Azure Functions and Azure App Services, you will also need to first create your workspace-based Application Insights resource and then point to that resource during the monitoring configuration phase.

尽管这些服务提供了在其自己的资源创建过程中创建新 Application Insights 资源的选项,但通过这些 UI 选项创建的资源当前仅限于经典 Application Insights 体验。While these services offer the option to create a new Application Insights resource within their own resource creation process, resources created via these UI options are currently restricted to the classic Application Insights experience.

这同样适用于 Visual Studio for ASP.NET 和 Visual Studio for ASP.NET Core 中的 Application Insights 资源创建体验。The same applies to the Application Insights resource creation experience in Visual Studio for ASP.NET and ASP.NET Core. 你必须从 Visual Studio 监视启用 UI 中选择一个基于工作区的现有资源。You must select an existing workspace-based resource from with the Visual Studio monitoring enablement UI. 选择从 Visual Studio 中创建新资源时,只能创建经典 Application Insights 资源。Selecting create new resource from within Visual Studio will limit you to creating a classic Application Insights resource.

自动创建资源Creating a resource automatically

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 create --app
                                         --location
                                         --resource-group
                                         [--application-type]
                                         [--ingestion-access {Disabled, Enabled}]
                                         [--kind]
                                         [--only-show-errors]
                                         [--query-access {Disabled, Enabled}]
                                         [--tags]
                                         [--workspace]

示例Example

az monitor app-insights component create --app demoApp --location chinaeast2 --kind web -g my_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 命令 New-AzApplicationInsights 当前不支持创建基于工作区的 Application Insights 资源。The New-AzApplicationInsights PowerShell command does not currently support creating a workspace-based Application Insights resource. 若要使用 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": "chinanorth"
        },
        "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

导出遥测Export telemetry

基于工作区的资源不支持旧版连续导出功能。The legacy continuous export functionality is not supported for workspace-based resources. 相反,请选择“诊断设置” > 从 Application Insights 资源中“添加诊断设置”。Instead, 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.

备注

遥测导出当前不额外收费。There are currently no additional charges for the telemetry export. 此功能的定价信息会在 Azure Monitor 定价页中提供。Pricing information for this feature will be available on the Azure Monitor pricing page. 开始计费之前,会发送通知。Prior to the start of billing, notifications will be sent. 如果你选择在通知期过后继续使用 ,系统会按照适用的费率计费。Should you choose to continue using after the notice period, you will be billed at the applicable rate.

后续步骤Next steps