aio-libs / aio-libs/aiohttp

New app signals proposal to track connections and requests

未关闭
#2,685 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Python
星标
16.5k
派生
2.4k
平均合并
17 小时 22 分钟
30 天内合并 PR
212

描述

## Long story short

Right now there is not a set of signals in place to track connections and request for Aiohttp web server. The proposal would implement the following subset of signals, attached to the application.

* `on_connection_created(app, context)` Triggered when a new connection has been created.
* `on_connection_closed(app, context)` Triggered when a connection has been closed.
* `on_request_start(app, context, request)` Triggered when a new request start.
* `on_request_end(app, context, request, response)` Triggered when a requests finishes.

All signals will receive as a parameter the app instance and a context that would help the user to pass information to the next semantic signal. For example, the `context` related with the connection will be instantiated when the `on_connection_created` is called and the value will be passed as a parameter for both connections methods, having the same for the request flavor.

These signals will be only triggered by the root app.

Taking into account that already exists a group of signals for the App and these differ a bit of the proposed ones, lack of context and so on. We could discuss on have a new module called `web_tracing` that will implement the same pattern as the client tracing [1], this might imply some name changing.

My 2cent about my cons with other ways to implement that:

* Middlewares are chained between the root app and nested apps, implement the request signals implicitly as a middleware IMHO is prone error and weak. Better having an ad-hoc set of signals that are never triggered by the nested apps.
* I would prefer to implement these signals out of the app scope, perhaps having them as a new parameter of the `run_app` that implements only these new signals. The problem with this solution is the incompatibility with environments that use the workers strategy to start the application such as `gunicorn`.

[1] https://github.com/aio-libs/aiohttp/blob/master/aiohttp/tracing.py

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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