How to Ignore localhost on Azure application insights

亡梦爱人 提交于 2019-12-08 17:07:24

问题


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?


回答1:


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>



回答2:


  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


来源:https://stackoverflow.com/questions/35370209/how-to-ignore-localhost-on-azure-application-insights

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!