apm-agent-python
apm-agent-python copied to clipboard
Automatic instrumention for custom modules/classes
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, 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 or module functions.
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.
Thanks for the request! This has been an idea we've been throwing around for awhile (the Java agent supports something like this), but it's not on our immediate roadmap. But now we have an issue for tracking it, so thank you! :)
Note to self: setuptools
entry_points
could be useful here.