# Custom instrumenting without decorators?

**URL:** <https://discuss.elastic.co/t/custom-instrumenting-without-decorators/156742>\
**Category:** APM\
**Created:** [November 14, 2018, 9:27pm UTC](https://discuss.elastic.co/t/custom-instrumenting-without-decorators/156742 "2018-11-14T21:27:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_H](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_h/32/33104_2.png) [@Mike\_H](https://discuss.elastic.co/u/Mike_H)\
**Post date:** [November 14, 2018, 9:27pm UTC](https://discuss.elastic.co/t/custom-instrumenting-without-decorators/156742/1 "2018-11-14T21:27:43Z")

</div>

Hey Guys, we're newbies to APM but we like what we see so far.

We have a few django services where we'd like to add some custom instrumenting, but we're hesitant to pollute our codebase with decorators, so is there a way to automatically instrument all function/method calls without having to add `@elasticapm.capture_span()` decorators or otherwise modifying the source code?

---

<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:** [November 16, 2018, 1:55pm UTC](https://discuss.elastic.co/t/custom-instrumenting-without-decorators/156742/2 "2018-11-16T13:55:00Z")

</div>

Hi @Mike_H

A tracing profiler like the Elastic APM Python Agent isn't a great fit for instrumenting _all_ function/method calls. Every call we instrument comes with a little bit of overhead. This is acceptable when instrumenting calls that are known to take some time (e.g. when they involve some kind of I/O, like database calls or HTTP requests), but when instrumenting calls that only take microseconds to execute, the overhead starts to dominate.

We suggest to use a statistical profiler like [py-spy](https://github.com/benfred/py-spy) to find slow calls e.g. by running your test suite, and then use `elasticapm.capture_span()` to instrument the calls that seem slowest according to the statistical profiler. This will then give you contextual information about those calls that a statistical profiler can't give.

---

<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 7, 2018, 9:55am UTC](https://discuss.elastic.co/t/custom-instrumenting-without-decorators/156742/3 "2018-12-07T09:55:02Z")

</div>

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