Skip to content

Commit 1848ea3

Browse files
committed
feat(ray): better handle the absence of ray.init()
1 parent f96a1dc commit 1848ea3

14 files changed

+783
-254
lines changed

ddtrace/contrib/internal/ray/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111
you have to follow one of the two methods below:
1212
1313
The recommended way to instrument Ray, is to instrument the Ray cluster.
14-
You can do it by starting the Ray head with a tracing startup hook::
1514
16-
ray start --head --tracing-startup-hook=ddtrace.contrib.ray:setup_tracing
15+
You can do it by starting the Ray head using ddtrace-run::
1716
18-
Otherwise, you can specify the tracing hook in `ray.init()` using::
17+
DD_PATCH_MODULES="ray:true, aiohttp:false, grpc:false, requests:false" ddtrace-run ray start --head
1918
20-
ray.init(_tracing_startup_hook="ddtrace.contrib.ray:setup_tracing")
19+
DD_PATCH_MODULES will allow to reduce noise.
2120
22-
Note that this method does not provide full tracing capabilities.
21+
You can do it by starting the Ray head with a tracing startup hook::
22+
23+
ray start --head --tracing-startup-hook=ddtrace.contrib.ray:setup_tracing
2324
25+
Note that this method does not provide full tracing capabilities if ``ray.init()`` is not called at the top
26+
of your job scripts.
2427
2528
Configuration
2629
~~~~~~~~~~~~~

ddtrace/contrib/internal/ray/patch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,10 @@ def traced_submit_task(wrapped, instance, args, kwargs):
153153
# This is done under a lock as multiple task could be submit at the same time
154154
# and thus try to modify the signature as the same time
155155
with instance._inject_lock:
156-
if not getattr(instance._function, "_dd_trace_wrapped", False):
156+
if instance._function_signature is None:
157157
instance._function = _wrap_remote_function_execution(instance._function)
158158
instance._function.__signature__ = _inject_dd_trace_ctx_kwarg(instance._function)
159159
instance._function_signature = extract_signature(instance._function)
160-
instance._function._dd_trace_wrapped = True
161160

162161
with tracer.trace(
163162
"task.submit",

tests/contrib/ray/jobs/actor_and_task.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/contrib/ray/jobs/actor_interactions.py

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ray
2+
3+
4+
@ray.remote
5+
class Counter:
6+
def __init__(self):
7+
self.value = 0
8+
9+
def increment(self):
10+
self.value += 1
11+
return self.value
12+
13+
def get_value(self):
14+
return self.value
15+
16+
17+
def main():
18+
counter = Counter.remote()
19+
result = ray.get(counter.increment.remote())
20+
assert result == 1, f"Expected 1, got {result}"
21+
22+
23+
if __name__ == "__main__":
24+
main()

tests/contrib/ray/jobs/error_in_task.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/contrib/ray/jobs/nested_tasks.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/contrib/ray/jobs/simple_actor.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/contrib/ray/jobs/simple_task.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/contrib/ray/jobs/simple_wait.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)