使用 Azure CLI 将 Application Insights 添加到 azure 函数

Add Application Insights to an azure function with Azure CLI

我有一个 PowerShell 脚本,它使用 azure cli 按照示例 In the Microsoft Docs

但是,要启用应用程序洞察,我必须转到 Azure 门户,找到 func select 监视器,然后单击启用应用程序洞察。

我如何扩展该脚本以便为新创建的函数启用自动执行此步骤?我一直无法找到任何特定的文档或示例,如果可能,我宁愿避免使用资源模板。

当然,您可以通过 Azure CLI 为 Azure 函数启用 Application Insights。

但您需要先在门户中创建 Application Insights,目前无法通过 Azure CLI 创建 Application Insights。

您可以按照以下步骤操作。

1.Go 到门户中的 Application Insights,复制屏幕截图中的 Instrumentation Key

2.After通过您的命令创建函数应用程序,只需使用下面的 CLI 命令。

az functionapp config appsettings set --name <functionname> --resource-group <resourcegroupname> --settings 'APPINSIGHTS_INSTRUMENTATIONKEY = <Instrumentation Key>'

我这边没问题,你可以在门户网站上查看。