@@ -728,25 +728,31 @@ def sync_wrapper(
728728 )
729729 )
730730 except Exception as exc :
731+ t2 = time .time ()
731732 if GCP_SERVERLESS is True :
732- t2 = time .time ()
733733 execution_duration = max (t2 - t1 , 0.1 )
734- self .record_usage (
735- ** self ._extract_usage_params_from_func_kwargs (
736- usage_fps = usage_fps ,
737- usage_api_key = usage_api_key ,
738- usage_workflow_id = usage_workflow_id ,
739- usage_workflow_preview = usage_workflow_preview ,
740- usage_inference_test_run = usage_inference_test_run ,
741- usage_billable = usage_billable ,
742- execution_duration = execution_duration ,
743- func = func ,
744- category = category ,
745- exc = str (exc ),
746- args = args ,
747- kwargs = kwargs ,
748- )
734+ else :
735+ execution_duration = t2 - t1
736+ exc_type = type (exc ).__name__
737+ if hasattr (exc , "inner_error_type" ):
738+ exc_type = exc .inner_error_type
739+ exc_str = f"{ exc_type } : { str (exc )} "
740+ self .record_usage (
741+ ** self ._extract_usage_params_from_func_kwargs (
742+ usage_fps = usage_fps ,
743+ usage_api_key = usage_api_key ,
744+ usage_workflow_id = usage_workflow_id ,
745+ usage_workflow_preview = usage_workflow_preview ,
746+ usage_inference_test_run = usage_inference_test_run ,
747+ usage_billable = usage_billable ,
748+ execution_duration = execution_duration ,
749+ func = func ,
750+ category = category ,
751+ exc = exc_str ,
752+ args = args ,
753+ kwargs = kwargs ,
749754 )
755+ )
750756 raise
751757 return res
752758
@@ -786,25 +792,31 @@ async def async_wrapper(
786792 )
787793 )
788794 except Exception as exc :
795+ t2 = time .time ()
789796 if GCP_SERVERLESS is True :
790- t2 = time .time ()
791797 execution_duration = max (t2 - t1 , 0.1 )
792- await self .async_record_usage (
793- ** self ._extract_usage_params_from_func_kwargs (
794- usage_fps = usage_fps ,
795- usage_api_key = usage_api_key ,
796- usage_workflow_id = usage_workflow_id ,
797- usage_workflow_preview = usage_workflow_preview ,
798- usage_inference_test_run = usage_inference_test_run ,
799- usage_billable = usage_billable ,
800- execution_duration = execution_duration ,
801- func = func ,
802- category = category ,
803- exc = str (exc ),
804- args = args ,
805- kwargs = kwargs ,
806- )
798+ else :
799+ execution_duration = t2 - t1
800+ exc_type = type (exc ).__name__
801+ if hasattr (exc , "inner_error_type" ):
802+ exc_type = exc .inner_error_type
803+ exc_str = f"{ exc_type } : { str (exc )} "
804+ await self .async_record_usage (
805+ ** self ._extract_usage_params_from_func_kwargs (
806+ usage_fps = usage_fps ,
807+ usage_api_key = usage_api_key ,
808+ usage_workflow_id = usage_workflow_id ,
809+ usage_workflow_preview = usage_workflow_preview ,
810+ usage_inference_test_run = usage_inference_test_run ,
811+ usage_billable = usage_billable ,
812+ execution_duration = execution_duration ,
813+ func = func ,
814+ category = category ,
815+ exc = exc_str ,
816+ args = args ,
817+ kwargs = kwargs ,
807818 )
819+ )
808820 raise
809821 return res
810822
0 commit comments