elastic / elastic/apm-agent-python

Django + Gunicorn integration on worker timeouts finish current transaction.

Open
#1,479 10 comments 0 reactions 0 assignees View on GitHub
agent-python bug community
Dominant language
Python
Stars
431
Forks
239
Avg merge
5d 10h
Merged PRs (30d)
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.