Detect 404 errors with Application Insights

  • Azure

Application Insights is a free service to monitor your web and desktop applications. It also provides a nice way to query data using a very comprehensive syntax.

Configure Application Insights

First, you need to add Application Insights to your web application. It should take about 1 minute with Visual Studio 2017:

Then, select your azure account and Visual Studio will do everything for you!

Search for 404 errors

Let's open the analytics tool:

Application Insights - Open analytics

The query editor is very convenient. You can easily write queries with a syntax similar to F#. And, what about the awesome auto-completion in the browser!

Now, you can execute your first query. Let's start with a basic query that search requests with a result code equals to 404:

requests
| where resultCode == 404

The result is hard to process. There are php files and duplicate urls, plus rows are not sorted. Let's improve the query with some pipes:

requests
| where resultCode == 404
| where url !endswith ".php" // Exclude php files
| where timestamp > ago(1d)  // Get result of the last day
| order by timestamp desc    // the last 404 first
| distinct url               // avoid duplicate urls

The results are much easier to process. But, which 404 should you fix first? I think you should start by the most requested 😃 So, let's use the summarize function to group the data and apply an aggregation function:

requests
| where resultCode == 404
| where url !endswith ".php"
| where timestamp > ago(1d)
| summarize count() by url   // Group by url and display the number of item of each group
| order by count_ desc

Here's the result 😃

Application Insights - Error 404 query

Follow me:
Enjoy this blog?Buy Me A CoffeeDonate with PayPal

Leave a reply