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

**URL:** <https://discuss.elastic.co/t/apm-does-not-work-when-use-both-service-addelastticapm-and-elastic-apm-agent-addfilter/363011>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [July 12, 2024, 9:37am UTC](https://discuss.elastic.co/t/apm-does-not-work-when-use-both-service-addelastticapm-and-elastic-apm-agent-addfilter/363011 "2024-07-12T09:37:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chung\_Toan\_Account](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chung_toan_account/32/128082_2.png) [@Chung\_Toan\_Account](https://discuss.elastic.co/u/Chung_Toan_Account)\
**Post date:** [July 12, 2024, 9:37am UTC](https://discuss.elastic.co/t/apm-does-not-work-when-use-both-service-addelastticapm-and-elastic-apm-agent-addfilter/363011/1 "2024-07-12T09:37:04Z")

</div>

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:

```csharp

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!
