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:
- 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.
-
In the search box, type ‘Application Insights’ and select ‘Application Insights’ from the search results.
-
In the ‘Basics’ tab, provide a name for the Application Insights resource and select the subscription, resource group, and location.
-
In the ‘Configure features’ tab, select the appropriate settings for your application, such as availability monitoring, live stream, etc.
-
Click on the ‘Review + create’ button, review the settings, and click on the ‘Create’ button to create the Application Insights resource.
-
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:
- Open the Azure portal and navigate to the web application for which you want to configure Application Insights.
-
Click on the ‘Application Insights’ option from the ‘Monitoring’ section in the left menu.
-
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.
-
Once you have selected the Application Insights resource, click on the ‘Apply’ button to start the Application Insights integration process.
-
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:
- Install the ‘Microsoft.ApplicationInsights.AspNetCore’ NuGet package in your .NET Core application.
-
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.
- 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.
- 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:
- Open the Application Insights portal and navigate to the ‘Telemetry’ section.
-
Select the telemetry type you want to customize, such as ‘Requests’, ‘Exceptions’, etc.
-
Click on the ‘Customize’ button to configure the telemetry settings.
-
In the telemetry settings window, you can enable/disable telemetry collection, filter data, customize dimensions, add custom properties, and much more.
-
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:
- Open the Application Insights portal and navigate to the ‘Analytics’ section.
-
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.
- You can also use the ‘Chart’ option to visualize the query results in different chart types, such as line, bar, pie, etc.
-
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.