DEV Community

Cover image for Getting started with Application Insights in .NET Web API
Ishwar398
Ishwar398

Posted on

Getting started with Application Insights in .NET Web API

Monitoring an application is one of the most important part in Software Lifecycle. With help of Monitoring tools, we can see whats going inside the application, predict any infra scaling, see how users are using the application etc.
Azure Application Insights offers powerful application performance and monitoring tools. It tracks user interactions, traces requests, measures performance metrics, and monitors application health. With features like custom event tracking and real-time analytics, it helps developers identify issues, optimize performance, and enhance user experiences in cloud-based applications.

Pre-Requisites:

  1. Azure Account
  2. .NET Web API project
  3. Visual Studio

Configuring Application Insights in Web API project

  1. Open the solution in Visual Studio
  2. Right click on the solution.
  3. Click on 'Configure Application Insights'

Configure Application Insights

  1. This will open a pop up asking for connecting to the dependency. If you need to use application insights on local machine, click on Application Insights SDK (Local). If you want to connect to an instance on Azure, click on Azure Application Insights. For this post, we will be connecting to an instance on Azure.

Connect to dependency

  1. On clicking next, we need to select the Application Insights instance. If not present, there is an option to create a new and then select it.

Select the Application Insights instance on Azure

  1. Next, it will show us the Application Insights connection string which is to be saved in the User secret file.

  2. On the next step, it will add the necessary config files and Nuget packages to the application.

Files added to the project

Deployment and Application Insights portal

Once the changes are deployed, you can visit the Azure portal to check the newly created Application Insights instance. It will start showing stats for your application in some time.

Application Insights Portal

Checking Failures in API

Here's an example on how we can check the exceptions which were throw by the API and their details.
In the overview page of Application Insights, we will see a Failures chart. This option is also present in the left pane.

Failures

Once you click on any of the above highlighted option, you'll get the list of the failures along with the exceptions by HTTP Status code, exception types etc. along with the operation name.

Failure details

If we click on the type of exception, we will get complete list of the exception of the selected type. We can then click on any item from the list to get the complete details about the exception.

List of exceptions

Exception Details

Top comments (0)