# APM Tracer doesn't show Python code time

**URL:** <https://discuss.elastic.co/t/apm-tracer-doesnt-show-python-code-time/210063>\
**Category:** APM\
**Tags:** python\
**Created:** [December 1, 2019, 1:51pm UTC](https://discuss.elastic.co/t/apm-tracer-doesnt-show-python-code-time/210063 "2019-12-01T13:51:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChillarAnand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chillaranand/32/58585_2.png) [@ChillarAnand](https://discuss.elastic.co/u/ChillarAnand)\
**Post date:** [December 1, 2019, 1:51pm UTC](https://discuss.elastic.co/t/apm-tracer-doesnt-show-python-code-time/210063/1 "2019-12-01T13:51:36Z")

</div>

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.

 ![33%20PM](https://us1.discourse-cdn.com/elastic/original/3X/8/7/87612aeab40209d0bb121b1b8927b0105ac50161.png)

 ![22%20PM](https://us1.discourse-cdn.com/elastic/original/3X/c/6/c6786ee00b3e79ac210e85161708245bdd5741f8.png)

---

<div class="post-metadata">

**Author:** ![beniwohli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beniwohli/32/21256_2.png) [@beniwohli](https://discuss.elastic.co/u/beniwohli)\
**Post date:** [December 1, 2019, 2:18pm UTC](https://discuss.elastic.co/t/apm-tracer-doesnt-show-python-code-time/210063/2 "2019-12-01T14:18:34Z")

</div>

Hi @ChillarAnand

if you have a hunch where your code might be slow, you can use [`capture_span`](https://www.elastic.co/guide/en/apm/agent/python/current/instrumenting-custom-code.html) 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](https://github.com/benfred/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](https://github.com/elastic/apm/issues/121).

---

<div class="post-metadata">

**Author:** ![ChillarAnand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chillaranand/32/58585_2.png) [@ChillarAnand](https://discuss.elastic.co/u/ChillarAnand)\
**Post date:** [December 1, 2019, 2:39pm UTC](https://discuss.elastic.co/t/apm-tracer-doesnt-show-python-code-time/210063/3 "2019-12-01T14:39:15Z")

</div>

Thanks, @beniwohli

Long back I was using Opbeat which used to profile Python code. I assumed APM also does the same thing.

---

<div class="post-metadata">

**Author:** ![beniwohli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/beniwohli/32/21256_2.png) [@beniwohli](https://discuss.elastic.co/u/beniwohli)\
**Post date:** [December 1, 2019, 9:21pm UTC](https://discuss.elastic.co/t/apm-tracer-doesnt-show-python-code-time/210063/4 "2019-12-01T21:21:55Z")

</div>

Hey @ChillarAnand

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.

Cheers  
Beni

---

<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:** [December 22, 2019, 5:21pm UTC](https://discuss.elastic.co/t/apm-tracer-doesnt-show-python-code-time/210063/5 "2019-12-22T17:21:59Z")

</div>

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