从 Application Insights 过滤掉信号器请求

Filter out signalr requests from Application Insights

我的 Application Insights 遥测配额的很大一部分被 SignalR 的 ping 请求(和其他 SignalR 请求)用完了。

如何防止这些请求被举报?我想保留其他 ajax 请求,但对 SignalR 请求应用某种(客户端)过滤器。

我找不到任何提供简单示例的好文档。我知道我可以使用 addTelemetryInitializer 过滤掉一些请求,但我不知道要过滤什么?

    appInsights.queue.push(function () {
        appInsights.context.addTelemetryInitializer(function (envelope) {
            // What should I do here to remove /signalr requests?
        });
    });

在您的场景中,我假设您想过滤浏览器发出的 Ajax 远程依赖调用。要从遥测中过滤我们的服务器端信号器请求,您需要在服务器端实现遥测处理器 (https://azure.microsoft.com/en-us/blog/request-filtering-in-application-insights-with-telemetry-processor/)

应该是这样的。现在无法验证,稍后会修复任何语法错误:

window.appInsights = appInsights;
// Add telemetry initializer
appInsights.queue.push(function () {

appInsights.context.addTelemetryInitializer(function (envelope) {

/* filter our Ajax requests with signalr in url*/

if (envelope.name === Microsoft.ApplicationInsights.Telemetry.RemoteDependencyData.envelopeType && envelope.data.baseData.commandName.indexOf("signalr")>-1){

   return false;

 }
});
});

// end of insertion

appInsights.trackPageView();

有关 JS 遥测初始化程序的更多示例,请参阅此内容:https://blogs.msdn.microsoft.com/albulank/2016/04/20/modifying-and-filtering-telemetry-with-appinsights-javascript-sdk-telemetry-initializer/