apm-agent-python
apm-agent-python copied to clipboard
gunicorn + uvicorn + ASGI + flask is not working
Describe the bug:
When I run as gunicorn -w 4 run:app using its own wsgi, then I see data in Kibana.
When I run as gunicorn -w 4 -k uvicorn.workers.UvicornWorker run:asgi_app, then I do not see the transactions showing up.
To Reproduce
- Please use this repo: https://github.com/helloflask/flask-examples
cd http- Add a new file
run.pywith the contents to convert flask WSGI to ASGI
from app import app
from asgiref.wsgi import WsgiToAsgi
# Convert the Flask WSGI app to ASGI
asgi_app = WsgiToAsgi(app)
if __name__ == '__main__':
app.run(debug=True)
- Now run with
gunicorn -w 4 run:apporgunicorn -w 4 -k uvicorn.workers.UvicornWorker run:asgi_app - Now access http://127.0.0.1:8000 - once with just gunicorn and once with uvicorn
- You will notice that with gunicorn, the transactions are captured, but with uvicorn, then home page transaction is not captured.
- OS: [e.g. Mac]
- Python version: 3.11.6
- Framework and version: Flask
- Agent version: Latest
It seems related to #1331
Thanks for reporting. What's the reason to run a wsgi framework in an asgi worker?
One of our teammates reported the issue and they use asgi with flask. And they reported that the issue happens only with uvicorn. So I just used this sample app to re-create the problem.