Make transports monitoring easier #2580
Unanswered
sam-mosleh
asked this question in
Ideas
Replies: 3 comments
Can you explain to me what you mean here? |
0 replies
|
Right now, to monitor every request, we must create sub-classes for each transport: class MonitoredASGITransport(httpx.ASGITransport):
async def handle_async_request(
self,
request: httpx.Request,
) -> httpx.Response:
start_time = time.time()
response = await super().handle_async_request(request)
print("Request took", time.time() - start_time)
return responseSince it is redundant for each transport class to override async def monitored_handle_async_request(
self,
request: httpx.Request,
) -> httpx.Response:
start_time = time.time()
response = await old_handle(request)
print("Request took", time.time() - start_time)
return response
old_handle = httpx.AsyncBaseTransport.handle_async_request
httpx.AsyncBaseTransport.handle_async_request = monitored_handle_async_requestThis is achieved by having |
0 replies
|
@tomchristie By looking at the example commit I made, which is fully backward-compatible, you can review the entire change. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Currently, the only way to use public methods to monitor/instrument requests is to monkey-patch each transport class. By making
BaseTransport.handle_requestandAsyncBaseTransport.handle_async_requestsingle entry points to all transport subclasses, it would be much easier to monitor them all (by patching onlyBaseTransportandAsyncBaseTransport), something like the below:I would be happy to try to open a PR for this. Thanks!
All reactions