# How to filter out all exception traces related to a EF Core exception?

**URL:** <https://discuss.elastic.co/t/how-to-filter-out-all-exception-traces-related-to-a-ef-core-exception/381883>\
**Category:** APM\
**Tags:** docker, dotnet\
**Created:** [September 11, 2025, 4:51pm UTC](https://discuss.elastic.co/t/how-to-filter-out-all-exception-traces-related-to-a-ef-core-exception/381883 "2025-09-11T16:51:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicystalker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicystalker/32/144994_2.png) [@nicystalker](https://discuss.elastic.co/u/nicystalker)\
**Post date:** [September 11, 2025, 4:51pm UTC](https://discuss.elastic.co/t/how-to-filter-out-all-exception-traces-related-to-a-ef-core-exception/381883/1 "2025-09-11T16:51:27Z")

</div>

Hi,

I’m trying to indicate the .NET APM client that the following exception, thrown from EF Core is properly handled:

```auto
catch (DbUpdateException exception) when
    (exception.InnerException is PostgresException
     {
         TableName: "my_table", SqlState: PostgresErrorCodes.UniqueViolation
     })
{

```

Just after `{`, I put:

```auto
ITransaction currentTransaction = tracer.CurrentTransaction;
currentTransaction.CaptureException(exception, isHandled: true);
tracer.CaptureException(exception, isHandled: true);

```

And the exception is not thrown again, in fact, there is an Minimal API `return TypedResults.Created(CreateTransactionRequest.Route);` at the end of this handle.

However, with the help of `Agent.AddFilter` and Kibana APM view, I noticed that related errors, that is, this unique violation exception, are sent regardless.

From Kibana (top) and `Agent.AddFilter` (bottom):

 ![BeFunky-collage](https://us1.discourse-cdn.com/elastic/original/3X/d/c/dc4324e785a73ec196d8bad1381f340e49a50a81.jpeg)

Clearly, there are some remains of this failure being sent to APM server.

I’m guessing that,

```auto
builder.Services.AddAllElasticApm();

```

, which is how we set up, subscribes to EF Core and intercept its errors, I don’t know.

This is a controlled environment (Docker compose with Elastic stack), simulating what we are experiencing in our instance.

Is it possible to filter out these related logs, exceptions, etc, reliably? Or comparing string within the `Agent.AddFilter` handler the only way?

Mind you, I may not be able to capture all 4 types of error, because `error.Context` is not the same from `ITransaction currentTransaction = tracer.CurrentTransaction` from before, so I cannot “mark it“ and later check the context for an entry, say “is\_unique\_validation\_exception“.

**Kibana version** :8.17

**Elasticsearch version** :8.17

**APM Server version** :8.17

**APM Agent language and version** : C#/.NET 9.0, ver: 1.34

**Is there anything special in your setup?** No.
