@@ -17,19 +17,26 @@ class Trackable(object):
1717 def __init__ (self , function ):
1818 lock = Lock ()
1919 self .function = function
20+ self ._success = None
21+ self ._caller_name = None
22+ self ._func_name_to_track = None
2023 with lock :
2124 Trackable .registered .add (function .__name__ )
2225 functools .update_wrapper (self , function )
2326
24- def __call__ (self , * args , ** kwargs ):
27+ def should_track (self ):
28+ if self ._caller_name not in Trackable .registered or self ._func_name_to_track in always_trackable_func_names :
29+ return True
30+ return False
31+
32+ def track (self , * args , ** kwargs ):
2533 try :
26- func_name_to_track = self .function .__name__
27- caller_name = sys ._getframe (1 ).f_code .co_name
28- if caller_name not in Trackable .registered or func_name_to_track in always_trackable_func_names :
29- data = getattr (parsers , func_name_to_track )(* args , ** kwargs )
34+ if self .should_track ():
35+ data = getattr (parsers , self ._func_name_to_track )(* args , ** kwargs )
3036 user_id = _api .user_id
3137 event_name = data ['event_name' ]
3238 properties = data ['properties' ]
39+ properties ['Success' ] = self ._success
3340 default = get_default (
3441 _api .team_name ,
3542 _api .user_id ,
@@ -39,6 +46,19 @@ def __call__(self, *args, **kwargs):
3946 properties = {** default , ** properties }
4047 if "pytest" not in sys .modules :
4148 mp .track (user_id , event_name , properties )
42- except :
49+ except Exception as e :
4350 pass
44- return self .function (* args , ** kwargs )
51+
52+
53+ def __call__ (self , * args , ** kwargs ):
54+ try :
55+ self ._caller_name = sys ._getframe (1 ).f_code .co_name
56+ self ._func_name_to_track = self .function .__name__
57+ ret = self .function (* args , ** kwargs )
58+ self ._success = True
59+ self .track (* args , ** kwargs )
60+ except Exception as e :
61+ self ._success = False
62+ self .track (* args , ** kwargs )
63+ raise e
64+ return ret
0 commit comments