o
    h                     @   s   d dl Z 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mZmZmZmZ zd dlZW n eyC   edw d dlZd dlmZ erdd dlmZ d d	lmZmZ d d
lmZ dd Zdd Zdd ZG dd de	ZdS )    N)OP
SPANSTATUS)_check_minimum_versionDidNotEnableIntegration)TransactionSource)event_from_exceptionloggerpackage_versionqualname_from_functionreraisezRay not installed.)TYPE_CHECKING)Callable)AnyOptional)ExcInfoc                   C   s   t   rd S td d S )Nz[[Tracing] Sentry not initialized in ray cluster worker, performance data will be discarded.)
sentry_sdk
get_client	is_activer	   debug r   r   ]/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/ray.py_check_sentry_initialized   s
   r   c                     s(   t j t d fdd	} | t _d S )Nc                    sF   t rg R i S  fdd}d ur!|S |S )Nc                    sP   d dfdd
}r|}n	i |}|j   fdd}||_ |S )N)_tracingc              	      s   t   tj| pi tjt tjtj	d}t
|5}z |i |}|tj W n tyD   |tj t }t| t|  Y nw |W  d    S 1 sQw   Y  d S )N)opnameoriginsource)r   r   continue_tracer   QUEUE_TASK_RAYr   RayIntegrationr   r   TASKstart_transaction
set_statusr   OK	ExceptionINTERNAL_ERRORsysexc_info_capture_exceptionr   )r   f_argsf_kwargstransactionresultr(   )user_fr   r   new_func9   s(   $zH_patch_ray_remote.<locals>.new_remote.<locals>.wrapper.<locals>.new_funcc               	      s   t jtjttjdD}dd t   D }z | i |d|i}|	t
j W n tyF   |	t
j t }t| t|  Y nw |W  d   S 1 sSw   Y  dS )z,
                Ray Client
                )r   r   r   c                 S   s   i | ]\}}||qS r   r   ).0kvr   r   r   
<dictcomp>a   s    zz_patch_ray_remote.<locals>.new_remote.<locals>.wrapper.<locals>._remote_method_with_header_propagation.<locals>.<dictcomp>r   N)r   
start_spanr   QUEUE_SUBMIT_RAYr   r    r   get_current_scopeiter_trace_propagation_headersr#   r   r$   r%   r&   r'   r(   r)   r   )argskwargsspantracingr-   r(   old_remote_methodr.   r   r   &_remote_method_with_header_propagationW   s(   
$zf_patch_ray_remote.<locals>.new_remote.<locals>.wrapper.<locals>._remote_method_with_header_propagation)remote)r.   r/   rvr>   )r8   fr9   
old_remoter<   r   wrapper7   s   
z6_patch_ray_remote.<locals>.new_remote.<locals>.wrapper)inspectisclass)rA   r8   r9   rC   rB   )r8   rA   r9   r   
new_remote,   s   
=z%_patch_ray_remote.<locals>.new_remote)N)rayr?   	functoolswraps)rG   r   rF   r   _patch_ray_remote(   s   
LrK   c                 K   s6   t  }t| |jdtjdd\}}t j||d d S )NF)handledtype)client_options	mechanism)hint)r   r   r   optionsr    
identifiercapture_event)r(   r9   clienteventrP   r   r   r   r)   |   s   
r)   c                   @   s&   e Zd ZdZde Zedd ZdS )r    rH   zauto.queue.c                  C   s   t d} tt|  t  d S )NrH   )r
   r   r    rK   )versionr   r   r   
setup_once   s   

zRayIntegration.setup_onceN)__name__
__module____qualname__rR   r   staticmethodrW   r   r   r   r   r       s
    
r    ) rD   r'   r   sentry_sdk.constsr   r   sentry_sdk.integrationsr   r   r   sentry_sdk.tracingr   sentry_sdk.utilsr   r	   r
   r   r   rH   ImportErrorrI   typingr   collections.abcr   r   r   r   r   rK   r)   r    r   r   r   r   <module>   s,    
T