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
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.