Elapsed time of response in logs #1965
|
Hi there! logger = logging.getLogger("http")
def my_log(response):
extra = {
"response_time": response.elapsed.seconds()
}
logger.info("Get response", extra=extra)
client = httpx.Client(event_hooks={"response": [my_log]})But after update httpx version from 0.18.2 to 0.19.0 event hooks are now also called for any additional redirect or auth requests.So I catch exception like this "'.elapsed' may only be accessed after the response has been read or closed." How can I collect or calculate elapsed time of response now? |
Answered by
lovelydinosaur
Jan 28, 2022
Replies: 1 comment
|
You can use You won't properly be supporting streaming responses at that point, but if you wanted to track the total elapsed time in an event hook that makes sense, because the response isn't complete until you've fully downloaded it. |
0 replies
Answer selected by
santasdi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
response.read()inside your event handler.You won't properly be supporting streaming responses at that point, but if you wanted to track the total elapsed time in an event hook that makes sense, because the response isn't complete until you've fully downloaded it.