# Hide or discard a transaction or span

**URL:** <https://discuss.elastic.co/t/hide-or-discard-a-transaction-or-span/199989>\
**Category:** APM\
**Tags:** java\
**Created:** [September 18, 2019, 11:26am UTC](https://discuss.elastic.co/t/hide-or-discard-a-transaction-or-span/199989 "2019-09-18T11:26:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregjeanmart](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gregjeanmart](https://discuss.elastic.co/u/gregjeanmart)\
**Post date:** [September 18, 2019, 11:26am UTC](https://discuss.elastic.co/t/hide-or-discard-a-transaction-or-span/199989/1 "2019-09-18T11:26:08Z")

</div>

Hey,

I have a custom Kafka instrumentation solution which starts a new transaction at reception (KafkaListener interceptor) and correlate it with the producer transaction (see [this thread for more info](https://discuss.elastic.co/t/spring-kafka-instrumentation-kafkalistenerendpointcontainer-mono-thread/193810)). One of the issue I encounter is that Kafka is used to broadcast events, all the microservices consume the events but depending on the some logic, only a small subset execute the message, the rest of the service just discard the event after reception.

This makes my APM transaction view quite unreadable because a lot of transactions are showing up for every single service just to announce the reception of the event but only a few actually do something.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/8/4/84b02daed2142e9312eeb277a38d084fc3378a72.png)

I know this is related to our architecture and the way we built it but I was wondering if there was a way using the API to discard/delete a transaction based on a certain condition or use a label to hide it from the transaction view ?

Thank you

* * *

**Kibana version** : 7.3.0  
**Elasticsearch version** : 7.3.0  
**APM Server version** : 7.3.0  
**APM Agent language and version** : java 1.8.0  
**Browser version** : n/a  
**Original install method (e.g. download page, yum, deb, from source, etc.) and version** : Kubernetes environment (Docker image)  
**Fresh install or upgraded from other version?** Fresh install  
**Is there anything special in your setup?** No  
**Other components** : Spring-boot:2.1.0.RELEASE, spirng-kafka:2.2.7-RELEASE

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [September 18, 2019, 12:21pm UTC](https://discuss.elastic.co/t/hide-or-discard-a-transaction-or-span/199989/2 "2019-09-18T12:21:54Z")

</div>

Hi and thanks for the question!

Please take a look at [this issue](https://github.com/elastic/apm-agent-java/issues/845), which asks for the ability to discard transactions for other reasons.  
Would the API suggested there answer your needs?

---

<div class="post-metadata">

**Author:** ![gregjeanmart](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gregjeanmart](https://discuss.elastic.co/u/gregjeanmart)\
**Post date:** [September 18, 2019, 12:43pm UTC](https://discuss.elastic.co/t/hide-or-discard-a-transaction-or-span/199989/3 "2019-09-18T12:43:56Z")

</div>

Unfortunately it won't work because it's entirely programmatic and depends on the context of the message received.

But if a function `disableTransaction` or `disableSpan` were available I could programmatically use it when needed in the logic.  
Is this possible to consider this for the future release ?

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [September 18, 2019, 1:02pm UTC](https://discuss.elastic.co/t/hide-or-discard-a-transaction-or-span/199989/4 "2019-09-18T13:02:35Z")

</div>

> [@gregjeanmart](#):
>
> it's entirely programmatic and depends on the context of the message received.

So why can't you check the context and invoke `startTransactionWithRemoteParent` only where required (in your `surroundOnMessage` method)?

> [@gregjeanmart](#):
>
> But if a function `disableTransaction` or `disableSpan` were available I could programmatically use it when needed in the logic.

The way I read the suggestion in this issue is: **either** use the annotation API, or use a programmatic API for that (meaning- we should add both), so I assume this will answer what you are looking for. Please see [the clarification comment I added](https://github.com/elastic/apm-agent-java/issues/845#issuecomment-532673321) and upvote this issue if you find it useful.

---

<div class="post-metadata">

**Author:** ![gregjeanmart](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gregjeanmart](https://discuss.elastic.co/u/gregjeanmart)\
**Post date:** [September 19, 2019, 8:55am UTC](https://discuss.elastic.co/t/hide-or-discard-a-transaction-or-span/199989/5 "2019-09-19T08:55:21Z")

</div>

> [@Eyal\_Koren](#):
>
> > [@gregjeanmart](#):
> >
> > it's entirely programmatic and depends on the context of the message received.
> 
> So why can't you check the context and invoke `startTransactionWithRemoteParent` only where required (in your `surroundOnMessage` method)?

Yeah, technically I could do this but this would break the separation of concern between my integration layer / consumers (including the interceptor for tracing) and the business logic layer.  
That is why the function `Transaction#ignore` could be useful in my case.

> [@Eyal\_Koren](#):
>
> > [@gregjeanmart](#):
> >
> > But if a function `disableTransaction` or `disableSpan` were available I could programmatically use it when needed in the logic.
> 
> The way I read the suggestion in this issue is: **either** use the annotation API, or use a programmatic API for that (meaning- we should add both), so I assume this will answer what you are looking for. Please see [the clarification comment I added](https://github.com/elastic/apm-agent-java/issues/845#issuecomment-532673321) and upvote this issue if you find it useful.

I upvoted the issue, it would be nice to have for my usecase.

It's not a major issue for me at the moment, I can live with it 🙂

Thanks for your help

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 10, 2019, 4:55am UTC](https://discuss.elastic.co/t/hide-or-discard-a-transaction-or-span/199989/6 "2019-10-10T04:55:21Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
