Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Suppressing Application Insights telemetry on an ASP.NET Core web applications
// **********************************************
// Fore more information, visit:
// **********************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
namespace aspnet_ai.Infrastructure.Filters
public class SuppressStaticResourcesFilter : ITelemetryProcessor
private ITelemetryProcessor Next { get; set; }
// some of the static resources that I'd like to exclude from my telemetry
static readonly List<string> names = new List<string> { "favicon.ico", "bootstrap", "jquery", "site.css", "site.js" };
// next will point to the next TelemetryProcessor in the chain.
public SuppressStaticResourcesFilter(ITelemetryProcessor next)
Next = next;
public void Process(ITelemetry item)
// To exclude requests from our telemetry we sould use RequestTelemetry
// For dependencies, use DependencyTelemetry
var req = item as RequestTelemetry;
if (req != null && names.Any(n => req.Name.Contains(n)))
// Send everything else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment