o
    h                     @   s  d dl Z d dlZd dlmZ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 d dlmZmZmZmZmZmZ zd dlZd dlmZ d d	lmZ d d
lmZmZm Z m!Z! W n e"yg   edw d dl#m$Z$ e$rd dl#m%Z%m&Z&m'Z'm(Z( d dl)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 d dlm4Z4 eee fZ5G dd deZ6dd Z7dd Z8dd Z9dd Z:dd Z;dd  Z<d!d" Z=d#d$ Z>dS )%    N)OP
SPANSTATUS)_check_minimum_versionDidNotEnableIntegration)ignore_logger)should_send_default_pii)TransactionTransactionSource)capture_internal_exceptionsensure_integration_enabledevent_from_exceptionSENSITIVE_DATA_SUBSTITUTEparse_versionreraise)VERSION)ArqRedis)JobExecutionFailedRetryRetryJobWorkerzArq is not installed)TYPE_CHECKING)AnyDictOptionalUnion)EventProcessorEventExcInfoHint)CronJob)Job)WorkerCoroutine)Functionc                   @   s&   e Zd ZdZde Zedd ZdS )ArqIntegrationarqzauto.queue.c               	   C   sj   zt ttrtt} ntjd d } W n ttfy    d } Y nw tt|  t	  t
  t  td d S )N   z
arq.worker)
isinstanceARQ_VERSIONstrr   version	TypeError
ValueErrorr   r$   patch_enqueue_jobpatch_run_jobpatch_create_workerr   )r*    r0   ]/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/arq.py
setup_once-   s   


zArqIntegration.setup_onceN)__name__
__module____qualname__
identifieroriginstaticmethodr2   r0   r0   r0   r1   r$   )   s
    
r$   c                     s(   t j  j}  fdd}| |_|t _d S )Nc                    s   t  t}|d u r | |g|R i |I d H S t jtj|tjd  | |g|R i |I d H W  d    S 1 s?w   Y  d S )N)opnamer7   )
sentry_sdk
get_clientget_integrationr$   
start_spanr   QUEUE_SUBMIT_ARQr7   )selffunctionargskwargsintegrationold_enqueue_jobr0   r1   _sentry_enqueue_jobH   s   
$z.patch_enqueue_job.<locals>._sentry_enqueue_job)r   enqueue_job__kwdefaults__)original_kwdefaultsrG   r0   rE   r1   r-   C   s
   
r-   c                     s   t j  fdd} | t _d S )Nc              	      s   t  t}|d u r | ||I d H S t  A}d|_|  tddtj	t
jtjd}t |  | ||I d H W  d    W  d    S 1 sMw   Y  W d    d S 1 s]w   Y  d S )Nr%   zunknown arq taskok)r:   statusr9   sourcer7   )r;   r<   r=   r$   isolation_scope_nameclear_breadcrumbsr	   r   QUEUE_TASK_ARQr
   TASKr7   start_transaction)r@   job_idscorerD   scopetransactionold_run_jobr0   r1   _sentry_run_job[   s(   
"z&patch_run_job.<locals>._sentry_run_job)r   run_job)rZ   r0   rX   r1   r.   W   s   
r.   c                 C   sp   t  }|jd ur| d tv r|jtj d S |jtj t| t 	 j
tjddd\}}t j||d d S )Nr   F)typehandled)client_options	mechanism)hint)r;   get_current_scoperW   ARQ_CONTROL_FLOW_EXCEPTIONS
set_statusr   ABORTEDINTERNAL_ERRORr   r<   optionsr$   r6   capture_event)exc_inforV   eventr`   r0   r0   r1   _capture_exceptions   s   


rj   c                    s    fdd}|S )Nc                    s   t  O t }|jd urd |j_d | d< | di }d |d< d dk|d< | d	i }d t r; ntt rAntd d
|d< W d    | S 1 sUw   Y  | S )Njob_namerW   tagsrT   arq_task_idjob_try   arq_task_retryextra)taskrB   rC   retryzarq-job)r   r;   ra   rW   r:   
setdefaultr   r   )ri   r`   rV   rl   rq   rB   ctxrC   r0   r1   event_processor   s$   

z._make_event_processor.<locals>.event_processorr0   )rv   rB   rC   rw   r0   ru   r1   _make_event_processor   s   rx   c                    s    fdd}|S )Nc                    s   t  t}|d u r | g|R i |I d H S t  ti | dig|R i | z | g|R i |I d H }W |S  tyW   t	 }t
| t|  Y |S w )Nrk   )r;   r<   r=   r$   get_isolation_scopeadd_event_processorrx   	Exceptionsysrh   rj   r   )rv   rB   rC   rD   resultrh   	coroutiner:   r0   r1   _sentry_coroutine   s     
z*_wrap_coroutine.<locals>._sentry_coroutiner0   )r:   r   r   r0   r~   r1   _wrap_coroutine   s   r   c                     s*   t jj tt  fdd} | t j_d S )Nc                     s   | d }t |tr+d|v rdd |dg D |d< d|v r+dd |dg D |d< t|dr9dd |jD |_t|drIdd |jpEg D |_d|v rZd	d |dg D |d< d|v rkd
d |dg D |d<  | i |S )Nr   	functionsc                 S      g | ]}t |qS r0   _get_arq_function.0funcr0   r0   r1   
<listcomp>       zFpatch_create_worker.<locals>._sentry_create_worker.<locals>.<listcomp>	cron_jobsc                 S   r   r0   _get_arq_cron_jobr   cron_jobr0   r0   r1   r      r   c                 S   r   r0   r   r   r0   r0   r1   r          c                 S   r   r0   r   r   r0   r0   r1   r      r   c                 S   r   r0   r   r   r0   r0   r1   r      r   c                 S   r   r0   r   r   r0   r0   r1   r      r   )r'   dictgethasattrr   r   )rB   rC   settings_clsold_create_workerr0   r1   _sentry_create_worker   s6   










z2patch_create_worker.<locals>._sentry_create_worker)r%   workercreate_workerr   r$   )r   r0   r   r1   r/      s   %r/   c                 C   s    t j| }t|j|j|_|S N)r%   r   r   r   r:   r   )r   arq_funcr0   r0   r1   r      s   r   c                 C   s   t | j| j| _| S r   )r   r:   r   )r   r0   r0   r1   r      s   r   )?r|   r;   sentry_sdk.constsr   r   sentry_sdk.integrationsr   r   r   sentry_sdk.integrations.loggingr   sentry_sdk.scoper   sentry_sdk.tracingr	   r
   sentry_sdk.utilsr   r   r   r   r   r   
arq.workerr%   arq.versionr   r(   arq.connectionsr   r   r   r   r   ImportErrortypingr   r   r   r   r   sentry_sdk._typesr   r   r   r   arq.cronr    arq.jobsr!   
arq.typingr"   r#   rb   r$   r-   r.   rj   rx   r   r/   r   r   r0   r0   r0   r1   <module>   sD     	
-