Search code examples
c#azureazure-application-insights

How to tell Application Insights to ignore 404 responses


ApplicationInsights has recently started mailing me a Weekly Telemetry Report. My problem is that it tells me that I have a bunch of Failed Requests, Failed Dependencies, and Exceptions, but when I click through to analyze the failures I see that they are all associated with attempts by bots or Bad Guys to access nonexistent pages in my website.

Is there an easy way to tell ApplicationInsights that I am not interested in metrics associated with attempts to access nonexistent pages? Yes, I appreciate the Weekly Telemetry Report, but I don't want to have to take the time to investigate a category of frequently reported problems that I consider "false positives".


Solution

  • You can filter AI telemetry by implementing a Telemetry Processor. For example, you can filter out 404 Not Found telemetry by implementing the ITelemetryProcessor 'Process' method as follows:

    public void Process(ITelemetry item)
    {
        RequestTelemetry requestTelemetry = item as RequestTelemetry;
    
        if (requestTelemetry != null && int.Parse(requestTelemetry.ResponseCode) == (int)HttpStatusCode.NotFound)
        {
            return;
        }
    
        this.Next.Process(item);
    }