从azure-cli向WebApp或FunctionApp添加AppInsights支持

时间:2018-11-05 12:25:10

标签: azure-web-sites azure-functions azure-application-insights azure-cli

是否可以通过azure-cli为WebApp或FunctionApp创建和/或激活AppInsights?

现在浏览文档。

2 个答案:

答案 0 :(得分:1)

通过cli https://github.com/Azure/azure-cli/issues/5543

创建应用洞察资源目前存在一个未解决的问题

您可以看到用户正在像现在这样创建它们

az resource create \
    --resource-group $RESOURCE_GROUP \
    --resource-type "Microsoft.Insights/components" \
    --name $NAMESPACE_PREFIX-appinsights \
    --location $PRIMARY_LOCATION \
    --properties '{"ApplicationId":"facerecognition","Application_Type":"other", "Flow_Type":"Redfield", "Request_Source":"IbizaAIExtension"}'

答案 1 :(得分:1)

我之前也曾考虑过您的问题。要创建应用程序见解,似乎az resource create将是当前另一种答案中提到的唯一可行方法。但是我不确定它是否100%有效,您可以尝试一下。

要激活WebApp或FunctionApp的应用程序见解,我们只需在WebApp或FunctionApp的应用程序设置中添加一个名为APPINSIGHTS_INSTRUMENTATIONKEY的设置。只需使用下面的命令,它对我来说就可以正常工作。

#retrive the InstrumentationKey of your application insight
$key = az resource show -g <resource group name> -n <appinsight name> --resource-type "Microsoft.Insights/components" --query properties.InstrumentationKey

#set the application insight for function app
az functionapp config appsettings set -g <resource group name> -n <function app name> --settings "APPINSIGHTS_INSTRUMENTATIONKEY = $key"

#set the application insight for web app
az webapp config appsettings set -g <resource group name> -n <web app name> --settings "APPINSIGHTS_INSTRUMENTATIONKEY = $key"

测试样本(网络应用的结果相同):

enter image description here 签入门户网站

enter image description here