问题
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:
- You can filter out already collected telemetry that you get with F5 in UI because it has property IsDeveloperMode=true
- 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)
- 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)
- You can use different iKeys for debug and release again by setting it in code
- 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