I'm running django (1.4) with gunicorn (0.17.4) and gevent. I want to have the gunicorn worker number available inside of django, so I can include it in log messages and statsd data for tracking purposes.
What I'm doing right now is I put a pre_request hook in my gunicorn config file which fakes a HTTP header
def pre_request(worker, req):
req.headers.append(("X-SONGZA-WORKER", str(worker.age)))
This works, but it seems kind of hacky. It's also messy because I need to process it for every request. It would be cleaner to do this in post_fork(), but I don't see how to communicate any information from the worker object available in pre_fork() to something that's visible inside django.