elastic / elastic/apm-agent-python
Django + Gunicorn integration on worker timeouts finish current transaction.
- 主要言語
- Python
- スター
- 431
- フォーク
- 239
- 平均マージ
- 5日 10時間
- マージ済み PR(30日)
- 7
説明
**Is your feature request related to a problem? Please describe.**
We are in the process of attempting to replace our Sentry integrations noticed that when we get the occasional endpoint that hits the 30 second gunicorn timeout, which causes a child process to get killed with a SystemExit(1)
`gunicorn/workers/base.py ~ln 203`
```
def handle_abort(self, sig, frame):
self.alive = False
self.cfg.worker_abort(self)
sys.exit(1)
```
The error/event shows in Sentry but not in APM. I believe this is because the parent gunicorn process does a hard kill on the child process (kill 9 SIGKILL) the current APM transaction isnt ended/finished.
**Describe the solution you'd like**
For APM to finish the transaction along with the error as an uncaught exception automagically.
**Describe alternatives you've considered**
Looking at gunicorn's hooks for on worker termination and doing something like this to handle it manually
https://docs.gunicorn.org/en/stable/settings.html#worker-abort
`gunicorn.conf.py`
```
from elasticapm import traces
def worker_abort(worker):
if span := traces.execution_context.get_span():
span.end()
if transaction := traces.execution_context.get_transaction():
transaction.end()
```
If this is a bad ideal thought let me know just something thought off off the cuff.
コントリビューションガイド
調査の方向性
gunicorn/workers/base.py の handle_abort 周辺に示されている timeout パスから始め、gunicorn.conf.py の worker_abort フックと比較してください。例で使用されている APM の実行コンテキスト span と transaction のエントリポイントを確認し、その後、worker の終了前に transaction を完了できるかどうかを判断してください。timeout エラーと transaction の両方が一貫して報告されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- django, python
- 領域
- backend, observability
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100