Azure / azure-cli

Azure Command-Line Interface
MIT License
4.03k stars 3.01k forks source link

No way to turn on App Insights in a Web App through Azure CLI #30030

Open JaimeStill opened 1 month ago

JaimeStill commented 1 month ago

Describe the bug

az monitor app-insights component connect-webapp is used to link a web app to an app insights instance. However, as far as I have been able to find, there is not an automated way of turning on app insights in the web app as you can on the Azure Portal:

image

Related command

az monitor app-insights component connect-webapp

Errors

There are no errors associated, just missing functionality.

Issue script & Debug output

Currently configuring Azure Monitor as follows:

# create log analytics workspace
az monitor log-analytics workspace create `
    --name $LogWorkspace `
    --resource-group $ResourceGroup

# create app insights
az monitor app-insights component create `
    --app $AppInsights `
    --location $Location `
    --resource-group $ResourceGroup `
    --workspace $LogWorkspace

# connect webapp to app insights
az monitor app-insights component connect-webapp `
    --app $AppInsights `
    --web-app $AppName `
    --resource-group $ResourceGroup

I have tried using az webapp config appsettings to compare the webapp configuration before and after turning on Application Insights.

Adjusting the following configuration values seemed to turn on app insights, but it was not actually receiving telemetry data from my deployed web app:

az webapp config appsettings set `
    --name $AppName `
    --resource-group $ResourceGroup `
    --settings `
    ApplicationInsightsAgent_EXTENSION_VERSION=~3 `
    XDT_MicrosoftApplicationInsights_Mode=recommended `
    APPINSIGHTS_PROFILERFEATURE_VERSION=1.0.0 `
    DiagnosticServices_EXTENSION_VERSION=~3 `
    APPINSIGHTS_SNAPSHOTFEATURE_VERSION=1.0.0

Expected behavior

One of the following two scenarios:

  1. When executing az monitor app-insights component connect-webapp, this should subsequently turn on Application Insights if it is not currently.

  2. An az webapp sub-command should allow you to explicitly turn on / off application insights.

Environment Summary

azure-cli                         2.64.0

core                              2.64.0
telemetry                          1.1.0

Extensions:
application-insights               1.2.2

Dependencies:
msal                              1.30.0
azure-mgmt-resource               23.1.1

Python location '/opt/az/bin/python3'
Extensions directory '/home/jaime/.azure/cliextensions'

Python (Linux) 3.11.8 (main, Aug 28 2024, 05:45:18) [GCC 11.4.0]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

No response

yonzhan commented 1 month ago

Thank you for opening this issue, we will look into it.

github-actions[bot] commented 1 month ago

Here are some similar issues that might help you. Please check if they can solve your problem.

JaimeStill commented 1 month ago

Here are some similar issues that might help you. Please check if they can solve your problem.

* ["az functionapp create --app-insights" doesn't link Application Insights #15176](https://github.com/Azure/azure-cli/issues/15176)

These are separate issues. In my case, app insights is linked to the specified web app. There is just no way to turn on application insights through the Azure CLI after they are connected.

microsoft-github-policy-service[bot] commented 1 month ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @SameergMS, @yairgil.

microsoft-github-policy-service[bot] commented 1 month ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @AzureAppServiceCLI, @antcp.