@@ -369,22 +369,21 @@ async def process_pdus_for_room(room_id: str):
369369
370370 async def process_pdu (pdu : EventBase ) -> JsonDict :
371371 event_id = pdu .event_id
372- with pdu_process_time .time ():
373- with nested_logging_context (event_id ):
374- try :
375- await self ._handle_received_pdu (origin , pdu )
376- return {}
377- except FederationError as e :
378- logger .warning ("Error handling PDU %s: %s" , event_id , e )
379- return {"error" : str (e )}
380- except Exception as e :
381- f = failure .Failure ()
382- logger .error (
383- "Failed to handle PDU %s" ,
384- event_id ,
385- exc_info = (f .type , f .value , f .getTracebackObject ()), # type: ignore
386- )
387- return {"error" : str (e )}
372+ with nested_logging_context (event_id ):
373+ try :
374+ await self ._handle_received_pdu (origin , pdu )
375+ return {}
376+ except FederationError as e :
377+ logger .warning ("Error handling PDU %s: %s" , event_id , e )
378+ return {"error" : str (e )}
379+ except Exception as e :
380+ f = failure .Failure ()
381+ logger .error (
382+ "Failed to handle PDU %s" ,
383+ event_id ,
384+ exc_info = (f .type , f .value , f .getTracebackObject ()), # type: ignore
385+ )
386+ return {"error" : str (e )}
388387
389388 await concurrently_execute (
390389 process_pdus_for_room , pdus_by_room .keys (), TRANSACTION_CONCURRENCY_LIMIT
@@ -932,9 +931,13 @@ async def _process_incoming_pdus_in_room_inner(
932931 exc_info = (f .type , f .value , f .getTracebackObject ()), # type: ignore
933932 )
934933
935- await self .store .remove_received_event_from_staging (
934+ received_ts = await self .store .remove_received_event_from_staging (
936935 origin , event .event_id
937936 )
937+ if received_ts is not None :
938+ pdu_process_time .observe (
939+ (self ._clock .time_msec () - received_ts ) / 1000
940+ )
938941
939942 # We need to do this check outside the lock to avoid a race between
940943 # a new event being inserted by another instance and it attempting
0 commit comments