
    \j&                        d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZmZmZmZmZ 	 d d	lmZ d d
lmZ d dlmZ d dlmZ d dl m!Z! 	 d dlm#Z#  e$e#d      sdZ#d dl%m&Z& e&rd dl%m'Z'm(Z( d dl)m*Z*m+Z+ d dlm,Z, d dl m-Z-  G d de	      Z.ddZ/ddZ0y# e"$ r	  ed      w xY w# e"$ r dZ#Y Rw xY w)    N)OP)continue_trace)_check_minimum_versionDidNotEnableIntegration)ignore_logger)should_send_default_pii)TransactionSource)SENSITIVE_DATA_SUBSTITUTEcapture_internal_exceptionsensure_integration_enabledevent_from_exceptionformat_timestampparse_version)Queue)JobTimeoutException)VERSION)Worker)	JobStatuszRQ not installed)
BaseWorkerperform_job)TYPE_CHECKING)AnyCallable)EventEventProcessor)ExcInfo)Jobc                   ,    e Zd ZdZde Zedd       Zy)RqIntegrationrqzauto.queue.Nc                     t        t              } t        t        |        t        t        nt
        }|j                  t        t              dddddddddt        f
fd	       }||_        |j                  	 	 	 	 	 	 	 	 	 	 dfd
}||_	        t        j                  t        t              	 	 	 	 	 	 	 	 dfd       }|t        _        t        d       y )Nselfr   jobr   argsr   kwargsreturnc                    t        j                         5 }|j                          |j                  t	        t        j                  |                   t        |j                  j                  d      xs i t        j                  dt        j                  t        j                        }t!               5  |j"                  |_        d d d        t        j&                  |d|i      5   | |g|i |}d d d        d d d        | j(                  r"t        j*                         j-                          S # 1 sw Y   pxY w# 1 sw Y   MxY w# 1 sw Y   QxY w)N_sentry_trace_headerszunknown RQ task)opnamesourceoriginrq_job)custom_sampling_context)
sentry_sdk	new_scopeclear_breadcrumbsadd_event_processor_make_event_processorweakrefrefr   metagetr   QUEUE_TASK_RQr
   TASKr    r-   r   	func_namer+   start_transactionis_horse
get_clientflush)r#   r$   r%   r&   scopetransactionrvold_perform_jobs          D/root/env/lib/python3.12/site-packages/sentry_sdk/integrations/rq.pysentry_patched_perform_jobz<RqIntegration.setup_once.<locals>.sentry_patched_perform_job@   s,    %%' E5'')))*?C@P*QR,HHLL!89?R''*,11(// 12 5'*}}K$5  11-5sO E )sDTDVDB	EE* }} %%'--/I5 5E EE Es<   BE5D6!E(E6E6D?	;EE	EEc                     t        |d      xr |j                  xr |j                  dkD  }|j                  t        j                  k(  xs |j
                  }|r|st        |        | |g|i |S )Nretries_leftr   )hasattrrG   _statusr   FAILED	is_failed_capture_exception)r#   r$   exc_infor&   retryfailedold_handle_exceptions         rD   sentry_patched_handle_exceptionzARqIntegration.setup_once.<locals>.sentry_patched_handle_exceptione   sx     ^, )$$)$$q( 
 [[I$4$44EFe"8,'cGHGGG    c                     t        j                         }|j                  &t        |j	                               |j
                  d<    | |fi |S )Nr)   )r0   get_current_scopespandictiter_trace_propagation_headersr7   )r#   r$   r&   r@   old_enqueue_jobs       rD   sentry_patched_enqueue_jobz<RqIntegration.setup_once.<locals>.sentry_patched_enqueue_jobw   sQ     002Ezz%4888:501 #4777rR   z	rq.worker)
r#   r   r$   r   rM   r   r&   r   r'   r   )r#   r   r$   r   r&   r   r'   r   )r   
RQ_VERSIONr   r    r   r   r   r   boolhandle_exceptionr   enqueue_jobr   )version
worker_clsrE   rQ   rY   rX   rP   rC   s        @@@rD   
setup_oncezRqIntegration.setup_once3   s   
+}g6 $.#9Zv
$00	#M?	C		#	,3	?D		 
D	@ "<
)::	H	H!&	H38	HDI	H	H 'F
#++	#M?	C		8		8 %		816		8		8 
D		8 7k"rR   )r'   N)__name__
__module____qualname__
identifierr-   staticmethodr`    rR   rD   r    r    /   s'    J:,'FQ# Q#rR   r    c                      d fd}|S )Nc                 f           }|t               5  | j                  di       }|j                  |j                  t	               r|j
                  nt        t	               r|j                  nt        |j                  d}|j                  rt        |j                        |d<   |j                  rt        |j                        |d<   ||d<   d d d        d|v r=t               5  t        |d   d   t              rdd	|j                  g| d
<   d d d        | S | S # 1 sw Y   LxY w# 1 sw Y   | S xY w)Nextra)job_idfuncr%   r&   descriptionenqueued_at
started_atzrq-jobrM   r   r!   r   fingerprint)r   
setdefaultidr;   r	   r%   r   r&   rl   rm   r   rn   
issubclassr   )eventhintr$   ri   r.   weak_jobs        rD   event_processorz._make_event_processor.<locals>.event_processor   s   j?,. )(("5!ffMM 34 6 34 

6#&??  ??,<S__,MF=)>>+;CNN+KF<("(h/)2 ,. Xd:.q13FG,02G+WE-(X u=) )4X s   B:D%)D&D#&D0)rs   r   rt   zdict[str, Any]r'   r   rf   )ru   rv   s   ` rD   r4   r4      s    !F rR   c                     t        j                         }t        | |j                  ddd      \  }}t        j                  ||       y )Nr!   F)typehandled)client_options	mechanism)rt   )r0   r>   r   optionscapture_event)rM   r&   clientrs   rt   s        rD   rL   rL      sB    ""$F&~~E2KE4 U.rR   )ru   zCallable[[], Job]r'   r   )rM   r   r&   r   r'   N)1r5   r0   sentry_sdk.constsr   sentry_sdk.apir   sentry_sdk.integrationsr   r   r   sentry_sdk.integrations.loggingr   sentry_sdk.scoper	   sentry_sdk.tracingr
   sentry_sdk.utilsr   r   r   r   r   r   rq.queuer   rq.timeoutsr   
rq.versionr   rZ   	rq.workerr   rq.jobr   ImportErrorr   rH   typingr   r   r   sentry_sdk._typesr   r   r   r   r    r4   rL   rf   rR   rD   <module>r      s        ) U U 9 4 0 +/0  $:}-
 !$7(V#K V#r$N	/m  +
)
**+  Js   B* !B; *B8;CC