How to find slow methodsedit

Identifying a problematic service is only half of the battle when diagnosing application slowdowns. Luckily, the Elastic APM Java Agent provides multiple ways to get method-level insights into your code. This can help you diagnose slow requests due to heavy computations, inefficient algorithms, or similar problems not related to interactions between services.

If you don’t know which methods you want to monitor…​edit

Sampling-based profileredit

Find out which part of your code is making your application slow by periodically recording running methods with a sampling-based profiler.

green check Very low overhead.
green check No code changes required.
red x Does not work on Windows and on OpenJ9.
red x The duration of profiler-inferred spans are not exact measurements, only estimates.

Learn more

If you know which methods you want to monitor…​edit


Use the API or OpenTracing bridge to manually create spans for methods of interest.

green check Most flexible.
red x Incorrect API usage may lead to invalid traces (scope leaks).

Learn more


Annotations can be placed on top of methods to automatically create spans for them.

green check Easier and more robust than the API.
red x Less flexible on its own, but can be combined with the API.

Learn more


Use a configuration option to specify additional methods to instrument.

green check No need to modify source code.
green check Possible to monitor code in third-party libraries.
green check Match methods via wildcards.
red x Easy to overuse which hurts runtime and startup performance.

Learn more