【问题标题】:Application Insights Telemetry filtering is not workingApplication Insights 遥测筛选不起作用
【发布时间】:2018-05-16 11:27:28
【问题描述】:

我已经按照指南here。我已经尝试了初始化和注册遥测处理器的配置和“代码中”方法。我的目标是过滤掉一些 HTTP 响应,这样它们就不会进入采样数据。我没有任何成功。虽然我们的处理器在应用程序启动时被初始化,但 Process 方法永远不会被命中。另外,我已经确保配置中有一个 InstrumentationKey 并且我使用了正确的密钥。我还缺少什么?

这就是我所拥有的:

public class MyTelemetryProcessor : ITelemetryProcessor
{
    private ITelemetryProcessor Next { get; set; }

    // You can pass values from .config
    public string MyParamFromConfigFile { get; set; }

    // Link processors to each other in a chain.
    public MyTelemetryProcessor(ITelemetryProcessor next)
    {
        this.Next = next; <-- this is always hit indicating this processor is active
    }

    public void Process(ITelemetry item)
    {
        // To filter out an item, just return
        if (!OKtoSend(item)) { return; } <-- breakpoint here is never hit
        // Modify the item if required
        ModifyItem(item);

        this.Next.Process(item);
    }

    private bool OKtoSend(ITelemetry item) <-- and consequently this method is never hit
    {
        var request = item as RequestTelemetry; <-- breakpoint here is never hit

        // some more code goes here

        return request.Success.GetValueOrDefault(false);
    }

    // Example: replace with your own modifiers.
    private void ModifyItem(ITelemetry item)
    {
        item.Context.Properties.Add("app-version", "1." + MyParamFromConfigFile);
    }
}

这就是它的注册方式。当应用启动时,我可以在调试期间看到这个问题:

var builder = TelemetryConfiguration.Active.TelemetryProcessorChainBuilder;
builder.Use((next) => new MyTelemetryProcessor (next));

builder.Build();

【问题讨论】:

  • 我无法判断您缺少什么。你能定义不工作吗?有没有异常,处理器没有被调用(你试过设置断点吗?)处理器的代码在哪里?
  • 您是否看到您的遥测处理器已正确插入? IE。如果您在处理器中设置断点 - 它会停在那里吗?
  • 嗨@PeterBons 感谢您的提问,因为我注意到我的问题不完整。我编辑了我的问题。 Process 方法没有被命中。
  • @ZakiMa 在处理器初始化时,当我访问一个不存在的页面时,没有命中 Process 方法。
  • 所以,遥测被收集(可以在 UX/Analytics 中看到),但处理器没有被击中,因此您无法过滤它,对吗?

标签: azure-application-insights


【解决方案1】:

在 aspnetcore 中,我的解决方案是使用: services.AddApplicationInsightsTelemetryProcessor(typeof(BasicTelemetryFilter));

(使用常规的 CreateWebHostBuilder :

WebHost.CreateDefaultBuilder(args)
            .UseApplicationInsights()
            .UseStartup<Startup>();

)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    相关资源
    最近更新 更多