Apm does not work when use both Service.AddElastticApm and Elastic.Apm.Agent.AddFilter

Hi there,

I'm using Elastic APM in my .NET application. When I use builder.Host.UseAllElasticApm() together with Elastic.Apm.Agent.AddFilter, it works for me, but it shows as obsolete. They recommend using the AddAllElasticApm extension via IServiceCollection.

However, when I use services.AddAllElasticApm(), it doesn't work—nothing is sent to the APM server.

Here's my code:


services.AddAllElasticApm();

var filteredSpanNames = configuration.GetSection("ElasticApm:FilteredSpanNames").Get<string[]>();
if (filteredSpanNames != null && filteredSpanNames.Length > 0)
{
    Elastic.Apm.Agent.AddFilter((ISpan span) =>
    {
        return filteredSpanNames.Contains(span.Name) ? null : span;
    });
}

Has anyone faced a similar issue or know why the AddAllElasticApm method might not be working with Elastic.Apm.Agent.AddFilter? Any suggestions or workarounds would be greatly appreciated!

Thanks in advance for your help!