Azure / Azure/azure-cli

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

Open
#30,030 6 comments 0 reactions 2 assignees Claimed by @seligj95 View on GitHub
act-observability-squad app-service-logging-monitoring Auto-Assign customer-reported Monitor question Service Attention Similar-Issue Web Apps
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### 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](https://github.com/user-attachments/assets/a35e8005-b821-4c17-a4a3-12b92f358585)

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

```pwsh
# 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:

```pwsh
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

```sh
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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.