ClientSession signals to track events related to each request. #2313
Description
The current implementation of ClientSession does not provide a clean and straightforward way to track events related to each request.
Right now in our organization, we are tracking the time spent and the status code overriding the _request private method and implementing a customized ClientSession. The solution that we have implemented is far from being the best.
To address this situation, ClientSession could implement a new set of methods that will allow the user to instrumentalize different metrics related to each request. The following is a list of new methods that will be used for this purpose:
on_pre_requestExecuted before the request is sent.on_post_requestExecuted after the request is sent.on_queuedExecuted when the request is queued.on_unqueuedExecuted when the request is unqueued.on_create_connExecuted when a new connection is created.
We are planning on have support for three new metrics: number of TCP connections created, number of operations queued because the limit has been reached, time spent in the queue
The previous methods will allow us to track all of these metrics.
Any comments appreciate.