Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Telemetry processor to ignore certain 404 errors in Application Insights
using System;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
namespace Samples
{
public class My404Filter : ITelemetryProcessor
{
private ITelemetryProcessor Next { get; set; }
public My404Filter(ITelemetryProcessor next)
{
Next = next;
}
public void Process(ITelemetry item)
{
// To filter out an item, just return
if (ShouldIgnoreRequest(item))
{
return;
}
Next.Process(item);
}
private static bool ShouldIgnoreRequest(ITelemetry item)
{
if (item.Context.Operation.Name != null)
{
var operationName = item.Context.Operation.Name.ToLower();
if (operationName.StartsWith("get api/getobjectwith404s"))
{
var req = item as RequestTelemetry;
return req != null && req.ResponseCode.Equals("404", StringComparison.OrdinalIgnoreCase);
}
return false;
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.