@@ -483,20 +483,36 @@ def _status_code_callback(s: str):
483
483
self ._metrics_manager .dec_num_ongoing_requests ()
484
484
485
485
latency_ms = (time .time () - start_time ) * 1000
486
+ self ._record_errors_and_metrics (
487
+ user_exception , status_code , latency_ms , request_metadata , request_args
488
+ )
489
+
490
+ if user_exception is not None :
491
+ raise user_exception from None
492
+
493
+ def _record_errors_and_metrics (
494
+ self ,
495
+ user_exception : Optional [BaseException ],
496
+ status_code : Optional [str ],
497
+ latency_ms : float ,
498
+ request_metadata : RequestMetadata ,
499
+ request_args : Tuple [Any ],
500
+ ):
501
+ http_method = self ._maybe_get_http_method (request_metadata , request_args )
502
+ http_route = request_metadata .route
503
+ call_method = request_metadata .call_method
486
504
if user_exception is None :
487
505
status_str = "OK"
488
506
elif isinstance (user_exception , asyncio .CancelledError ):
489
507
status_str = "CANCELLED"
490
508
else :
491
509
status_str = "ERROR"
492
510
493
- http_method = self ._maybe_get_http_method (request_metadata , request_args )
494
- http_route = request_metadata .route
495
511
# Set in _wrap_user_method_call.
496
512
logger .info (
497
513
access_log_msg (
498
514
method = http_method or "CALL" ,
499
- route = http_route or request_metadata . call_method ,
515
+ route = http_route or call_method ,
500
516
# Prefer the HTTP status code if it was populated.
501
517
status = status_code or status_str ,
502
518
latency_ms = latency_ms ,
@@ -509,9 +525,6 @@ def _status_code_callback(s: str):
509
525
was_error = user_exception is not None ,
510
526
)
511
527
512
- if user_exception is not None :
513
- raise user_exception from None
514
-
515
528
async def _call_user_generator (
516
529
self ,
517
530
request_metadata : RequestMetadata ,
0 commit comments