
    `i                     &   d dl Z 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mZ n# e$ r  e	d          w xY w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dZddZddZddZ  G d de
          Z!dS )    N)OP
SPANSTATUS)_check_minimum_versionDidNotEnableIntegration)TransactionSource)event_from_exceptionloggerpackage_versionqualname_from_functionreraise)remotezRay not installed.)TYPE_CHECKING)Callable)AnyOptional)ExcInforeturnc                  |    t          j                                                    rd S t          j        d           d S )Nz[[Tracing] Sentry not initialized in ray cluster worker, performance data will be discarded.)
sentry_sdk
get_client	is_activer
   debug     o/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/sentry_sdk/integrations/ray.py_check_sentry_initializedr      sE    ((** 
Le    r   funcCallable[..., Any]c                    t          j        |           }t          |j                                                  }t          j        dt           j        j        d           }|r5|d         j        t           j        j        u r|	                    d|           n|
                    |           |                    |          | _        d S )N_sentry_tracing)kinddefault)
parameters)inspect	signaturelistr%   values	ParameterKEYWORD_ONLYr"   VAR_KEYWORDinsertappendreplace__signature__)r   r'   paramssentry_tracing_params       r   #_insert_sentry_tracing_in_signaturer3   (   s     !$''I)&--//00F",+    ,&*/W%6%BBBb.////*+++"**f*==Dr   c                      t           t          j                  	 d		 	 	 	 	 	 	 d
fd            } | t          _         d S )NfOptional[Callable[..., Any]]argsr   kwargsr   r   c                 z     t          j                   r  gR i S d fd}  |           S |S )Nuser_fr   r   r   c                 <    t          j                   r  i            S t          j                   d d	 	 	 	 	 	 	 d fd            }t	          |           r |          }n  i |          }|j        	 	 	 	 	 	 d fd}||_        |S )N)r!   f_argsr   r!   Optional[dict[str, Any]]f_kwargsr   c                    t                       t          j        | pi t          j        t                    t          j        t          j	                  }t          j
        |          5 }	  |i |}|                    t          j                   nZ# t          $ rM |                    t          j                   t!          j                    }t%          |           t'          |  Y nw xY w|cd d d            S # 1 swxY w Y   d S )N)opnameoriginsource)r   r   continue_tracer   QUEUE_TASK_RAYr   RayIntegrationrB   r   TASKstart_transaction
set_statusr   OK	ExceptionINTERNAL_ERRORsysexc_info_capture_exceptionr   )r!   r<   r>   transactionresultrN   r:   s         r   new_funczH_patch_ray_remote.<locals>.new_remote.<locals>.wrapper.<locals>.new_funcR   sT    *+++(7#)r(/77)0,1    1+>> 
"++!'!<8!<!<#..z}====$ + + +#..z/HIII#&<>>*8444****	+ "
" 
" 
" 
" 
" 
" 
" 
" 
" 
" 
" 
" 
" 
" 
" 
" 
" 
"s7   *C<,'BC<AC+(C<*C++C<<D D r7   r8   c                     t          j        t          j        t	                    t
          j                  5 }d t          j                                                    D             }	  | i |d|i}|	                    t          j                   nZ# t          $ rM |	                    t          j                   t          j                    }t!          |           t#          |  Y nw xY w|cddd           S # 1 swxY w Y   dS )z,
                Ray Client
                )r@   rA   rB   c                     i | ]\  }}||	S r   r   ).0kvs      r   
<dictcomp>zz_patch_ray_remote.<locals>.new_remote.<locals>.wrapper.<locals>._remote_method_with_header_propagation.<locals>.<dictcomp>   s.        Aq 1  r   r!   N)r   
start_spanr   QUEUE_SUBMIT_RAYr   rF   rB   get_current_scopeiter_trace_propagation_headersrI   r   rJ   rK   rL   rM   rN   rO   r   )r7   r8   spantracingrQ   rN   old_remote_methodr:   s         r   &_remote_method_with_header_propagationzf_patch_ray_remote.<locals>.new_remote.<locals>.wrapper.<locals>._remote_method_with_header_propagationv   sw     **/77)0   "  $.$@$B$B$a$a$c$c  G	+!2!2!"%+" "=D" " " 
6666$ + + +
(ABBB#&<>>*8444****	+ ")" " " " " " " " " " " " " " " " " "s6   0C?++BC?AC.+C?-C..C??DD)r<   r   r!   r=   r>   r   r   r   )r7   r   r8   r   r   r   )r&   isclass	functoolswrapsr3   r   )	r:   rR   rvr`   r_   r7   r5   r8   
old_remotes	   `   @r   wrapperz6_patch_ray_remote.<locals>.new_remote.<locals>.wrapperJ   s2   v&& ;
 3zz426226:::_V$$ ?C" ""!;" "" 	" " " " " %$"6 0999 ;Z))0ZZ000:: "	""(-"" " " " " " "8 ?BIIr   )r:   r   r   r   )r&   ra   )r5   r7   r8   rf   re   s   ``` r   
new_remotez%_patch_ray_remote.<locals>.new_remote?   s     ?1 	2
 :a1$111&111J	 J	 J	 J	 J	 J	 J	 J	 J	X =71::Nr   )N)r5   r6   r7   r   r8   r   r   r   )r   rb   rc   ray)rg   re   s    @r   _patch_ray_remoteri   <   sv    J_Z  ,0Y)Y9>YJOY	Y Y Y Y Y ! Yv CJJJr   rN   r   r8   r   c                     t          j                    }t          | |j        dt          j        d          \  }}t          j        ||           d S )NF)handledtype)client_options	mechanism)hint)r   r   r	   optionsrF   
identifiercapture_event)rN   r8   clienteventro   s        r   rO   rO      sa    "$$F&~"-
 
  KE4 U......r   c                   4    e Zd ZdZde Zedd            ZdS )rF   rh   zauto.queue.r   Nc                  j    t          d          } t          t          |            t                       d S )Nrh   )r   r   rF   ri   )versions    r   
setup_oncezRayIntegration.setup_once   s1    !%((~w777r   r   N)__name__
__module____qualname__rq   rB   staticmethodrx   r   r   r   rF   rF      sD        J':''F   \  r   rF   ry   )r   r   r   N)rN   r   r8   r   r   N)"r&   rb   rM   r   sentry_sdk.constsr   r   sentry_sdk.integrationsr   r   r   sentry_sdk.tracingr   sentry_sdk.utilsr	   r
   r   r   r   rh   r   ImportErrortypingr   collections.abcr   r   r   r   r   r3   ri   rO   rF   r   r   r   <module>r      s        



     , , , , , , , , U U U U U U U U U U 0 0 0 0 0 0             -JJJ - - -
,+
,
,,- !           )(((((($$$$$$$$((((((   > > > >(_ _ _ _D/ / / /	 	 	 	 	[ 	 	 	 	 	s   
A A