open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.1k stars 740 forks source link

Adding filter processor after also filter previous processor #5672

Open abratv opened 1 month ago

abratv commented 1 month ago

What is the question?

The first registration

builder.Services.AddOpenTelemetry()
    .WithMetrics(metrics =>
    {
        metrics.AddAspNetCoreInstrumentation()
            .AddHttpClientInstrumentation()
            .AddRuntimeInstrumentation();
    })
    .WithTracing(tracing =>
    {
        tracing.AddAspNetCoreInstrumentation()
            // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
            //.AddGrpcClientInstrumentation()
            .AddHttpClientInstrumentation()
            .AddSqlClientInstrumentation()
            .AddRedisInstrumentation();
    });

next

builder.Services.AddOpenTelemetry().WithTracing(tracing =>
{
   tracing.AddProcessor(new MyFilterProcessor())

tracing.AddProcessor(new MyProcessor());
});

I was expecting "MyProcessor" should be filtered but what happened is AspNetCoreInstrumentation also filtered

Is this expected?

Additional context

No response

vishweshbankwar commented 1 month ago

@abratv - could you please elaborate on what you are trying to do?

I was expecting "MyProcessor" should be filtered but what happened is AspNetCoreInstrumentation also filtered

This statement is not clear to me.

abratv commented 1 month ago

Let's say I have following processors

Expectation: "Processor Filter" only apply to "Processor C" Actual: "Processor Filter" also applied to "Processor A", "Processor B" and "Processor C"

cijothomas commented 1 month ago

Let's say I have following processors

  • Processor A
  • Processor B
  • Processor Filter
  • Processor C

Expectation: "Processor Filter" only apply to "Processor C" Actual: "Processor Filter" also applied to "Processor A", "Processor B" and "Processor C"

This would be a bug, if ProcessorFilter applied to things before it! Can you share a minimal repro or a unittest to show the behavior you are seeing?

abratv commented 1 month ago

I'm bit tight right now

You can check quickly if the traces over the dashboard also got filtered

image

or the way I configure it wrong some how?

this is the way i configure my filter

    public static IHostApplicationBuilder ConfigureMyTelemetry(this IHostApplicationBuilder builder, Action<TracerProviderBuilder> configure)
    {
        builder.Services.AddOpenTelemetry().WithTracing(tracing =>
        {
            configure(tracing);
        });

        return builder;
    }

and in program.cs

//these 2 lines below come from github example
builder.ConfigureOpenTelemetry(); 
builder.AddDefaultHealthChecks();

//My own telemetry, filter and processor
builder.ConfigureMyTelemetry(trace =>
{
    trace.AddProcessor<MyFilterProcessor>();
    trace.AddProcessor<MyProcessor>();
});

So MyFilterProcessor also filter configuration in "ConfigurationOpenTelemetry"

cijothomas commented 1 month ago

https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/trace/extending-the-sdk Please use a minimal example and share the repro code, so it'll be easy for us to confirm you are adding processors correctly.