APM tips blog

Blog about application monitoring.

When 404 Is Not Tracked by Application Insights

| Comments

Sometimes Application Insights wouldn’t track web requests made with the bad routes resulting in the response code 404. The reason may not be clear initially. However once you opened the application from localhost and see the standard IIS error page - it become clearer. Without the default route set up in your applicaiton - 404 will be returned by StaticFile handler, not by the managed handler. This is what the error page says:

Easiest and most straightforward workaround is to change a web.config according to this blog post - add runAllManagedModulesForAllRequests="true" and remove preCondition="managedHandler":

1
2
3
4
5
<modules runAllManagedModulesForAllRequests="true">
  <remove name="ApplicationInsightsWebTracking" />
  <add name="ApplicationInsightsWebTracking"
   type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</modules>

This way Application Insights http module will be working on every request and you’ll capture all requests made to the bad routes.

Comments