Skip to content

Commit 9a1fbb4

Browse files
committed
Fix transaction name setting and forked some tests to make them work in potel
1 parent 706300c commit 9a1fbb4

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

sentry_sdk/integrations/rq.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
from rq.job import Job
3434

35+
DEFAULT_TRANSACTION_NAME = "unknown RQ task"
36+
3537

3638
class RqIntegration(Integration):
3739
identifier = "rq"
@@ -55,22 +57,27 @@ def setup_once():
5557
def sentry_patched_perform_job(self, job, *args, **kwargs):
5658
# type: (Any, Job, *Queue, **Any) -> bool
5759
with sentry_sdk.new_scope() as scope:
60+
try:
61+
transaction_name = job.func_name or DEFAULT_TRANSACTION_NAME
62+
except AttributeError:
63+
transaction_name = DEFAULT_TRANSACTION_NAME
64+
65+
scope.set_transaction_name(
66+
transaction_name, source=TRANSACTION_SOURCE_TASK
67+
)
5868
scope.clear_breadcrumbs()
5969
scope.add_event_processor(_make_event_processor(weakref.ref(job)))
6070

6171
with sentry_sdk.continue_trace(
6272
job.meta.get("_sentry_trace_headers") or {}
6373
):
64-
with sentry_sdk.start_transaction(
74+
with sentry_sdk.start_span(
6575
op=OP.QUEUE_TASK_RQ,
66-
name="unknown RQ task",
76+
name=transaction_name,
6777
source=TRANSACTION_SOURCE_TASK,
6878
origin=RqIntegration.origin,
6979
custom_sampling_context={"rq_job": job},
70-
) as transaction:
71-
with capture_internal_exceptions():
72-
transaction.name = job.func_name
73-
80+
):
7481
rv = old_perform_job(self, job, *args, **kwargs)
7582

7683
if self.is_horse:

tests/integrations/rq/test_rq.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def do_trick(dog, trick):
4646
return "{}, can you {}? Good dog!".format(dog, trick)
4747

4848

49+
@pytest.mark.forked
4950
def test_basic(sentry_init, capture_events):
5051
sentry_init(integrations=[RqIntegration()])
5152
events = capture_events()
@@ -78,6 +79,7 @@ def test_basic(sentry_init, capture_events):
7879
assert "started_at" in extra
7980

8081

82+
@pytest.mark.forked
8183
def test_transport_shutdown(sentry_init, capture_events_forksafe):
8284
sentry_init(integrations=[RqIntegration()])
8385

@@ -96,6 +98,7 @@ def test_transport_shutdown(sentry_init, capture_events_forksafe):
9698
assert exception["type"] == "ZeroDivisionError"
9799

98100

101+
@pytest.mark.forked
99102
def test_transaction_with_error(
100103
sentry_init, capture_events, DictionaryContaining # noqa:N803
101104
):
@@ -131,6 +134,7 @@ def test_transaction_with_error(
131134
)
132135

133136

137+
@pytest.mark.forked
134138
def test_error_has_trace_context_if_tracing_disabled(
135139
sentry_init,
136140
capture_events,
@@ -149,6 +153,7 @@ def test_error_has_trace_context_if_tracing_disabled(
149153
assert error_event["contexts"]["trace"]
150154

151155

156+
@pytest.mark.forked
152157
def test_tracing_enabled(
153158
sentry_init,
154159
capture_events,
@@ -171,6 +176,7 @@ def test_tracing_enabled(
171176
assert envelope["contexts"]["trace"] == error_event["contexts"]["trace"]
172177

173178

179+
@pytest.mark.forked
174180
def test_tracing_disabled(
175181
sentry_init,
176182
capture_events,
@@ -251,6 +257,7 @@ def test_traces_sampler_gets_correct_values_in_sampling_context(
251257
)
252258

253259

260+
@pytest.mark.forked
254261
@pytest.mark.skipif(
255262
parse_version(rq.__version__) < (1, 5), reason="At least rq-1.5 required"
256263
)

0 commit comments

Comments
 (0)