elastic / elastic/apm-agent-python
Allow flexibility in automatic instrumentation
- Ngôn ngữ chính
- Python
- Star
- 431
- Fork
- 239
- Merge trung bình
- 5 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 7
Mô tả
**Is your feature request related to a problem? Please describe.**
Currently we have a single `INSTRUMENTED` config value that turns _all_ instrumentation on/off. I think it would be useful to have some more flexibility.
In my particular use case for example, I would like to customise the `requests` instrumentation in my project which requires me to disable the out-of-the-box instrumentation. The easiest way I've found to do this is:
- Set `INSTRUMENTED: false` in config
- Vendor in logic found in `elasticapm.instrumentation.register`, `elasticapm.instrumentation.control`, to customising the `_cls_register` set to include my own instrumentation for `requests`.
- (Additionally for flask) Subclass `elasticapm.contrib.flask.ElasticAPM`, overriding the `init_app` method so that I can register the `request_started`, `request_finished` signals.
Side note re: flask - I think this may be a bug, depending on your perspective. In other places in the project e.g. Django instrumentation, the `INSTRUMENTED` config value refers only to instrumentation logic found in `elasticapm.instrumentation` (`AbstractInstrumentedModule` subclasses). Whereas in the flask module, it additionally prevents registering of the above flask signals.
**Describe the solution you'd like**
A way to customise exactly what gets instrumented from config, opt-in and opt-out.
**Describe alternatives you've considered**
Possible implementations:
- Exclusion/inclusion override lists of modules to instrument, e.g.
```
Config:
instrument_exclude = ["requests", "celery"]
instrument_include = [("requests", my_custom_instrumentation_module_name)]
```
or
```
Config:
instrument_overrides = [
("requests", my_custom_instrumentation_module_name), # to replace
("celery", None), # to disable
]
```
- Config value that overrides `elasticapm.instrumentation.register._cls_register`. A "raw" solution. This however would require the client to specify the module names which are internal to `elasticapm` (probably less than ideal).
Does anyone have any thoughts on this? Please correct me if I have overlooked something that makes this easy in the current version. Thanks.
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với elasticapm.instrumentation.register, elasticapm.instrumentation.control và tập hợp _cls_register để hiểu cơ chế tự động instrumentation hiện tại. Xem xét elasticapm.contrib.flask.ElasticAPM.init_app và việc đăng ký các Flask signal của nó. Phần hoàn thành phải bao gồm một cơ chế cấu hình được xác định để lựa chọn hoặc thay thế instrumentation, đồng thời duy trì hành vi Flask dự kiến.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- django, flask, python
- Lĩnh vực
- backend, observability-sre
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 25/100