Description:

Application Insights is an Azure service that provides performance monitoring, application health tracking, and real-time diagnostics for your web applications. It helps you detect and diagnose issues with your applications, track application performance, and analyze usage patterns. Enabling Application Insights ensures that your applications are continuously monitored for performance bottlenecks, exceptions, and other issues, offering real-time analytics and actionable insights.

Configuring Application Insights is essential for any production application, especially for identifying operational issues, performance degradation, or user behavior that could impact the application's overall performance or user experience.

Rationale:

Enabling Application Insights for your applications provides crucial visibility into application performance and usage. It can automatically capture telemetry data such as:

  • Request rates.

  • Response times.

  • Failure rates.

  • Dependencies (e.g., database queries, API calls).

  • Exceptions and errors.

  • User activity and usage patterns.

It allows you to detect issues proactively and make informed decisions for improving the application’s health and user experience.

Impact:

Enabling Application Insights for your applications significantly improves observability and monitoring, enabling rapid issue detection. However, it may increase costs based on the amount of telemetry data collected, the retention period of that data, and the frequency of queries or dashboards. It's essential to configure retention policies and monitor usage to ensure that costs are controlled.

Default Value:

By default, Application Insights is not enabled for Azure applications unless explicitly configured.

Pre-requisites:

  • Azure subscription.

  • Owner, Contributor, or Monitoring Contributor permissions.

  • Web applications or services hosted in Azure (e.g., Azure App Services, Virtual Machines, or Azure Functions).

  • Log Analytics workspace (optional, if you're using it for storing telemetry data).

Audit:

  1. Sign in to Azure portal as an Owner, Contributor, or Monitoring Contributor.

  2. Navigate to Application Insights in the portal and review the applications for which Application Insights has been configured.

  3. Ensure that Application Insights is properly linked with the resources that need to be monitored.

Implementation Steps (Automated):

  1. Sign in to Azure portal:

    • Use an account with Owner, Contributor, or Monitoring Contributor permissions.

  2. Navigate to Application Insights:

    • In the Azure portal, search for Application Insights.

    • Create a new Application Insights resource or configure an existing one.

  3. Configure Application Insights for Web Apps:

    • For an Azure App Service or Web App, go to the App Service resource.

    • Under Monitoring, select Application Insights.

    • Click on Turn on Application Insights and select the Application Insights resource (create a new one if needed).

    • Enable Application Insights and ensure that it is linked to your web app for monitoring.

Example using Azure CLI to enable Application Insights for an App Service:

az webapp up --name <App-Service-Name> --resource-group <Resource-Group-Name> --plan <App-Service-Plan-Name> --sku <SKU-Name>

az monitor app-insights component create --app <App-Service-Name> --resource-group <Resource-Group-Name> --location <Location>

  1. Configure Application Insights for Other Resources (VMs, Functions, etc.):

    • For Azure Virtual Machines or Azure Functions, navigate to the respective resource and configure Application Insights to collect telemetry.

    • For Azure Functions, you can enable Application Insights directly from the Function App settings under Monitoring.

Example for Azure Functions using Azure CLI:

az functionapp update --name <Function-App-Name> --resource-group <Resource-Group-Name> --set appInsights.instrumentationKey=<Instrumentation-Key>

Automate Application Insights Configuration Using Azure CLI: To automate the enabling of Application Insights for resources, such as Web Apps or Azure Functions, use the following Azure CLI commands:

  1. Configure Data Retention and Sampling:

    • In the Application Insights resource, configure sampling settings to reduce the volume of data collected and control costs.

    • Set the data retention period for logs and telemetry data (default is 90 days, but this can be adjusted).

    • Configure continuous export of data to a Log Analytics workspace or an external storage solution, if needed.

  2. Review Application Insights Metrics:

    • Use Azure Monitor or Application Insights dashboards to visualize metrics and logs, including request counts, failure rates, response times, and more.

    • Set up alerts in Azure Monitor to notify you of performance degradation, exceptions, or high failure rates.

  3. Monitor Telemetry and Logs:

    • After configuring Application Insights, monitor telemetry data from your application using the Application Insights interface in Azure portal or Log Analytics queries.

    • Review application performance and troubleshoot issues based on the collected data.

  4. Test the Application Insights Configuration:

    • Generate traffic for the application (e.g., make requests to the web app) to ensure that Application Insights is collecting the required telemetry data and that the logs appear in the dashboard.

    • Review the collected data to confirm that metrics like response times, failure rates, and exceptions are logged correctly.

Backout Plan (Automated):

  1. Sign in to Azure portal:

    • Use an account with Owner, Contributor, or Monitoring Contributor permissions.

  2. Navigate to Application Insights:

    • In the Azure portal, go to Application Insights.

  3. Disable Application Insights:

    • For the resource (e.g., Web App, VM, Function App), go to Monitoring > Application Insights.

    • Disable or unlink Application Insights from the resource.

Remove Configuration Using Azure CLI: To remove Application Insights for a Web App or Function App using Azure CLI, use the following commands:

 For Web Apps:

az webapp config appsettings delete --name <App-Service-Name> --resource-group <Resource-Group-Name> --settings "APPINSIGHTS_INSTRUMENTATIONKEY"

 For Azure Functions:

az functionapp config appsettings delete --name <Function-App-Name> --resource-group <Resource-Group-Name> --settings "APPINSIGHTS_INSTRUMENTATIONKEY"
  1. Verify the Backout:

    • After disabling Application Insights, verify that no telemetry data is being collected by checking the Application Insights resource.

    • Ensure that logs and metrics are no longer being reported for the resource.

References: