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

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:


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:


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.

Hi and welcome to the forum :wave:

I'd recommend using profiler-inferred spans 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.

Thanks for your suggestions. I will try both of them.

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

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