pydantic / pydantic/httpx2

Make elapsed time available in the `response` event hook

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

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
78
Avg merge
8h 59m
Merged PRs (30d)
24

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.

Contributor guide

Open the contributing guide

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.