
    lh                         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 	 d dlZd dlZd dlmZ erd dlmZ d d	lmZmZ d d
lmZ d Zd Zd Z G d de	      Zy# e$ r	  ed      w xY w)    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                  t    t        j                         j                         ry t        j                  d       y )Nz[[Tracing] Sentry not initialized in ray cluster worker, performance data will be discarded.)
sentry_sdk
get_client	is_activer
   debug     m/var/www/pru.catia.catastroantioquia-mas.com/tasa/lib/python3.12/site-packages/sentry_sdk/integrations/ray.py_check_sentry_initializedr      s)    ((*
LLer   c                  x    t         j                  t        j                        dfd	       } | t         _        y )Nc                 t     t        j                         r  gi S  fd}  |       S |S )Nc                      d d fd
}r	 |      }n  i |      }|j                    fd}||_         |S )N)_tracingc                    t                t        j                  | xs i t        j                  t              t        j                  t        j                        }t        j                  |      5 }	  |i |}|j                  t        j                         cd d d        S # t        $ rI |j                  t        j                         t!        j"                         }t%        |       t'        |  Y \w xY w# 1 sw Y   y xY w)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_fs         r   new_funczH_patch_ray_remote.<locals>.new_remote.<locals>.wrapper.<locals>.new_func9   s    )+(77N((/7)00,11  11+> 
"++!'!<8!<#..z}}= "
" 
" % +#..z/H/HI#&<<>*84*	+	
" 
"s1   2C;4'B&C;&AC85C;7C88C;;Dc                  &   t        j                  t        j                  t	        	      t
        j                        5 }t        j                         j                         D ci c]  \  }}||
 }}}	  | i |d|i}|j                  t        j                         cddd       S c c}}w # t        $ rI |j                  t        j                         t        j                         }t!        |       t#        |  Y bw xY w# 1 sw Y   yxY w)z,
                Ray Client
                )r!   r"   r#   r   N)r   
start_spanr   QUEUE_SUBMIT_RAYr   r'   r#   get_current_scopeiter_trace_propagation_headersr*   r   r+   r,   r-   r.   r/   r0   r   )
argskwargsspankvtracingr4   r/   old_remote_methodr5   s
           r   &_remote_method_with_header_propagationzf_patch_ray_remote.<locals>.new_remote.<locals>.wrapper.<locals>._remote_method_with_header_propagationW   s    
  ****/7)00 "  %/$@$@$B$a$a$c Aq 1G +!2D!UF!UW!U
6 "%" "
 % +
(A(AB#&<<>*84*	+" "sB   &D%B,2D6+B2!D,D2ADDDDD)remote)	r5   r6   rvrC   rB   r<   fr=   
old_remotes	   `   @r   wrapperz6_patch_ray_remote.<locals>.new_remote.<locals>.wrapper7   sM    +/ "0 )0Z00: "		"2 ?BIIr   )inspectisclass)rF   r<   r=   rH   rG   s   ``` r   
new_remotez%_patch_ray_remote.<locals>.new_remote,   sD     ??1
 a1$1&11;	z =1:Nr   )N)rayrD   	functoolswraps)rK   rG   s    @r   _patch_ray_remoterO   (   s3    J__Z J !JX CJr   c                     t        j                         }t        | |j                  dt        j
                  d      \  }}t        j                  ||       y )NF)handledtype)client_options	mechanism)hint)r   r   r	   optionsr'   
identifiercapture_event)r/   r=   clienteventrU   s        r   r0   r0   |   sK    ""$F&~~"--
KE4 U.r   c                   *    e Zd ZdZde Zed        Zy)r'   rL   zauto.queue.c                  N    t        d      } t        t        |        t                y )NrL   )r   r   r'   rO   )versions    r   
setup_oncezRayIntegration.setup_once   s     "%(~w7r   N)__name__
__module____qualname__rW   r#   staticmethodr^   r   r   r   r'   r'      s%    J:,'F r   r'   ) rI   r.   r   sentry_sdk.constsr   r   sentry_sdk.integrationsr   r   r   sentry_sdk.tracingr   sentry_sdk.utilsr	   r
   r   r   r   rL   ImportErrorrM   typingr   collections.abcr   r   r   r   r   rO   r0   r'   r   r   r   <module>rj      s{     
  , U U 0 -   ($(Qh/
[ 
s  -
+
,,-s   A- -A;