01 Run extension add command (Windows/macOS/Linux) to install the Azure Application Insights extension for Azure CLI (the command request does not produce an output):
az extension add -n application-insights
02 Run monitor app-insights component create command (Windows/macOS/Linux) using the name of the web application that you want to configure as the identifier parameter, to create the required Application Insights resource for the selected application. Microsoft Azure displays data about your application within an Application Insights resource. Creating a new resource is therefore part of setting up Application Insights to monitor your web application:
az monitor app-insights component create
--app cc-ecommerce-app
--resource-group cloud-shell-storage-eastus
--location eastus
--application-type web
03 The command output should return the information available for the new Application Insights resource. This information includes the connection string (i.e. "connectionString" attribute value) necessary to link the new Application Insights resource to the selected web application. The requested information also includes the instrumentation key (i.e. "instrumentationKey" value). The instrumentation key provides backward compatibility and can be used to enable Application Insights for legacy applications:
{
"appId": "1234abcd-1234-abcd-1234-abcd1234abcd",
"applicationId": "cc-ecommerce-app",
"applicationType": "web",
"connectionString": "InstrumentationKey=abcdabcd-1234-abcd-1234-abcdabcdabcd;IngestionEndpoint=https://eastus-6.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/",
"creationDate": "2024-02-16T09:48:47.114650+00:00",
"disableIpMasking": null,
"flowType": "Bluefield",
"hockeyAppId": null,
"hockeyAppToken": null,
"id": "/subscriptions/1234abcd-1234-abcd-1234-abcd1234abcd/resourceGroups/cloud-shell-storage-eastus/providers/microsoft.insights/components/cc-ecommerce-app",
"immediatePurgeDataOn30Days": null,
"ingestionMode": "ApplicationInsights",
"kind": "web",
"location": "eastus",
"name": "cc-ecommerce-app",
"privateLinkScopedResources": null,
"provisioningState": "Succeeded",
"publicNetworkAccessForIngestion": "Enabled",
"publicNetworkAccessForQuery": "Enabled",
"requestSource": "rest",
"resourceGroup": "cloud-shell-storage-eastus",
"instrumentationKey": "abcdabcd-1234-abcd-1234-abcdabcdabcd",
"retentionInDays": 90,
"samplingPercentage": null,
"tags": {},
"type": "microsoft.insights/components"
}
04 Define the Application Insights configuration settings that should be applied to your web application and save the settings to a JSON file named application-insights-config.json. Replace the "APPLICATIONINSIGHTS_CONNECTION_STRING" parameter value with your own connection string, returned at the previous step. This should link the new Application Insights resource with your web application. If your application requires additional parameters, add the necessary parameters to the configuration file:
[
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"slotSetting": false,
"value": "[your-connection-string]"
},
{
"name": "APPINSIGHTS_JAVASCRIPT_ENABLED",
"slotSetting": false,
"value": "true"
},
{
"name": "APPINSIGHTS_PROFILERFEATURE_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "APPINSIGHTS_SNAPSHOTFEATURE_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "ApplicationInsightsAgent_EXTENSION_VERSION",
"slotSetting": true,
"value": "~2"
},
{
"name": "DiagnosticServices_EXTENSION_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "InstrumentationEngine_EXTENSION_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "SnapshotDebugger_EXTENSION_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "XDT_MicrosoftApplicationInsights_BaseExtensions",
"slotSetting": true,
"value": "disabled"
},
{
"name": "XDT_MicrosoftApplicationInsights_Mode",
"slotSetting": true,
"value": "recommended"
}
]
05 Run webapp config appsettings set command (Windows/macOS/Linux) using the name of the web application that you want to configure as the identifier parameter to apply the Application Insights configuration settings defined at the previous step (i.e. application-insights-config.json file):
az webapp config appsettings set
--name cc-ecommerce-app
--resource-group cloud-shell-storage-eastus
--settings @application-insights-config.json
06 The command output should return the applied Application Insights settings:
[
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"slotSetting": false,
"value": "InstrumentationKey=abcdabcd-1234-abcd-1234-abcdabcdabcd;IngestionEndpoint=https://eastus-6.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"
},
{
"name": "APPINSIGHTS_JAVASCRIPT_ENABLED",
"slotSetting": false,
"value": "true"
},
{
"name": "APPINSIGHTS_PROFILERFEATURE_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "APPINSIGHTS_SNAPSHOTFEATURE_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "ApplicationInsightsAgent_EXTENSION_VERSION",
"slotSetting": true,
"value": "~2"
},
{
"name": "DiagnosticServices_EXTENSION_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "InstrumentationEngine_EXTENSION_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "SnapshotDebugger_EXTENSION_VERSION",
"slotSetting": true,
"value": "disabled"
},
{
"name": "XDT_MicrosoftApplicationInsights_BaseExtensions",
"slotSetting": true,
"value": "disabled"
},
{
"name": "XDT_MicrosoftApplicationInsights_Mode",
"slotSetting": true,
"value": "recommended"
}
]
07 Run monitor app-insights component create command (Windows/macOS/Linux) using the name of the function app that you want to configure as the identifier parameter, to create the required Application Insights resource for the selected function app:
az monitor app-insights component create
--app cc-project5-function-app
--resource-group cloud-shell-storage-eastus
--location eastus
--application-type other
08 The command output should return the information available for the new Application Insights resource. This information includes the connection string (i.e. "connectionString" attribute value) necessary to link the new Application Insights resource to the selected function app. The requested information also includes the instrumentation key (i.e. "instrumentationKey" value). The instrumentation key provides backward compatibility and can be used to enable Application Insights for legacy applications:
{
"appId": "abcd1234-abcd-1234-abcd-1234abcd1234",
"applicationId": "cc-project5-function-app",
"applicationType": "other",
"connectionString": "InstrumentationKey=abcd1234-abcd-1234-abcd-1234abcd1234;IngestionEndpoint=https://eastus-6.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/",
"creationDate": "2024-02-16T10:27:00.208449+00:00",
"disableIpMasking": null,
"flowType": "Bluefield",
"hockeyAppId": null,
"hockeyAppToken": null,
"id": "/subscriptions/abcd1234-abcd-1234-abcd-1234abcd1234/resourceGroups/cloud-shell-east-us/providers/microsoft.insights/components/cc-project5-functions-app",
"immediatePurgeDataOn30Days": null,
"ingestionMode": "ApplicationInsights",
"kind": "web",
"location": "eastus",
"name": "cc-project5-functions-app",
"privateLinkScopedResources": null,
"provisioningState": "Succeeded",
"publicNetworkAccessForIngestion": "Enabled",
"publicNetworkAccessForQuery": "Enabled",
"requestSource": "rest",
"resourceGroup": "cloud-shell-east-us",
"instrumentationKey": "abcd1234-abcd-1234-abcd-1234abcd1234",
"retentionInDays": 90,
"samplingPercentage": null,
"tags": {},
"type": "microsoft.insights/components"
}
09 Define the Application Insights configuration settings that should be applied to your function app and save the settings to a JSON file named application-insights-config.json. Replace the "APPLICATIONINSIGHTS_CONNECTION_STRING" parameter value with your own connection string, returned at the previous step. This should link the new Application Insights resource with your function app. If your application requires additional parameters, add the necessary parameters to the configuration file:
[
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"slotSetting": false,
"value": "[your-connection-string]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"slotSetting": false,
"value": "~4"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"slotSetting": false,
"value": "dotnet-isolated"
},
{
"name": "WEBSITE_USE_PLACEHOLDER_DOTNETISOLATED",
"slotSetting": false,
"value": "1"
},
{
"name": "AzureWebJobsStorage",
"slotSetting": false,
"value": "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"slotSetting": false,
"value": "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net"
},
{
"name": "WEBSITE_CONTENTSHARE",
"slotSetting": false,
"value": "cc-project5-functions-appabcd"
}
]
10 Run functionapp config appsettings set command (Windows/macOS/Linux) using the name of the function app that you want to configure as the identifier parameter to apply the Application Insights configuration settings defined at the previous step (i.e. application-insights-config.json file):
az functionapp config appsettings set
--name cc-project5-function-app
--resource-group cloud-shell-storage-eastus
--settings @application-insights-config.json
11 The command output should return the applied Application Insights settings:
[
{
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
"slotSetting": false,
"value": "InstrumentationKey=abcd1234-abcd-1234-abcd-1234abcd1234;IngestionEndpoint=https://eastus-6.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"slotSetting": false,
"value": "~4"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"slotSetting": false,
"value": "dotnet-isolated"
},
{
"name": "WEBSITE_USE_PLACEHOLDER_DOTNETISOLATED",
"slotSetting": false,
"value": "1"
},
{
"name": "AzureWebJobsStorage",
"slotSetting": false,
"value": "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net"
},
{
"name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
"slotSetting": false,
"value": "DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net"
},
{
"name": "WEBSITE_CONTENTSHARE",
"slotSetting": false,
"value": "cc-project5-functions-appabcd"
}
]
12 Repeat steps no. 2 – 11 for each Azure App Services application (including function app) that you want to configure, available in the selected subscription.
13 Repeat steps no. 2 – 12 for each subscription created in your Microsoft Azure cloud account.