@@ -42,73 +42,81 @@ def _patch_ray_remote():
42
42
old_remote = ray .remote
43
43
44
44
@functools .wraps (old_remote )
45
- def new_remote (f , * args , ** kwargs ):
46
- # type: (Callable[..., Any], *Any, **Any) -> Callable[..., Any]
45
+ def new_remote (f = None , * args , ** kwargs ):
46
+ # type: (Optional[Callable[..., Any]], *Any, **Any) -> Callable[..., Any]
47
+
47
48
if inspect .isclass (f ):
48
49
# Ray Actors
49
50
# (https://docs.ray.io/en/latest/ray-core/actors.html)
50
51
# are not supported
51
52
# (Only Ray Tasks are supported)
52
- return old_remote (f , * args , * kwargs )
53
-
54
- def _f (* f_args , _tracing = None , ** f_kwargs ):
55
- # type: (Any, Optional[dict[str, Any]], Any) -> Any
56
- """
57
- Ray Worker
58
- """
59
- _check_sentry_initialized ()
60
-
61
- transaction = sentry_sdk .continue_trace (
62
- _tracing or {},
63
- op = OP .QUEUE_TASK_RAY ,
64
- name = qualname_from_function (f ),
65
- origin = RayIntegration .origin ,
66
- source = TransactionSource .TASK ,
67
- )
68
-
69
- with sentry_sdk .start_transaction (transaction ) as transaction :
70
- try :
71
- result = f (* f_args , ** f_kwargs )
72
- transaction .set_status (SPANSTATUS .OK )
73
- except Exception :
74
- transaction .set_status (SPANSTATUS .INTERNAL_ERROR )
75
- exc_info = sys .exc_info ()
76
- _capture_exception (exc_info )
77
- reraise (* exc_info )
78
-
79
- return result
80
-
81
- rv = old_remote (_f , * args , * kwargs )
82
- old_remote_method = rv .remote
83
-
84
- def _remote_method_with_header_propagation (* args , ** kwargs ):
85
- # type: (*Any, **Any) -> Any
86
- """
87
- Ray Client
88
- """
89
- with sentry_sdk .start_span (
90
- op = OP .QUEUE_SUBMIT_RAY ,
91
- name = qualname_from_function (f ),
92
- origin = RayIntegration .origin ,
93
- ) as span :
94
- tracing = {
95
- k : v
96
- for k , v in sentry_sdk .get_current_scope ().iter_trace_propagation_headers ()
97
- }
98
- try :
99
- result = old_remote_method (* args , ** kwargs , _tracing = tracing )
100
- span .set_status (SPANSTATUS .OK )
101
- except Exception :
102
- span .set_status (SPANSTATUS .INTERNAL_ERROR )
103
- exc_info = sys .exc_info ()
104
- _capture_exception (exc_info )
105
- reraise (* exc_info )
106
-
107
- return result
108
-
109
- rv .remote = _remote_method_with_header_propagation
110
-
111
- return rv
53
+ return old_remote (f , * args , ** kwargs )
54
+
55
+ def wrapper (user_f ):
56
+ # type: (Callable[..., Any]) -> Any
57
+ def new_func (* f_args , _tracing = None , ** f_kwargs ):
58
+ # type: (Any, Optional[dict[str, Any]], Any) -> Any
59
+ _check_sentry_initialized ()
60
+
61
+ transaction = sentry_sdk .continue_trace (
62
+ _tracing or {},
63
+ op = OP .QUEUE_TASK_RAY ,
64
+ name = qualname_from_function (user_f ),
65
+ origin = RayIntegration .origin ,
66
+ source = TransactionSource .TASK ,
67
+ )
68
+
69
+ with sentry_sdk .start_transaction (transaction ) as transaction :
70
+ try :
71
+ result = user_f (* f_args , ** f_kwargs )
72
+ transaction .set_status (SPANSTATUS .OK )
73
+ except Exception :
74
+ transaction .set_status (SPANSTATUS .INTERNAL_ERROR )
75
+ exc_info = sys .exc_info ()
76
+ _capture_exception (exc_info )
77
+ reraise (* exc_info )
78
+
79
+ return result
80
+
81
+ if f :
82
+ rv = old_remote (new_func )
83
+ else :
84
+ rv = old_remote (* args , ** kwargs )(new_func )
85
+ old_remote_method = rv .remote
86
+
87
+ def _remote_method_with_header_propagation (* args , ** kwargs ):
88
+ # type: (*Any, **Any) -> Any
89
+ """
90
+ Ray Client
91
+ """
92
+ with sentry_sdk .start_span (
93
+ op = OP .QUEUE_SUBMIT_RAY ,
94
+ name = qualname_from_function (user_f ),
95
+ origin = RayIntegration .origin ,
96
+ ) as span :
97
+ tracing = {
98
+ k : v
99
+ for k , v in sentry_sdk .get_current_scope ().iter_trace_propagation_headers ()
100
+ }
101
+ try :
102
+ result = old_remote_method (* args , ** kwargs , _tracing = tracing )
103
+ span .set_status (SPANSTATUS .OK )
104
+ except Exception :
105
+ span .set_status (SPANSTATUS .INTERNAL_ERROR )
106
+ exc_info = sys .exc_info ()
107
+ _capture_exception (exc_info )
108
+ reraise (* exc_info )
109
+
110
+ return result
111
+
112
+ rv .remote = _remote_method_with_header_propagation
113
+
114
+ return rv
115
+
116
+ if f is not None :
117
+ return wrapper (f )
118
+ else :
119
+ return wrapper
112
120
113
121
ray .remote = new_remote
114
122
0 commit comments