Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Ignore localhost on Azure application insights

I started hosting my first production application recently. I went ahead and activated application insights, which I think have a lot of value. However, I'm getting stats which come from the developer side, for example logs are recording entries from localhost:xxxx. I'm sure there is a way to turn this off. Can anyone give me some pointers please?

like image 287
chesco Avatar asked Feb 12 '16 18:02

chesco


1 Answers

You can also filter localhost telemetry using TelemetryProcessor (if you are using the latest (prerelease version of Application Insights Web SDK). Here's an example. Add this class to your project:

public class LocalHostTelemetryFilter : ITelemetryProcessor
{
    private ITelemetryProcessor next;
    public LocalHostTelemetryFilter(ITelemetryProcessor next)
    {
        this.next = next;
    }

    public void Process(ITelemetry item)
    {
        var requestTelemetry = item as RequestTelemetry;
        if (requestTelemetry != null && requestTelemetry.Url.Host.Equals("localhost", StringComparer.OrdinalIgnoreCase))
        {
            return;
        }
        else
        {
            this.next.Process(item);
        }   
    }
}

And then register it in ApplicationInsights.config:

<TelemetryProcessors>
    <Add Type="LocalhostFilterSample.LocalHostTelemetryFilter, LocalHostFilterSample"/>
</TelemetryProcessors>
like image 152
Alex Bulankou Avatar answered Oct 04 '22 13:10

Alex Bulankou