diff --git a/sentry_sdk/integrations/ray.py b/sentry_sdk/integrations/ray.py index 08e78b7585..cef3446d0e 100644 --- a/sentry_sdk/integrations/ray.py +++ b/sentry_sdk/integrations/ray.py @@ -54,6 +54,13 @@ def new_remote(f=None, *args, **kwargs): def wrapper(user_f): # type: (Callable[..., Any]) -> Any + if inspect.isclass(user_f): + # Ray Actors + # (https://docs.ray.io/en/latest/ray-core/actors.html) + # are not supported + # (Only Ray Tasks are supported) + return old_remote(*args, **kwargs)(user_f) + @functools.wraps(user_f) def new_func(*f_args, _sentry_tracing=None, **f_kwargs): # type: (Any, Optional[dict[str, Any]], Any) -> Any diff --git a/tests/integrations/ray/test_ray.py b/tests/integrations/ray/test_ray.py index 6aaced391e..dcbf8f456b 100644 --- a/tests/integrations/ray/test_ray.py +++ b/tests/integrations/ray/test_ray.py @@ -183,7 +183,9 @@ def example_task(): shutil.rmtree(ray_temp_dir, ignore_errors=True) -def test_tracing_in_ray_actors(): +# Arbitrary keyword argument to test all decorator paths +@pytest.mark.parametrize("remote_kwargs", [{}, {"namespace": "actors"}]) +def test_tracing_in_ray_actors(remote_kwargs): setup_sentry() ray.init( @@ -194,16 +196,30 @@ def test_tracing_in_ray_actors(): ) # Setup ray actor - @ray.remote - class Counter: - def __init__(self): - self.n = 0 + if remote_kwargs: - def increment(self): - with sentry_sdk.start_span(op="task", name="example actor execution"): - self.n += 1 + @ray.remote(**remote_kwargs) + class Counter: + def __init__(self): + self.n = 0 + + def increment(self): + with sentry_sdk.start_span(op="task", name="example actor execution"): + self.n += 1 + + return sentry_sdk.get_client().transport.envelopes + else: - return sentry_sdk.get_client().transport.envelopes + @ray.remote + class Counter: + def __init__(self): + self.n = 0 + + def increment(self): + with sentry_sdk.start_span(op="task", name="example actor execution"): + self.n += 1 + + return sentry_sdk.get_client().transport.envelopes with sentry_sdk.start_transaction(op="task", name="ray test transaction"): counter = Counter.remote()