Bob.at.Indigo.Health
Bob.at.Indigo.Health

Reputation: 11895

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".

Upvotes: 34

Views: 13150

Answers (2)

gius
gius

Reputation: 9437

You can modify the request telemetry and mark it as a Success (not Fail). This way, the request will be properly logged by the AI but as a successful one. You need to implement a Telemetry Initializer.

Example:

public class CustomTelemetryInitializer : ITelemetryInitializer
{
    public void Initialize(ITelemetry telemetry)
    {
        switch (telemetry)
        {
            case RequestTelemetry request when request.ResponseCode == "404":
                request.Success = true;
                break;
        }
    }
}

Upvotes: 38

yonisha
yonisha

Reputation: 3096

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);
}

Upvotes: 22

Related Questions