Search code examples
asp.netazureazure-application-insights

Azure application insights disable favicon check


I have a regular mvc app. How can I disable app insights from checking for favicon.ico?

enter image description here


Solution

  • You can write a custom TelemetryFilter that prevents telemetry from being send to application insights:

    public class CustomTelemetryFilter : ITelemetryProcessor
    {
        private readonly ITelemetryProcessor _next;
    
        public CustomTelemetryFilter(ITelemetryProcessor next)
        {
            _next = next;
        }
    
        public void Process(ITelemetry item)
        {
            // Example: process all telemetry except requests to favicon
            var isFavIconUrl = item is RequestTelemetry request && request.Url.ToString().EndsWith("favicon.ico");
    
            if (!isFavIconUrl)
                _next.Process(item); // Process the item only if it is not the request for favicon
        }
    }
    

    The last step is to register your filter, see the docs on how to do that for your specific runtime.