Skip to content

Instantly share code, notes, and snippets.

@Swimburger
Last active September 20, 2019 21:44
Show Gist options
  • Save Swimburger/03987eb409b22d9384f3545b158dd14a to your computer and use it in GitHub Desktop.
Save Swimburger/03987eb409b22d9384f3545b158dd14a to your computer and use it in GitHub Desktop.
ITelemetryProcessor for Application Insights to filter out Umbraco's ping requests, learn more at https://swimburger.net/blog/umbraco/ignoring-umbraco-ping-from-azure-application-insights
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using System;
namespace YourApp.ApplicationInsights
{
public class PingFilter : ITelemetryProcessor
{
//next processor in the pipeline
private readonly ITelemetryProcessor next;
public PingFilter(ITelemetryProcessor next)
{
//store next processor in the pipeline
this.next = next;
}
//our logic goes here
public void Process(ITelemetry telemetry)
{
//check to see if telemetry is for a Request
var request = telemetry as RequestTelemetry;
//ignore if RequestTelemetry is a ping request
if (request?.Url?.AbsolutePath.Equals("/umbraco/ping.aspx", StringComparison.OrdinalIgnoreCase) == true)
{
//stop pipeline
return;
}
//invoke next processor
next.Process(telemetry);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment