elastic / elastic/apm-agent-python

Automatic instrumention for custom modules/classes

Open
#642 2 comments 10 reactions 0 assignees View on GitHub
agent-python feature instrumentation
Dominant language
Python
Stars
431
Forks
239
Avg merge
5d 10h
Merged PRs (30d)
7

Description

**Is your feature request related to a problem? Please describe.**
Currently using APM with Django apps and `@capture_span` has been incredibly helpful in finding bottlenecks and optimizing performance. However when new functionality is added, its tedious for the developer to remember to apply the decorator everywhere.

While [explicit is better than implicit](https://www.python.org/dev/peps/pep-0020/), explicit also increases the likelihood that it's missed or forgotten, and at times (of which this may be one) implicit can be preferred when something useful comes for free in future development.

**Describe the solution you'd like**
An option to auto-instrument custom written modules and classes with `@capture_span` in a Django application would be a killer feature. Ideally this could just be a settings flag or included module. Additional useful configuration would be ignoring certain files, modules, or directories; for example for ignoring test code or unimportant-to-trace framework files like `manage.py` in Django.

**Describe alternatives you've considered**
We've looked into a couple different ways of solving this with code, such as programatically adding decorator to all [class functions](https://stackoverflow.com/questions/3467526/attaching-a-decorator-to-all-functions-within-a-class) or [module functions](https://stackoverflow.com/questions/38017401/patch-all-functions-in-module-with-decorator).

We've also considered using CI validation to validate on pull requests that the decorator was applied to new functionality, which would follow "explicit is better than implicit" more closely. This also might spawn a python module to check this, as experiments validating with a multi-line `grep` have been...hairy.

**Additional context**
As a final note, an argument could be made (although I'm sure someone will correct me) that monitoring is more a deployment concern than an application concern, and so more comprehensive automatic instrumentation without explicit references in source code could be appropriate.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.