Filter Hangfire Requests from Microsoft Azure Application Insights

Written by Ken Dale

We use Microsoft Azure Application Insights in our web applications. It logs tons of useful data about our applications, including web requests and requests to dependencies like databases. We also use Hangfire for running jobs in our web applications. Put these two together and you’re logging lots of unnecessary information which ultimately costs money.

That said, here’s how to skip sending Hangfire information to Application Insights in ASP.NET web applications:


Here’s an ITelemetryProcessor implementation that filters out Hangfire and Hangfire SQL.

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using System;
using System.Data.SqlClient;

namespace WebApplication
    /// <summary>
    /// Ignore the dashboard and Hangfire SQL backend telemetry.
    /// </summary>
    /// <remarks>
    /// This does not support ignoring Redis or any other backend.
    /// </remarks>
    public class IgnoreHangfireTelemetry : ITelemetryProcessor
        private readonly ITelemetryProcessor next;
        private readonly string hangfireDashboardPath;
        private readonly string sqlDatabase;

        public IgnoreHangfireTelemetry(
            ITelemetryProcessor next,
            string sqlConnectionString = null,
            string hangfireDashboardPath = "/hangfire")
   = next ?? throw new ArgumentNullException(nameof(next));

            if (!string.IsNullOrEmpty(sqlConnectionString))
                var builder = new SqlConnectionStringBuilder(sqlConnectionString);

                sqlDatabase = builder.InitialCatalog;

            this.hangfireDashboardPath = hangfireDashboardPath ?? throw new ArgumentNullException(nameof(hangfireDashboardPath));

        public void Process(ITelemetry item)
            var request = item as RequestTelemetry;

            if (request != null
                && request.Url.AbsolutePath.StartsWith(hangfireDashboardPath))

            if (sqlDatabase != null)
                var sqlBackend = item as DependencyTelemetry;

                if (sqlBackend != null
                    && sqlBackend.Type == "SQL"
                    && sqlBackend.Target.EndsWith($"| {sqlDatabase}", StringComparison.OrdinalIgnoreCase))


Next, use the IgnoreHangfireTelemetry class with Application Insights. There’s ASP.NET and ASP.NET Core examples at

Enjoy the savings!

Published July 31, 2019 by

undefined avatar
Ken Dale Senior Application Developer (Former)

Suggested Reading