Custom instrumenting without decorators?

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?

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 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.

1 Like

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