When looking at trace, APM shows a timeline only DB queries but not for Python code. Is it possible to show this timeline for Python code as well? Otherwise, how is it possible to find the slowest part of the code.
if you have a hunch where your code might be slow, you can use
capture_span to instrument a certain code path.
For generally finding slow code paths, a tracer like Elastic APM is often not the best solution, as every traced function call or code block comes with a bit of overhead. If every function call is traced (which would be necessary if you don't know where the slow code paths are), the overhead quickly dwarfs the traced code itself. For such cases, a sampling profiler like py-spy is better suited. Often, it makes sense to combine the two: find slow code paths using a profiler in your development environment, then instrument those code paths using
capture_span to monitor them on your production systems.
In the longer term, we are looking into adding a profiler to Elastic APM, but that's quite a bit in the future. You can follow progress here: https://github.com/elastic/apm/issues/121.
Long back I was using Opbeat which used to profile Python code. I assumed APM also does the same thing.
Great to see a former Opbeat user! The Opbeat agent worked in the same way as the Elastic APM agent (in fact, the Elastic APM agent is just a continuation of the Opbeat agent). Profiling wasn't something we did back in the Opbeat days. The good news is that we've grown the team quite a bit since then, and that enables us to look into such big ticket features like profiling.