o
    S۷i                     @   sn  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 zd dlm Z  e!e dsrdZ W n ey~   dZ Y n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)
BaseWorkerperform_job)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d urtnt}|jttdddddddddtf
fd	d
}||_|j											dfdd}||_	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 P/home/ubuntu/vllm_env/lib/python3.10/site-packages/sentry_sdk/integrations/rq.pysentry_patched_perform_job>   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   )hasattrrB   _statusr   FAILED	is_failed_capture_exception)r   r    rA   r"   retryfailed)old_handle_exceptionr>   r?   sentry_patched_handle_exceptionc   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_headersr1   )r   r    r"   r:   )old_enqueue_jobr>   r?   sentry_patched_enqueue_jobu   s   

z<RqIntegration.setup_once.<locals>.sentry_patched_enqueue_jobz	rq.worker)
r   r   r    r   rA   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_clsr@   rK   rQ   r>   )rP   rJ   r=   r?   
setup_once1   sV   
 zRqIntegration.setup_once)r   N)__name__
__module____qualname__
identifierr'   staticmethodrX   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-jobrA   r   r   r   fingerprint)r	   
setdefaultidr5   r!   r"   rf   rg   r   rh   
issubclassr   )r`   ra   r    rc   r(   r^   r>   r?   event_processor   s6   


z._make_event_processor.<locals>.event_processor)r`   r   ra   rb   r   r   r>   )r^   rn   r>   rm   r?   r.      s   r.   rA   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)ra   )r*   r8   r   optionscapture_event)rA   r"   clientr`   ra   r>   r>   r?   rG      s   
rG   )r^   r_   r   r   )rA   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   rR   	rq.workerr   rq.jobr   ImportErrorr   rC   typingr   r   r   sentry_sdk._typesr   r   r   r   r   r.   rG   r>   r>   r>   r?   <module>   sD    

Y