o
    i                     @   s8  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dZ*d"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dZdS )RqIntegrationrqzauto.queue.returnNc                     s   t t} tt|  tjttdddddddddtf
fd	d
}|t_tj										dfdd}|t_t	j
 tt 								d fdd}|t	_
td d S )Nselfr   jobr   argsr   kwargsr   c              	      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)r   r   r   r    scopetransactionrv)old_perform_job W/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/sentry_sdk/integrations/rq.pysentry_patched_perform_job0   s0   

z<RqIntegration.setup_once.<locals>.sentry_patched_perform_jobr   exc_infoc                    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)r   r   r?   r    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/   )r   r   r    r8   )old_enqueue_jobr<   r=   sentry_patched_enqueue_jobg   s   

z<RqIntegration.setup_once.<locals>.sentry_patched_enqueue_jobz	rq.worker)
r   r   r   r   r?   r   r    r   r   r   )r   r   r   r   r    r   r   r   )r   
RQ_VERSIONr   r   r   perform_jobr
   boolhandle_exceptionr   enqueue_jobr   )versionr>   rI   rO   r<   )rN   rH   r;   r=   
setup_once)   sT   
 zRqIntegration.setup_once)r   N)__name__
__module____qualname__
identifierr%   staticmethodrV   r<   r<   r<   r=   r   %   s
    
r   weak_jobCallable[[], Job]r   r   c                    s   d fdd}|S )	Neventr   hintdict[str, Any]r   c                    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funcr   r    descriptionenqueued_at
started_atzrq-jobr?   r   r   r   fingerprint)r	   
setdefaultidr3   r   r    rd   re   r   rf   
issubclassr   )r^   r_   r   ra   r&   r\   r<   r=   event_processory   s6   


z._make_event_processor.<locals>.event_processor)r^   r   r_   r`   r   r   r<   )r\   rl   r<   rk   r=   r,   x   s   r,   r?   r   r    r   c                 K   s4   t  }t| |jdddd\}}t j||d d S )Nr   F)typehandled)client_options	mechanism)r_   )r(   r6   r   optionscapture_event)r?   r    clientr^   r_   r<   r<   r=   rE      s   
rE   )r\   r]   r   r   )r?   r   r    r   r   N),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   rP   	rq.workerr   rq.jobr   ImportErrortypingr   r   r   sentry_sdk._typesr   r   r   r   r   r,   rE   r<   r<   r<   r=   <module>   s4    
S