Configuring Application Insights in Azure

Introduction

Monitoring the behavior and performance of a software application has become essential for businesses to ensure high-quality and efficient service delivery. Azure Application Insights is a handy tool that provides a comprehensive view of the application’s behavior, real-time insights, trace analysis, and performance metrics.

In this tutorial, we will guide you through the process of configuring Application Insights in Azure by covering the following topics:

  • Creating an Application Insights resource
  • Adding Application Insights to an Azure web application
  • Configuring Application Insights for .NET Core applications
  • Customizing Application Insights telemetry
  • Using Application Insights analytics

Creating an Application Insights Resource

To start using Application Insights, we need to create an Application Insights resource in Azure. An Application Insights resource acts as a container for all the telemetry data collected from the application. Follow the steps below to create an Application Insights resource:

  1. Log in to the Azure portal and navigate to the ‘Create a resource’ page by clicking on the ‘+’ icon in the upper left corner of the portal.
  2. In the search box, type ‘Application Insights’ and select ‘Application Insights’ from the search results.

  3. In the ‘Basics’ tab, provide a name for the Application Insights resource and select the subscription, resource group, and location.

  4. In the ‘Configure features’ tab, select the appropriate settings for your application, such as availability monitoring, live stream, etc.

  5. Click on the ‘Review + create’ button, review the settings, and click on the ‘Create’ button to create the Application Insights resource.

  6. Once the resource is created, you can access it from the ‘All resources’ page in the Azure portal.

Adding Application Insights to an Azure Web Application

Now let’s explore how to add Application Insights to an Azure Web Application. Follow the steps below:

  1. Open the Azure portal and navigate to the web application for which you want to configure Application Insights.
  2. Click on the ‘Application Insights’ option from the ‘Monitoring’ section in the left menu.

  3. If you have previously created an Application Insights resource, click on the ‘Configure Application Insights’ option and select the resource from the drop-down list. If you have not created an Application Insights resource, click on the ‘Create new resource’ button to create one.

  4. Once you have selected the Application Insights resource, click on the ‘Apply’ button to start the Application Insights integration process.

  5. Once the integration is complete, you will be redirected to the Application Insights portal, where you can view the telemetry data collected from your application.

Configuring Application Insights for .NET Core Applications

If you are developing .NET Core applications, there are a few additional steps you need to follow to configure Application Insights. Follow the steps below:

  1. Install the ‘Microsoft.ApplicationInsights.AspNetCore’ NuGet package in your .NET Core application.
  2. Open the ‘Startup.cs’ file and add the following line of code to the ‘ConfigureServices’ method:

services.AddApplicationInsightsTelemetry();

This line of code configures Application Insights for your .NET Core application.

  1. If you want to customize the telemetry data collected by Application Insights, you can add the following code snippet to the ‘ConfigureServices’ method:
services.AddApplicationInsightsTelemetry(options => {
    options.EnableDebugLogger = true;
    options.RequestCollectionOptions.TrackExceptions = true;
});

This code snippet configures Application Insights to collect telemetry for exceptions and enable debug logging.

  1. Finally, add the following code snippet to the ‘Configure’ method in the ‘Startup.cs’ file:
app.UseApplicationInsights();

This code snippet configures Application Insights to track requests and exceptions in your .NET Core application.

Customizing Application Insights Telemetry

Application Insights provides a wide range of telemetry data that can be customized to suit your requirements. Follow these steps to customize Application Insights telemetry:

  1. Open the Application Insights portal and navigate to the ‘Telemetry’ section.
  2. Select the telemetry type you want to customize, such as ‘Requests’, ‘Exceptions’, etc.

  3. Click on the ‘Customize’ button to configure the telemetry settings.

  4. In the telemetry settings window, you can enable/disable telemetry collection, filter data, customize dimensions, add custom properties, and much more.

  5. Once you have customized the telemetry settings, click on the ‘Save’ button to save the changes.

Using Application Insights Analytics

Application Insights Analytics is a powerful tool that allows you to analyze and query telemetry data collected by Application Insights. Follow these steps to use Application Insights Analytics:

  1. Open the Application Insights portal and navigate to the ‘Analytics’ section.
  2. In the query editor, you can write queries to filter and analyze the telemetry data. Here’s an example query for analyzing exceptions:

exceptions | summarize count() by type | order by count_ desc

This query returns the count of exceptions grouped by exception type.

  1. You can also use the ‘Chart’ option to visualize the query results in different chart types, such as line, bar, pie, etc.
  2. Once you have created a query and chart, you can save it for future reference by clicking on the ‘Save’ button.

Conclusion

In this tutorial, we covered the steps required to configure Application Insights in Azure. We started by creating an Application Insights resource and then added it to an Azure web application. We then explored how to customize Application Insights telemetry and use Analytics to analyze the telemetry data. As a developer, it is essential to monitor application behavior and performance, and Application Insights provides an easy and efficient way to accomplish this task.

Related Post