Find and diagnose run-time exceptions with Azure Application Insights

Azure Application Insights collects telemetry from your application to help identify and diagnose run-time exceptions. This tutorial takes you through this process with your application. You learn how to:

  • Modify your project to enable exception tracking
  • Identify exceptions for different components of your application
  • View details of an exception
  • Download a snapshot of the exception to Visual Studio for debugging
  • Analyze details of failed requests using query language
  • Create a new work item to correct the faulty code


To complete this tutorial:

Log in to Azure

Log in to the Azure portal at

Analyze failures

Application Insights collects any failures in your application and lets you view their frequency across different operations to help you focus your efforts on those with the highest impact. You can then drill down on details of these failures to identify root cause.

  1. Select Application Insights and then your subscription.
  2. To open the Failures panel either select Failures under the Investigate menu or click the Failed requests graph.

    Failed requests

  3. The Failed requests panel shows the count of failed requests and the number of users affected for each operation for the application. By sorting this information by user you can identify those failures that most impact users. In this example, the GET Employees/Create and GET Customers/Details are likely candidates to investigate because of their large number of failures and impacted users. Selecting an operation shows further information about this operation in the right panel.

    Failed requests panel

  4. Reduce the time window to zoom in on the period where the failure rate shows a spike.

    Failed requests window

  5. Click View Details to see the details for the operation. This includes a Gantt chart that shows two failed dependencies which collectively took almost half of a second to complete. You can find out more about analyzing performance issues by completing the tutorial Find and diagnose performance issues with Azure Application Insights.

    Failed requests details

  6. The operations detail also shows a FormatException which appears to have caused the failure. Click the exception or on the Top 3 exception types count to view its details. You can see that it's due to an invalid zip code.

    Exception details


Enable the "Unified details: E2E Transaction Diagnostics" preview experience to see all related server-side telemetry like requests, dependencies, exceptions, traces, events etc. in a single full screen view.

With the preview enabled, you can see the time spent in dependency calls, along with any failures or exceptions in a unified experience. For cross-component transactions, the Gantt chart along with the details pane can help you quickly diagnose the root-cause component, dependency or exception. You can expand the bottom section to see time-sequence of any traces or events collected for the selected component-operation. Learn more about the new experience

Transaction diagnostics

Identify failing code

The Snapshot Debugger collects snapshots of the most frequent exceptions in your application to assist you in diagnosing its root cause in production. You can view debug snapshots in the portal to see the call stack and inspect variables at each call stack frame. You can then debug the source code by downloading the snapshot and opening it in Visual Studio 2017.

  1. In the properties of the exception, click Open debug snapshot.
  2. The Debug Snapshot panel opens with the call stack for the request. Click any method to view the values of all local variables at the time of the request. Starting from the top method in this example, we can see local variables that have no value.

    Debug snapshot

  3. The first call that has valid values is ValidZipCode, and we can see that a zip code was provided with letters that isn't able to be translated into an integer. This appears to be the error in the code that needs to be corrected.

    Debug snapshot

  4. To download this snapshot into Visual Studio where we can locate the actual code that needs to be corrected, click Download Snapshot.

  5. The snapshot is loaded into Visual Studio.
  6. You can now run a debug session in Visual Studio that quickly identifies the line of code that caused the exception.

    Exception in code

Use analytics data

All data collected by Application Insights is stored in Azure Log Analytics, which provides a rich query language that allows you to analyze the data in a variety of ways. We can use this data to analyze the requests that generated the exception we're researching.

  1. Click the CodeLens information above the code to view telemetry provided by Application Insights.


  2. Click Analyze impact to open Application Insights Analytics. It's populated with several queries that provide details on failed requests such as impacted users, browsers, and regions.


Add work item

If you connect Application Insights to a tracking system such as Visual Studio Team Services or GitHub, you can create a work item directly from Application Insights.

  1. Return to the Exception Properties panel in Application Insights.
  2. Click New Work Item.
  3. The New Work Item panel opens with details about the exception already populated. You can add any additional information before saving it.

    New Work Item

Next steps

Now that you've learned how to identify run-time exceptions, advance to the next tutorial to learn how to identify and diagnose performance issues.