o
    h                     @   s4  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mZmZmZmZ 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 W n eyc   edw d dl m!Z! e!rd 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 de	Z)dd Z*dd Z+dS )    N)OP)continue_trace)_check_minimum_versionDidNotEnableIntegration)ignore_logger)TransactionSource)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionformat_timestampparse_version)Queue)JobTimeoutException)VERSION)Worker)	JobStatuszRQ not installed)TYPE_CHECKING)AnyCallable)EventEventProcessor)ExcInfo)Jobc                   @   s&   e Zd ZdZde Zedd ZdS )RqIntegrationrqzauto.queue.c                     sz   t t} tt|  tjttfdd}|t_tjfdd}|t_tj	 tt  fdd}|t_	t
d d S )Nc              	      s   t  d}|  |tt| t|j	dpi t
jdtjtjd}t  |j|_W d    n1 s7w   Y  t j|d|id  | |g|R i |}W d    n1 s\w   Y  W d    n1 skw   Y  | jryt    |S )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)selfjobargskwargsscopetransactionrv)old_perform_job \/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/rq.pysentry_patched_perform_job1   s0   

z<RqIntegration.setup_once.<locals>.sentry_patched_perform_jobc                    sT   t |do|jo|jdk}|jtjkp|j}|r|st|  | |g|R i |S )Nretries_leftr   )hasattrr>   _statusr   FAILED	is_failed_capture_exception)r3   r4   exc_infor6   retryfailed)old_handle_exceptionr;   r<   sentry_patched_handle_exceptionU   s   
zARqIntegration.setup_once.<locals>.sentry_patched_handle_exceptionc                    s6   t  }|jd urt| |jd<  | |fi |S )Nr   )r#   get_current_scopespandictiter_trace_propagation_headersr*   )r3   r4   r6   r7   )old_enqueue_jobr;   r<   sentry_patched_enqueue_jobf   s   

z<RqIntegration.setup_once.<locals>.sentry_patched_enqueue_jobz	rq.worker)r   
RQ_VERSIONr   r   r   perform_jobr
   handle_exceptionr   enqueue_jobr   )versionr=   rH   rN   r;   )rM   rG   r:   r<   
setup_once)   s   

zRqIntegration.setup_onceN)__name__
__module____qualname__
identifierr    staticmethodrT   r;   r;   r;   r<   r   %   s
    
r   c                    s    fdd}|S )Nc                    s     }|d urEt  3 | di }|j|j|j|j|jd}|jr(t|j|d< |j	r2t|j	|d< ||d< W d    n1 s@w   Y  d|v rvt  " t
|d d trfdd	|jg| d
< W d    | S W d    | S 1 sqw   Y  | S )Nextra)job_idfuncr5   r6   descriptionenqueued_at
started_atzrq-jobrD   r   r   r   fingerprint)r	   
setdefaultidr.   r5   r6   r]   r^   r   r_   
issubclassr   )eventhintr4   rZ   r!   weak_jobr;   r<   event_processorx   s6   


z._make_event_processor.<locals>.event_processorr;   )rg   rh   r;   rf   r<   r'   v   s   r'   c                 K   s4   t  }t| |jdddd\}}t j||d d S )Nr   F)typehandled)client_options	mechanism)re   )r#   r1   r   optionscapture_event)rD   r6   clientrd   re   r;   r;   r<   rC      s   
rC   ),r(   r#   sentry_sdk.constsr   sentry_sdk.apir   sentry_sdk.integrationsr   r   r   sentry_sdk.integrations.loggingr   sentry_sdk.tracingr   sentry_sdk.utilsr	   r
   r   r   r   rq.queuer   rq.timeoutsr   
rq.versionr   rO   	rq.workerr   rq.jobr   ImportErrortypingr   r   r   sentry_sdk._typesr   r   r   r   r   r'   rC   r;   r;   r;   r<   <module>   s4    Q!