@@ -209,7 +209,9 @@ def start_attempt(self) -> None:
209209 if self .backoff_generator and len (self .completed_attempts ) > 0 :
210210 # find the attempt's backoff by sending attempt number to generator
211211 # generator will return the backoff time in seconds, so convert to ms
212- backoff_ms = self .backoff_generator .send (len (self .completed_attempts ) - 1 ) * 1000
212+ backoff_ms = (
213+ self .backoff_generator .send (len (self .completed_attempts ) - 1 ) * 1000
214+ )
213215 else :
214216 backoff_ms = 0
215217
@@ -307,14 +309,14 @@ def end_attempt_with_status(self, status: StatusCode | Exception) -> None:
307309 return self ._handle_error (
308310 INVALID_STATE_ERROR .format ("end_attempt_with_status" , self .state )
309311 )
310-
312+ if isinstance (status , Exception ):
313+ status = self ._exc_to_status (status )
314+ duration_seconds = time .monotonic () - self .active_attempt .start_time .monotonic
311315 new_attempt = CompletedAttemptMetric (
312316 start_time = self .active_attempt .start_time .utc ,
313317 first_response_latency_ms = self .active_attempt .first_response_latency_ms ,
314- duration_ms = (time .monotonic () - self .active_attempt .start_time .monotonic ) * 1000 ,
315- end_status = self ._exc_to_status (status )
316- if isinstance (status , Exception )
317- else status ,
318+ duration_ms = duration_seconds * 1000 ,
319+ end_status = status ,
318320 gfe_latency_ms = self .active_attempt .gfe_latency_ms ,
319321 application_blocking_time_ms = self .active_attempt .application_blocking_time_ms ,
320322 backoff_before_attempt_ms = self .active_attempt .backoff_before_attempt_ms ,
0 commit comments