Make elapsed time available in the `response` event hook

Open
#762 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Quiet
Tech stack
python
Domain
networking

Research direction

Start by tracing the response event hook lifecycle and the existing response.elapsed implementation. Determine where request timing is captured relative to request and response hooks, then verify that the actual request duration can be exposed to the response hook without including hook processing time.

Written by the indexing model from the issue text.

Description

Originally opened by @joaonc on 2023-05-23 20:12:14 in encode/httpx

There are two types of elapsed time on a response:

  • The current .elapsed that accounts for total time of request, including event hooks. This is what we have now (Related to https://github.com/encode/httpx/issues/655).
  • The elapsed time of the actual request, not taking into account the event hooks, which can take a significant amount of time, depending on what you're doing. This number is currently not available.

In many scenarios, we have request and/or response event hooks that do a time consuming process, but need the time of the actual request only, w/o event hooks. Prime example is logging the response in a response event hook and we want to include the elapsed time in the response.

Is it possible to add a mechanism in which:

  • We can access the elapsed time w/o the time to process event hooks.
  • Have that time available in the response hook.
Dominant language
Python
Stars
1.6k
Forks
103
Avg merge
1d 19h
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pydantic/httpx2

All issues in pydantic/httpx2

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.