34

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

2 Answers 2

38

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;
        }
    }
}
3
  • 4
    This is actually the better answer, because the requests are properly logged, but don't show as failure. Commented Jan 28, 2021 at 10:08
  • 1
    The only thing that I am missing here is the fact that my dependency (db returning 404) is gone Commented Mar 30, 2022 at 14:31
  • @MarkLagendijk is correct. Requests should be logged, but not as errors
    – freeAll
    Commented Mar 15 at 19:27
22

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);
}
2
  • 2
    You should check if requestTelemetry.ResponseCode is null. I don't know when it happens, but I just had the case
    – qd0r
    Commented Aug 13, 2018 at 21:47
  • That happens when the request has been cancelled or timed-out I believe.
    – Johan B
    Commented Feb 8, 2021 at 18:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.