How to tell Application Insights to ignore 404 responses How to tell Application Insights to ignore 404 responses azure azure

How to tell Application Insights to ignore 404 responses


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


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