elastic / elastic/apm-agent-python

Django + Gunicorn integration on worker timeouts finish current transaction.

Aperta
#1,479 10 commenti 0 reazioni 0 assegnatari Vedi su GitHub
agent-python bug community
Lingua principale
Python
Stelle
431
Fork
239
Merge medio
5g 10h
PR unite (30g)
7

Descrizione

**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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.