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.
Very low overhead.
No code changes required.
Does not work on Windows and on OpenJ9.
The duration of profiler-inferred spans are not exact measurements, only estimates.
If you know which methods you want to monitor…edit
API/Codeedit
Use the API or OpenTracing bridge to manually create spans for methods of interest.
Most flexible.
Incorrect API usage may lead to invalid traces (scope leaks).
Annotationsedit
Annotations can be placed on top of methods to automatically create spans for them.
Easier and more robust than the API.
Less flexible on its own, but can be combined with the API.
Configuration-basededit
Use a configuration option to specify additional methods to instrument.
No need to modify source code.
Possible to monitor code in third-party libraries.
Match methods via wildcards.
Easy to overuse which hurts runtime and startup performance.