File tree Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Original file line number Diff line number Diff line change 7
7
from sentry_sdk .integrations import DidNotEnable , Integration
8
8
from sentry_sdk .integrations .logging import ignore_logger
9
9
from sentry_sdk .tracing import Transaction , TRANSACTION_SOURCE_TASK
10
- from sentry_sdk .utils import capture_internal_exceptions , event_from_exception
10
+ from sentry_sdk .utils import (
11
+ capture_internal_exceptions ,
12
+ event_from_exception ,
13
+ format_timestamp ,
14
+ )
11
15
12
16
try :
13
17
from rq .queue import Queue
@@ -129,6 +133,11 @@ def event_processor(event, hint):
129
133
"description" : job .description ,
130
134
}
131
135
136
+ if job .enqueued_at :
137
+ extra ["rq-job" ]["enqueued_at" ] = format_timestamp (job .enqueued_at )
138
+ if job .started_at :
139
+ extra ["rq-job" ]["started_at" ] = format_timestamp (job .started_at )
140
+
132
141
if "exc_info" in hint :
133
142
with capture_internal_exceptions ():
134
143
if issubclass (hint ["exc_info" ][0 ], JobTimeoutException ):
Original file line number Diff line number Diff line change @@ -58,13 +58,18 @@ def test_basic(sentry_init, capture_events):
58
58
assert exception ["stacktrace" ]["frames" ][- 1 ]["vars" ]["foo" ] == "42"
59
59
60
60
assert event ["transaction" ] == "tests.integrations.rq.test_rq.crashing_job"
61
- assert event ["extra" ]["rq-job" ] == {
62
- "args" : [],
63
- "description" : "tests.integrations.rq.test_rq.crashing_job(foo=42)" ,
64
- "func" : "tests.integrations.rq.test_rq.crashing_job" ,
65
- "job_id" : event ["extra" ]["rq-job" ]["job_id" ],
66
- "kwargs" : {"foo" : 42 },
67
- }
61
+
62
+ extra = event ["extra" ]["rq-job" ]
63
+ assert extra ["args" ] == []
64
+ assert extra ["kwargs" ] == {"foo" : 42 }
65
+ assert extra ["description" ] == "tests.integrations.rq.test_rq.crashing_job(foo=42)"
66
+ assert extra ["func" ] == "tests.integrations.rq.test_rq.crashing_job"
67
+ assert "job_id" in extra
68
+ assert "enqueued_at" in extra
69
+
70
+ # older versions don't persist started_at correctly
71
+ if tuple (map (int , rq .VERSION .split ("." ))) >= (0 , 9 ):
72
+ assert "started_at" in extra
68
73
69
74
70
75
def test_transport_shutdown (sentry_init , capture_events_forksafe ):
You can’t perform that action at this time.
0 commit comments