elastic / elastic/apm-agent-python
Django + Gunicorn integration on worker timeouts finish current transaction.
- Langage dominant
- Python
- Étoiles
- 431
- Forks
- 239
- Merge moyen
- 5 j 10 h
- PR mergées (30 j)
- 7
Description
**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.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par le chemin de timeout montré dans gunicorn/workers/base.py autour de handle_abort et comparez-le avec le hook worker_abort dans gunicorn.conf.py. Examinez les points d’entrée du span de contexte d’exécution APM et de la transaction utilisés dans l’exemple, puis déterminez si la transaction peut être terminée avant l’arrêt du worker ; le travail est considéré comme terminé lorsque les erreurs de timeout et les transactions sont toutes deux signalées de manière cohérente.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- django, python
- Domaine
- backend, observability
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100