Azure Cli如何为Webapp启用Application Insights [英] Azure Cli How to enable Application Insights for webapp

查看:95
本文介绍了Azure Cli如何为Webapp启用Application Insights的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下代码.它创建了一个应用程序见解,然后检索了instrumentationkey并将其分配给我的webapp.

Consider the following code. It creates an application insight, then it retrieves the instrumentationkey and assigns it to my 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

但是,如屏幕截图中所示,这不会打开Web应用程序的应用程序见解.我无法弄清楚如何从蔚蓝cli中打开它.

However, this does not turn on application insight for the webapp as shown in this screen capture. I cannot figure out how to turn it on from azure cli.

推荐答案

您需要另外设置一些应用程序设置,以使其与从Azure门户启用它完全相同.我相信工具键之后的第二个重要键是 ApplicationInsightsAgent_EXTENSION_VERSION .

You need to set a couple more app settings to make it exactly like if you enabled it from the Azure Portal. I believe the second important key after the instrumentation key is ApplicationInsightsAgent_EXTENSION_VERSION.

https://docs.microsoft.com/zh-CN/azure/azure-monitor/app/azure-web-apps?tabs=net#automate-monitoring

可以适应AzureCLI的Powershell示例:

Powershell example which you can adapt to AzureCLI:

$app = Get-AzWebApp -ResourceGroupName "AppMonitoredRG" -Name "AppMonitoredSite" -ErrorAction Stop
$newAppSettings = @{} # case-insensitive hash map
$app.SiteConfig.AppSettings | %{$newAppSettings[$_.Name] = $_.Value} # preserve non Application Insights application settings.
$newAppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"] = "012345678-abcd-ef01-2345-6789abcd"; # set the Application Insights instrumentation key
$newAppSettings["APPLICATIONINSIGHTS_CONNECTION_STRING"] = "InstrumentationKey=012345678-abcd-ef01-2345-6789abcd"; # set the Application Insights connection string
$newAppSettings["ApplicationInsightsAgent_EXTENSION_VERSION"] = "~2"; # enable the ApplicationInsightsAgent
$app = Set-AzWebApp -AppSettings $newAppSettings -ResourceGroupName $app.ResourceGroup -Name $app.Name -ErrorAction Stop

这篇关于Azure Cli如何为Webapp启用Application Insights的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆