make-fetch-happen icon indicating copy to clipboard operation
make-fetch-happen copied to clipboard

[FEATURE] Add way to measure request duration if retry is enabled

Open rpaterson opened this issue 4 years ago • 1 comments

What / Why

I want to measure how long successful requests take, in order to calibrate my timeout so that only the slowest 5% of requests time out. If retry is disabled that's easy - simply record Date.now() before calling fetch() and then subtract it from Date.now() after the response is received. However if retry is enabled I can't figure out a way to measure the duration of the ultimately successful try.

The onRetry() callback is invoked before the sleep for the retry delay, so there's no way to measure how long the request actually took without including the retry delay, especially if the randomize retry option is enabled.

When

When retry is enabled

Where

  • n/a

How

Current Behavior

No way to measure successful request try duration if there were retries.

Expected Behavior

Somehow I would like this to be possible. For example perhaps we could add duration or startedAt to the returned response object?

Who

  • n/a

References

  • n/a

rpaterson avatar Jan 13 '20 13:01 rpaterson

Just noticed the x-fetch-attempts header - something like that could work as an interface for this - e.g. a new header x-fetch-started-at or x-fetch-duration.

rpaterson avatar Jan 13 '20 14:01 rpaterson