microsoft / ApplicationInsights-dotnet

ApplicationInsights-dotnet
MIT License
565 stars 287 forks source link

OpenTelemetry processor doesn't work when configured through delegate from "WithTracing" method #2920

Open jasonshave opened 3 days ago

jasonshave commented 3 days ago

Azure.Monitor.OpenTelemetry.AspNetCore Serilog.Sinks.ApplicationInsights

net8.0

Linux on K8S

Describe the bug

When using the "WithTracing" method to configure a processor to filter out OTEL dependencies sent to App Insights, it triggers but doesn't seem to filter out the data in Azure.

To Reproduce

builder.Services.AddOpenTelemetry()
    .UseAzureMonitor()
    .WithTracing(tracerProviderBuilder =>
    {
       // filter out dependency data for Jaeger
        tracerProviderBuilder.AddProcessor<JaegerSpanFilterProcessor>();
    });

Here is the filter in case you want to see it:

public class JaegerSpanFilterProcessor : BaseProcessor<Activity>
{
    public override void OnEnd(Activity activity)
    {
        // Filter Jaeger requests based on the target or URL
        if (activity.Kind is ActivityKind.Client && activity.GetTagItem("server.address") is string url && url.Contains("jaeger"))
        {
            activity.ActivityTraceFlags &= ~ActivityTraceFlags.Recorded;
        }

        base.OnEnd(activity);
    }
}

This works:

// set up the processor beforehand and configured off another extension method...
builder.Services.ConfigureOpenTelemetryTracerProvider(t=> t.AddProcessor<JaegerSpanFilterProcessor>());
builder.Services.AddOpenTelemetry()
    .UseAzureMonitor();

We will close this issue if:

For Immediate Support

For immediate support relating to the Application Insights .NET SDK we encourage you to file an Azure Support Request with Microsoft Azure instead of filing a GitHub Issue in this repository. You can do so by going online to the Azure portal and submitting a support request. Access to subscription management and billing support is included with your Microsoft Azure subscription, and technical support is provided through one of the Azure Support Plans. For step-by-step guidance for the Azure portal, see How to create an Azure support request. Alternatively, you can create and manage your support tickets programmatically using the Azure Support ticket REST API