elastic / elastic/apm-agent-python

gunicorn + uvicorn + ASGI + flask is not working

未关闭
#2,153 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
agent-python community triage
主要语言
Python
星标
431
派生
239
平均合并
5 天 10 小时
30 天内合并 PR
7

描述

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

1. Please use this repo: https://github.com/helloflask/flask-examples
2. `cd http`
3. Add a new file `run.py` with 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)

```
4. Now run with `gunicorn -w 4 run:app` or `gunicorn -w 4 -k uvicorn.workers.UvicornWorker run:asgi_app`
5. Now access http://127.0.0.1:8000 - once with just gunicorn and once with uvicorn
6. You will notice that with gunicorn, the transactions are captured, but with uvicorn, then home page transaction is not captured.
7. OS: [e.g. Mac]
- Python version: 3.11.6
- Framework and version: Flask
- Agent version: Latest

It seems related to #1331

贡献指南

打开贡献指南

调研方向

从 helloflask/flask-examples 的 http 示例中的 run.py 复现开始,并比较 issue 中显示的两个 Gunicorn 命令。验证 Flask WSGI 应用与使用 WsgiToAsgi 包装的应用的事务捕获情况,然后检查相关 issue #1331。当 ASGI 运行像 WSGI 运行一样捕获主页事务时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
flask, python
领域
backend, observability
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。