Skip to content

Commit d0c38a2

Browse files
test with and without kwargs
1 parent 50abe7d commit d0c38a2

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

tests/integrations/ray/test_ray.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,29 @@ def read_error_from_log(job_id, ray_temp_dir):
7474
return error
7575

7676

77+
def example_task():
78+
with sentry_sdk.start_span(op="task", name="example task step"):
79+
...
80+
81+
return sentry_sdk.get_client().transport.envelopes
82+
83+
84+
# RayIntegration must leave variadic keyword arguments at the end
85+
def example_task_with_kwargs(**kwargs):
86+
with sentry_sdk.start_span(op="task", name="example task step"):
87+
...
88+
89+
return sentry_sdk.get_client().transport.envelopes
90+
91+
7792
@pytest.mark.parametrize(
7893
"task_options", [{}, {"num_cpus": 0, "memory": 1024 * 1024 * 10}]
7994
)
80-
def test_tracing_in_ray_tasks(task_options):
95+
@pytest.mark.parametrize(
96+
"task",
97+
[example_task, example_task_with_kwargs],
98+
)
99+
def test_tracing_in_ray_tasks(task_options, task):
81100
setup_sentry()
82101

83102
ray.init(
@@ -87,22 +106,18 @@ def test_tracing_in_ray_tasks(task_options):
87106
}
88107
)
89108

90-
# RayIntegration must leave variadic keyword arguments at the end
91-
def example_task(**kwargs):
92-
with sentry_sdk.start_span(op="task", name="example task step"):
93-
...
94-
95-
return sentry_sdk.get_client().transport.envelopes
96-
97109
# Setup ray task, calling decorator directly instead of @,
98110
# to accommodate for test parametrization
99111
if task_options:
100-
example_task = ray.remote(**task_options)(example_task)
112+
example_task = ray.remote(**task_options)(task)
101113
else:
102-
example_task = ray.remote(example_task)
114+
example_task = ray.remote(task)
103115

104116
# Function name shouldn't be overwritten by Sentry wrapper
105-
assert example_task._function_name == "tests.integrations.ray.test_ray.example_task"
117+
assert (
118+
example_task._function_name
119+
== f"tests.integrations.ray.test_ray.{task.__name__}"
120+
)
106121

107122
with sentry_sdk.start_transaction(op="task", name="ray test transaction"):
108123
worker_envelopes = ray.get(example_task.remote())
@@ -116,17 +131,14 @@ def example_task(**kwargs):
116131
worker_transaction = worker_envelope.get_transaction_event()
117132
assert (
118133
worker_transaction["transaction"]
119-
== "tests.integrations.ray.test_ray.test_tracing_in_ray_tasks.<locals>.example_task"
134+
== f"tests.integrations.ray.test_ray.{task.__name__}"
120135
)
121136
assert worker_transaction["transaction_info"] == {"source": "task"}
122137

123138
(span,) = client_transaction["spans"]
124139
assert span["op"] == "queue.submit.ray"
125140
assert span["origin"] == "auto.queue.ray"
126-
assert (
127-
span["description"]
128-
== "tests.integrations.ray.test_ray.test_tracing_in_ray_tasks.<locals>.example_task"
129-
)
141+
assert span["description"] == f"tests.integrations.ray.test_ray.{task.__name__}"
130142
assert span["parent_span_id"] == client_transaction["contexts"]["trace"]["span_id"]
131143
assert span["trace_id"] == client_transaction["contexts"]["trace"]["trace_id"]
132144

0 commit comments

Comments
 (0)