# Elastic Java Agent unable to capture Kafka traces with Custom Threadpool

**URL:** <https://discuss.elastic.co/t/elastic-java-agent-unable-to-capture-kafka-traces-with-custom-threadpool/353597>\
**Category:** APM\
**Tags:** java\
**Created:** [February 19, 2024, 1:11pm UTC](https://discuss.elastic.co/t/elastic-java-agent-unable-to-capture-kafka-traces-with-custom-threadpool/353597 "2024-02-19T13:11:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Namita\_Jaokar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/namita_jaokar/32/104106_2.png) [@Namita\_Jaokar](https://discuss.elastic.co/u/Namita_Jaokar)\
**Post date:** [February 19, 2024, 1:11pm UTC](https://discuss.elastic.co/t/elastic-java-agent-unable-to-capture-kafka-traces-with-custom-threadpool/353597/1 "2024-02-19T13:11:49Z")

</div>

Hi,

I am using Java elastic APM agent version 1.36 with my kafka based application.  
The Kafka based application uses custom thread pool which is developed by using LinkedBlockingQueue for holding tasks.  
However, I am unable to get the kafka traces of the class that behaves as a Task for the worked threads. This task holds the logic to send messages to the kafka server.  
The same works when Java's inbuilt executor framework is used instead of custom threadpool.

The executor framework is supported by the apm agent is known to me but in case of custom threadpool implementations , Are the traces not captured?

I also tried to add the Task.java class of my sample application in the trace\_methods property but still unable to get the traces captured.

Is there any other way to get the trace captured? Please advise.

Thanks & Regards,  
Namita Jaokar

---

<div class="post-metadata">

**Author:** ![Jonas\_Kunz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_kunz/32/110740_2.png) [@Jonas\_Kunz](https://discuss.elastic.co/u/Jonas_Kunz)\
**Post date:** [February 20, 2024, 11:34am UTC](https://discuss.elastic.co/t/elastic-java-agent-unable-to-capture-kafka-traces-with-custom-threadpool/353597/2 "2024-02-20T11:34:24Z")

</div>

You'll need to manually propagate the tracing context in your custom executor:

When a task is added to your executor, you'll need to "remember" the currently active span for that task obtained via [ElasticAPM.currentSpan()](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html#api-current-span).

When you start executing the task (on the different thread), you'll need to [activate](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html#api-span-activate) the remembered span.

---

<div class="post-metadata">

**Author:** ![Namita\_Jaokar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/namita_jaokar/32/104106_2.png) [@Namita\_Jaokar](https://discuss.elastic.co/u/Namita_Jaokar)\
**Post date:** [February 26, 2024, 11:44am UTC](https://discuss.elastic.co/t/elastic-java-agent-unable-to-capture-kafka-traces-with-custom-threadpool/353597/3 "2024-02-26T11:44:38Z")

</div>

Thanks @Jonas_Kunz for the suggestion. Is there any way it can be handled in the elastic agent jar ?

Best Regards,  
Namita

---

<div class="post-metadata">

**Author:** ![Namita\_Jaokar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/namita_jaokar/32/104106_2.png) [@Namita\_Jaokar](https://discuss.elastic.co/u/Namita_Jaokar)\
**Post date:** [February 27, 2024, 10:26am UTC](https://discuss.elastic.co/t/elastic-java-agent-unable-to-capture-kafka-traces-with-custom-threadpool/353597/4 "2024-02-27T10:26:31Z")

</div>

Hi @Jonas_Kunz , Is there any example I can refer to for implementing the same.

Best Regards,  
Namita Jaokar

---

<div class="post-metadata">

**Author:** ![Jonas\_Kunz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jonas_kunz/32/110740_2.png) [@Jonas\_Kunz](https://discuss.elastic.co/u/Jonas_Kunz)\
**Post date:** [March 5, 2024, 8:09am UTC](https://discuss.elastic.co/t/elastic-java-agent-unable-to-capture-kafka-traces-with-custom-threadpool/353597/5 "2024-03-05T08:09:50Z")

</div>

> Is there any way it can be handled in the elastic agent jar ?

You could wirte a [custom plugin](https://www.elastic.co/guide/en/apm/agent/java/current/plugin-api.html).

> Is there any example I can refer to for implementing the same

I don't think so, you'll have to rely on the public API docs.

---

<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:** [April 2, 2024, 8:10am UTC](https://discuss.elastic.co/t/elastic-java-agent-unable-to-capture-kafka-traces-with-custom-threadpool/353597/6 "2024-04-02T08:10:44Z")

</div>

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