Azure Cli如何为webapp启用应用程序洞察

Azure Cli如何为webapp启用应用程序洞察,azure,azure-application-insights,azure-cli,azure-webapps,Azure,Azure Application Insights,Azure Cli,Azure Webapps,考虑以下代码。它创建一个application insight,然后检索instrumentationkey并将其分配给我的webapp az monitor app-insights component create -g $resourceGroup --app $webapp --application-type web --kind web --tags $defaultTags $instrumentationKey = az monitor app-insi

考虑以下代码。它创建一个application insight,然后检索instrumentationkey并将其分配给我的webapp

    az monitor app-insights component create -g $resourceGroup --app $webapp --application-type web --kind web --tags $defaultTags
    
    $instrumentationKey = az monitor app-insights component show -g $resourceGroup -a $webapp --query 'instrumentationKey' -o tsv
    az webapp config appsettings set -g $resourceGroup -n $webapp --settings APPINSIGHTS_INSTRUMENTATIONKEY=$instrumentationKey APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=$instrumentationKey
但是,这不会如本屏幕截图所示为webapp打开application insight。我不知道如何从azure cli打开它


您需要再设置几个应用程序设置,使其与从Azure门户启用的应用程序完全相同。我认为,插装键之后的第二个重要键是
ApplicationInsightsAgent\u EXTENSION\u VERSION

可适用于AzureCLI的Powershell示例:

$app=Get-AzWebApp-ResourceGroupName“AppMonitoredRG”-Name“AppMonitoredSite”-错误操作停止
$newAppSettings=@{}#不区分大小写的哈希映射
$app.SiteConfig.AppSettings |%{$newAppSettings[$\.Name]=$\.Value}保留非应用程序设置。
$newAppSettings[“APPINSIGHTS\u INSTRUMENTATIONKEY”]=“012345678-abcd-ef01-2345-6789abcd”;#设置应用程序指令插入键
$newAppSettings[“APPLICATIONINSIGHTS\u CONNECTION\u STRING”]=“InstrumentationKey=012345678-abcd-ef01-2345-6789abcd”;#设置应用程序连接字符串
$newAppSettings[“ApplicationInsightsAgent_扩展_版本”]=“~2”#启用ApplicationInsightsAgent
$app=设置AzWebApp-AppSettings$newAppSettings-ResourceGroupName$app.ResourceGroup-Name$app.Name-ErrorAction停止

使用@Alex AIT链接,提供如下cli

请注意,如果您不创建App Insights实例,则会创建并使用自动实例,这也是您可以信赖的事实

#(…)设置$plan、$resourcegroup和$region
az appservice计划创建--名称$plan--资源组$resourcegroup--位置$region--无sku
[String]$webapp=“myapp”
az webapp创建--名称$webapp--计划$plan--资源组$resourcegroup
[字符串]$appinsights=$webapp
az monitor应用程序洞察组件创建--应用程序$appinsights--位置$region--资源组$resourcegroup
#获取仪表键
#“--输出tsv”,即“以制表符分隔的值,不带键”
#用于获取未加引号的值
#如中所示https://docs.microsoft.com/en-us/cli/azure/query-azure-cli?view=azure-cli最新#获取单个值
[String]$instrumentationKey=(az监视器应用程序洞察组件显示--应用程序$appinsights--资源组$resourcegroup--查询“instrumentationKey”--输出tsv)
#配置应用程序以使用新的应用程序洞察实例
#基于https://docs.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps?tabs=net#enabling-通过powershell
az webapp config appsettings set--name$webapp--resource group$resourcegroup--settings APPINSIGHTS\u INSTRUMENTATIONKEY=$INSTRUMENTATIONKEY APPLICATIONINSIGHTS\u CONNECTION\u STRING=INSTRUMENTATIONKEY=$INSTRUMENTATIONKEY ApplicationInsightsAgent\u EXTENSION\u VERSION=~2

您能解释一下如何创建自动实例吗?