# Discard traces with no exit spans

**URL:** <https://discuss.elastic.co/t/discard-traces-with-no-exit-spans/377598>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [April 29, 2025, 5:57am UTC](https://discuss.elastic.co/t/discard-traces-with-no-exit-spans/377598 "2025-04-29T05:57:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![holterbades](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@holterbades](https://discuss.elastic.co/u/holterbades)\
**Post date:** [April 29, 2025, 5:57am UTC](https://discuss.elastic.co/t/discard-traces-with-no-exit-spans/377598/1 "2025-04-29T05:57:07Z")

</div>

Hello there,  
is it possible to discard traces which have no spans assigned to them?  
I am currently (manually) integrating APM in my .NET Framework WinForms application and I see a lot of traces which have no spans (which is correct and not the issue). Those traces have no value to me because I am only interested in traces which have exit spans for HTTP-calls or DB calls.

I haven't seen a setting in the APM agent or the server to discard souch traces automatically.  
I looked into the `Elastic.Apm.Api` - but i haven't found a way to discard souch traces before they are sent to the APM server (`IExecutionSegment.IsSampled` is write protected). The only way i could think of is that i add a label `no_spans` if `CurrentTransaction.SpanCount == 0` and somehow discard souch traces in an ingest pipeline.

Would this be a valid way or are there other ways I haven't seen?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![holterbades](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@holterbades](https://discuss.elastic.co/u/holterbades)\
**Post date:** [May 20, 2025, 7:46am UTC](https://discuss.elastic.co/t/discard-traces-with-no-exit-spans/377598/2 "2025-05-20T07:46:22Z")

</div>

Found the solution.  
It's pretty easy: You can use

```auto
Elastic.Apm.Agent.AddFilter((ITransaction e) => e.SpanCount.Started < 1 ? null : e);

```

This Delegate gets called when the Agent is sending the traces. If the transaction, span, ... is set to `null`, it isn't sent to the server.
