Application Insights遥测过滤不起作用 [英] Application Insights Telemetry filtering is not working

查看:72
本文介绍了Application Insights遥测过滤不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照指南 InstrumentationKey ,并且我使用的是正确的密钥.我还想念什么?

I have already followed the guide here. I have tried both the config and "in code" approach of initializing and registering our telemetry processor. My goal is to filter out some HTTP responses so that those don't make their way to the sampled data. I haven't had any success. While our processor is initialized on app start, the Process method is never hit. Also, I already made sure that there is an InstrumentationKey in the config and that I'm using the correct key. What else am I missing?

这就是我所拥有的:

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);
    }
}

这就是它的注册方式.我可以看到在应用程序启动时在调试过程中遇到了这个问题:

And this is how it is registered. I can see this being hit during debugging when the app starts up:

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

builder.Build();

推荐答案

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

In aspnetcore, my solution was to use : services.AddApplicationInsightsTelemetryProcessor(typeof(BasicTelemetryFilter));

(使用常规的CreateWebHostBuilder:

(using the regular CreateWebHostBuilder :

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

)

这篇关于Application Insights遥测过滤不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆