make-fetch-happen
make-fetch-happen copied to clipboard
[FEATURE] Add way to measure request duration if retry is enabled
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
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
.