3535DEFAULT_TRANSACTION_NAME = "unknown RQ task"
3636
3737
38+ JOB_PROPERTY_TO_ATTRIBUTE = {
39+ "id" : "messaging.message.id" ,
40+ }
41+
42+ QUEUE_PROPERTY_TO_ATTRIBUTE = {
43+ "name" : "messaging.destination.name" ,
44+ }
45+
46+
3847class RqIntegration (Integration ):
3948 identifier = "rq"
4049 origin = f"auto.queue.{ identifier } "
@@ -54,8 +63,8 @@ def setup_once():
5463 old_perform_job = Worker .perform_job
5564
5665 @ensure_integration_enabled (RqIntegration , old_perform_job )
57- def sentry_patched_perform_job (self , job , * args , ** kwargs ):
58- # type: (Any, Job, * Queue, **Any) -> bool
66+ def sentry_patched_perform_job (self , job , queue , * args , ** kwargs ):
67+ # type: (Any, Job, Queue, *Any , **Any) -> bool
5968 with sentry_sdk .new_scope () as scope :
6069 try :
6170 transaction_name = job .func_name or DEFAULT_TRANSACTION_NAME
@@ -76,9 +85,9 @@ def sentry_patched_perform_job(self, job, *args, **kwargs):
7685 name = transaction_name ,
7786 source = TRANSACTION_SOURCE_TASK ,
7887 origin = RqIntegration .origin ,
79- attributes = _prepopulate_attributes (job ),
88+ attributes = _prepopulate_attributes (job , queue ),
8089 ):
81- rv = old_perform_job (self , job , * args , ** kwargs )
90+ rv = old_perform_job (self , job , queue , * args , ** kwargs )
8291
8392 if self .is_horse :
8493 # We're inside of a forked process and RQ is
@@ -169,9 +178,18 @@ def _capture_exception(exc_info, **kwargs):
169178 sentry_sdk .capture_event (event , hint = hint )
170179
171180
172- JOB_PROPERTY_TO_ATTRIBUTE = {}
181+ def _prepopulate_attributes (job , queue ):
182+ # type: (Job, Queue) -> dict[str, Any]
183+ attributes = {
184+ "messaging.system" : "rq" ,
185+ }
186+
187+ for prop , attr in JOB_PROPERTY_TO_ATTRIBUTE .items ():
188+ if getattr (job , prop , None ) is not None :
189+ attributes [attr ] = getattr (job , prop )
173190
191+ for prop , attr in QUEUE_PROPERTY_TO_ATTRIBUTE .items ():
192+ if getattr (queue , prop , None ) is not None :
193+ attributes [attr ] = getattr (queue , prop )
174194
175- def _prepopulate_attributes (job ):
176- attributes = {}
177195 return attributes
0 commit comments