How to Ignore localhost on Azure application insights

2021-6-21 anglehua

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?

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)
    { = next;

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

And then register it in ApplicationInsights.config:

    <Add Type="LocalhostFilterSample.LocalHostTelemetryFilter, LocalHostFilterSample"/>

  1. You can filter out already collected telemetry that you get with F5 in UI because it has property IsDeveloperMode=true
  2. You can have web.config transformation that removes Application Insights module from web.debug.config and leaves it only in web.release.config (if you have only auto-collected properties)
  3. You can remove instrumentation key from config and set it only for release version in code: TelemetryConfiguration.Active.InsrumentationKey = "MyKey" (if you do not provide iKey in debug you can still see all telemetry in AI hub in VS 2015)
  4. You can use different iKeys for debug and release again by setting it in code
  5. You can disable ApplicationInsights completely in debug by setting TelemetryConfiguration.Active.DisableTelemetry = true


Powered by emlog 京ICP备15036472号-3 sitemap