代码之家  ›  专栏  ›  技术社区  ›  mattruma

从azure cli向webapp或functionapp添加appinsights支持

  •  2
  • mattruma  · 技术社区  · 6 年前

    是否有方法从 azure-cli ?

    现在翻阅文件。

    2 回复  |  直到 6 年前
        1
  •  1
  •   Joy Wang    6 年前

    我以前也考虑过你的问题。要创建应用程序洞察,似乎 az resource create 将是目前唯一可能的方式,正如在另一个答案中提到的。但我不确定它是否100%有效,你可以试试。

    要激活webapp或functionapp的application insight,只需添加一个名为 APPINSIGHTS_INSTRUMENTATIONKEY 应用程序设置 关于webapp或functionapp。只要使用下面的命令,我这边就可以了。

    #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"
    

    试验样品 (Web应用的结果相同):

    enter image description here 签入门户 :

    enter image description here

        2
  •  1
  •   Lloyd Smith    5 年前

    当前存在通过cli创建app insights资源的开放问题 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"}'
    

    ================================================================

    根据最新的cli文档( https://docs.microsoft.com/en-us/cli/azure/ext/application-insights/monitor/app-insights?view=azure-cli-latest ,您可以使用以下命令创建新的app insight资源

    az monitor app-insights component create --app demoApp --location westus2 --kind web -g demoRg --application-type web