elastic / elastic/apm-agent-python
Automatic instrumention for custom modules/classes
- 主要语言
- Python
- 星标
- 431
- 派生
- 239
- 平均合并
- 5 天 10 小时
- 30 天内合并 PR
- 7
描述
**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.
贡献指南
调研方向
首先审查现有的 @capture_span 装饰器,以及 Django 应用程序的插桩方式。明确自动覆盖自定义模块和类的设计,包括针对文件、模块、目录、测试和 manage.py 的设置与排除项。当范围和配置行为达成一致,并且该功能已针对 Django 用例完成验证时,即可视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- django, python
- 领域
- backend, observability
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 32/100