2

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?

This is what I have:

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();
von v.
  • 16,868
  • 4
  • 60
  • 84
  • I can't possible tell what you are missing. Can you define *not working*? Do you get any exceptions, is the processor not called (did you tried setting a breakpoint?) Where is the code of the processor? – Peter Bons May 16 '18 at 12:14
  • Do you see that your telemetry processor plugged correctly? I.e. if you put a breakpoint in your processor - does it stop there? – ZakiMa May 16 '18 at 16:13
  • Hi @PeterBons thanks for asking as I noticed my question is not complete. I edited my question. The Process method is not being hit. – von v. May 18 '18 at 12:45
  • @ZakiMa while the processor is initialized, when I visit a non-existing page, the Process method is not hit. – von v. May 18 '18 at 12:46
  • So, telemetry is collected (can be seen in UX/Analytics), but processor is not being hit and as a result you cannot filter it, correct? – ZakiMa May 18 '18 at 16:35
  • Yes that is correct @ZakiMa – von v. May 22 '18 at 03:21
  • Can you please paste the source code how you've configured it? Either through code or config? – ZakiMa May 22 '18 at 16:37
  • I edited my question @ZakiMa – von v. May 24 '18 at 14:28
  • My understanding is that .Process is not being hit in debugger, correct? Which points to a problem with registration. Can you please add a snippet which shows how you register this processor in AI pipeline? – ZakiMa May 24 '18 at 19:35
  • I added the registration code @ZakiMa – von v. May 25 '18 at 11:40

1 Answers1

2

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

(using the regular CreateWebHostBuilder :

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

)

Guillaume
  • 1,076
  • 10
  • 21