Determine if appinsight is enabled on appservice

Copper Contributor

Good day, 

I'm trying to find a way to establish if a given appservice or function app has application insight enabled or not, I can easily check it trough the portal, but I would like to do it programmatically via cli (either az cli, or powershell, or rest api), but I cannot find the proper way to do it, so to recap, given an app service I would like to execute a command that returns whether application insight is on or not on the specific app service.

 

Any help will be appreciated 

 

Thanks 

 

M. 

4 Replies

To use the Azure API Management REST API to check if Application Insights is enabled for an Azure App Service (including Function Apps), you can follow these steps:
Get the Subscription ID and Resource Group Name:
You'll need the Subscription ID and Resource Group Name where your Azure App Service is located.

Get the Azure App Service ID:
You'll need the ID of your Azure App Service. You can find this by navigating to the Azure portal, selecting your App Service, and copying the ID from the URL. It will look something like this:
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{appName}

Get the Application Insights Component ID:
You'll need the ID of the Application Insights component associated with your App Service. You can find this in the Azure portal by navigating to your App Service, selecting "Application Insights" under Monitoring, and copying the Instrumentation Key from the overview page. The Instrumentation Key is part of the Application Insights Component ID.

Check if Application Insights is Enabled:
Use the Azure API Management REST API to check if Application Insights is enabled for your App Service. You can do this by making a GET request to the following endpoint:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/p...

Replace {subscriptionId}, {resourceGroupName}, and {appInsightsComponentId} with your Subscription ID, Resource Group Name, and Application Insights Component ID, respectively.

If the GET request returns a successful response (200 OK), it means Application Insights is enabled for your App Service.
Please note that you'll need to authenticate your API requests using Azure AD credentials with appropriate permissions to access the Azure API Management API.

Hello Senthil,
thanks for your reply what you describe makes sense, but in my case I do not want to interact with the portal, and I do not know in advance the name/details of the appinsight component.

From the portal I can see that if I select an app service. there is an appinsight section , so I would like to find a way to get the same information via cli/api ; so to recap I have an app service with full details /(name , resource group , id) I want to know if this app service has an active appinsight.
I'm actively checking for a solution so If I'll be able to find a solution I'll post an update
thank you
M.

You can use the Azure CLI or Azure Resource Manager (ARM) templates to query the resources associated with your App Service. Here's a general approach to determine if an App Service has an active Application Insights component:

Use Azure CLI to list resources: First, list the resources associated with your App Service using the Azure CLI. You can filter the results to include only resources related to Application Insights.

az resource list --tag Microsoft.Web/serverFarmId="<app_service_id>"
Replace <app_service_id> with the ID of your App Service.

Check for Application Insights resource: Look for an Application Insights resource in the list of resources returned by the command. If an Application Insights resource is listed, it indicates that your App Service is linked to an active Application Insights component.

If no Application Insights resource is found, it means that your App Service does not have an active Application Insights component associated with it.

Automate the process: You can automate this process using scripts or Azure Automation to regularly check the status of Application Insights for your App Services.

Note: This approach assumes that the Application Insights component is directly linked to the App Service. If the linking is done at a higher level (e.g., through an Azure Resource Manager template), additional steps may be required to determine the association.

Hello,
I just want to share ea response I had from official azure support :
the presence of the application/function setting like :
"APPINSIGHTS_INSTRUMENTATIONKEY" is sufficient to say that the webapp/function
qil ltry to send metrics to appinsight , clearly if the value is wrong it will not work, but the presence of the setting will trigger the runtime to activate application insights.

hope it is useful for everyone

M.