# Elastic Apm java agent and spring boot with embedded jetty - All transactions get added to application#main

**URL:** <https://discuss.elastic.co/t/elastic-apm-java-agent-and-spring-boot-with-embedded-jetty-all-transactions-get-added-to-application-main/244329>\
**Category:** APM\
**Tags:** java\
**Created:** [August 10, 2020, 12:04am UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-and-spring-boot-with-embedded-jetty-all-transactions-get-added-to-application-main/244329 "2020-08-10T00:04:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul.joshi](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@rahul.joshi](https://discuss.elastic.co/u/rahul.joshi)\
**Post date:** [August 10, 2020, 12:04am UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-and-spring-boot-with-embedded-jetty-all-transactions-get-added-to-application-main/244329/1 "2020-08-10T00:04:03Z")

</div>

Turning on method tracing for spring-boot application that uses embedded jetty will add all RestController transactions to the "application#main" transaction as opposed to recording each call to the controller as a separate transaction.

Method tracing turned on by using:

`-Delastic.apm.trace_methods=net.company.*`

After turning on trace logging for the java elastic apm, I noticed that all http requests to the controller were starting at the QueuedThreadPool class in jetty. So I decided to exclude this class from elastic apm instrumentation like so:

`-Delastic.apm.classes_excluded_from_instrumentation=org.eclipse.jetty.util.thread.QueuedThreadPool`

Once i did the above I was able to see the controller requests being recored in kibana as separate transactions. Is this a good workaround for the issue?

Using the following versions of spring and elastic apm java agent:  
-Spring boot version being used is 2.0.2

- Elastic apm agent version being used was 1.12.0

**Other Things to note:**

1. If we don't turn on method tracing then controller requests will get recored as separate transactions without an issue. However...this means that we will not be able to see full traces in the code base..but rather just traces for http requests. So this is not an ideal solution.

2. This problem does NOT occur when the spring-boot application is using **embedded tomcat**. When method tracing is turned on the spring boot application with embedded tomcat, all rest calls to the restcontrollers are recored as separate transactions as expected.

Would like to know if anyone else is experiencing this.

---

<div class="post-metadata">

**Author:** ![felixbarny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/felixbarny/32/27341_2.png) [@felixbarny](https://discuss.elastic.co/u/felixbarny)\
**Post date:** [August 10, 2020, 7:22am UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-and-spring-boot-with-embedded-jetty-all-transactions-get-added-to-application-main/244329/2 "2020-08-10T07:22:56Z")

</div>

Hi and welcome to the forum 👋

I'd recommend using [profiler-inferred spans](https://www.elastic.co/guide/en/apm/agent/java/current/config-profiling.html#config-profiling-inferred-spans-enabled) rather than `trace_methods` to get more method-level visibility.

If you absolutely need to use `trace_methods` to trace all methods within your app (this is not recommended for production use!) try placing your `Application` class, which contains the `public static void main` method in a package that's not included in `trace_methods`.

---

<div class="post-metadata">

**Author:** ![rahul.joshi](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@rahul.joshi](https://discuss.elastic.co/u/rahul.joshi)\
**Post date:** [August 10, 2020, 4:43pm UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-and-spring-boot-with-embedded-jetty-all-transactions-get-added-to-application-main/244329/3 "2020-08-10T16:43:18Z")

</div>

Felix,  
Thanks for your suggestions. I will try both of them.  
-Rahul

---

<div class="post-metadata">

**Author:** ![rahul.joshi](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@rahul.joshi](https://discuss.elastic.co/u/rahul.joshi)\
**Post date:** [August 12, 2020, 5:00am UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-and-spring-boot-with-embedded-jetty-all-transactions-get-added-to-application-main/244329/4 "2020-08-12T05:00:56Z")

</div>

@felixbarny i tested out your workaround of putting the main application class in a different package and that worked as well. thanks!

---

<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:** [September 2, 2020, 1:01am UTC](https://discuss.elastic.co/t/elastic-apm-java-agent-and-spring-boot-with-embedded-jetty-all-transactions-get-added-to-application-main/244329/5 "2020-09-02T01:01:10Z")

</div>

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