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 77from sentry_sdk .integrations import DidNotEnable , Integration
88from sentry_sdk .integrations .logging import ignore_logger
99from 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+ )
1115
1216try :
1317 from rq .queue import Queue
@@ -129,6 +133,11 @@ def event_processor(event, hint):
129133 "description" : job .description ,
130134 }
131135
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+
132141 if "exc_info" in hint :
133142 with capture_internal_exceptions ():
134143 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):
5858 assert exception ["stacktrace" ]["frames" ][- 1 ]["vars" ]["foo" ] == "42"
5959
6060 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
6873
6974
7075def test_transport_shutdown (sentry_init , capture_events_forksafe ):
You can’t perform that action at this time.
0 commit comments