hashicorp / go-retryablehttp

Retryable HTTP client in Go
Mozilla Public License 2.0
1.99k stars 251 forks source link

Measure latency/request duration and provide it for logging purpose #235

Open SirSova opened 2 months ago

SirSova commented 2 months ago

Right now it's hardly possible to get an attempt latency for a log like "request failed after 300ms, attempts: 3". It's quite important to know how much time was actually spent per each request, since the external service can abort it at any moment. And in case the backoff didn't help -- to know the total duration in the default error within the number of attempts.

Ideally, ResponseLogHook could be extended with more arguments like attemptsNumber, attemptLatency (last one), totalLatency (sum of all attempts + delays) All of it can be structured under some "Details" structure.

For ErrorHandler it could also be useful to have the final total latency.