Created
January 29, 2017 17:47
-
-
Save gbellmann/fcb146a92bb93a33cb4d8e92ce361a85 to your computer and use it in GitHub Desktop.
Telemetry processor to ignore certain 404 errors in Application Insights
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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