Skip to content

Commit a682198

Browse files
fix(ray): Actor class decorator with arguments (#5230)
Always default to Ray's unchanged `remote` decorator when patching actor classes. Previously, using the `remote` decorator with arguments triggered a code path only intended for patching remote functions. Closes #5225
1 parent 5261223 commit a682198

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

sentry_sdk/integrations/ray.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ def new_remote(f=None, *args, **kwargs):
5454

5555
def wrapper(user_f):
5656
# type: (Callable[..., Any]) -> Any
57+
if inspect.isclass(user_f):
58+
# Ray Actors
59+
# (https://docs.ray.io/en/latest/ray-core/actors.html)
60+
# are not supported
61+
# (Only Ray Tasks are supported)
62+
return old_remote(*args, **kwargs)(user_f)
63+
5764
@functools.wraps(user_f)
5865
def new_func(*f_args, _sentry_tracing=None, **f_kwargs):
5966
# type: (Any, Optional[dict[str, Any]], Any) -> Any

tests/integrations/ray/test_ray.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ def example_task():
183183
shutil.rmtree(ray_temp_dir, ignore_errors=True)
184184

185185

186-
def test_tracing_in_ray_actors():
186+
# Arbitrary keyword argument to test all decorator paths
187+
@pytest.mark.parametrize("remote_kwargs", [{}, {"namespace": "actors"}])
188+
def test_tracing_in_ray_actors(remote_kwargs):
187189
setup_sentry()
188190

189191
ray.init(
@@ -194,16 +196,30 @@ def test_tracing_in_ray_actors():
194196
)
195197

196198
# Setup ray actor
197-
@ray.remote
198-
class Counter:
199-
def __init__(self):
200-
self.n = 0
199+
if remote_kwargs:
201200

202-
def increment(self):
203-
with sentry_sdk.start_span(op="task", name="example actor execution"):
204-
self.n += 1
201+
@ray.remote(**remote_kwargs)
202+
class Counter:
203+
def __init__(self):
204+
self.n = 0
205+
206+
def increment(self):
207+
with sentry_sdk.start_span(op="task", name="example actor execution"):
208+
self.n += 1
209+
210+
return sentry_sdk.get_client().transport.envelopes
211+
else:
205212

206-
return sentry_sdk.get_client().transport.envelopes
213+
@ray.remote
214+
class Counter:
215+
def __init__(self):
216+
self.n = 0
217+
218+
def increment(self):
219+
with sentry_sdk.start_span(op="task", name="example actor execution"):
220+
self.n += 1
221+
222+
return sentry_sdk.get_client().transport.envelopes
207223

208224
with sentry_sdk.start_transaction(op="task", name="ray test transaction"):
209225
counter = Counter.remote()

0 commit comments

Comments
 (0)