
    tnir                        d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZ erd dlmZmZ d d	lmZmZ 	 d dlZd d
lmZmZ d dlmZmZ n# e$ r  ed          w xY w G d dej        j                  ZdS )    N)OP)DidNotEnable)SPAN_ORIGIN)TransactionTransactionSource)event_from_exception)TYPE_CHECKING)	AwaitableCallable)AnyOptional)HandlerCallDetailsRpcMethodHandler)
AbortErrorServicerContextzgrpcio is not installedc                   V     e Zd Z	 d	 	 	 	 	 d fdZ	 	 	 	 	 	 	 	 ddZdddefdZ xZS )ServerInterceptorNself	find_name'Callable[[ServicerContext], str] | Nonereturnc                 d    |p| j         | _        t                                                       d S N)
_find_name_find_method_namesuper__init__)r   r   	__class__s     d/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/sentry_sdk/integrations/grpc/aio/server.pyr   zServerInterceptor.__init__   s0     "+!=do    continuation;Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler]]handler_call_detailsr   %Optional[Awaitable[RpcMethodHandler]]c                 z   K   | _          ||           d {V d S j        sj        st          j        }d fd}nbj        sj        rt          j        }dfd}nAj        rj        st          j        }dfd}n j        rj        rt          j        }dfd	} ||j        j	        
          S )Nrequestr   contextr   r   c                 *  K                        |          }|s | |           d {V S t          j        t          |                                          t
          j        |t          j        t                    }t          j
        |          5  	                     | |           d {V 	 cd d d            S # t          $ r  t          $ r3}t          |ddd          \  }}t          j        ||            d }~ww xY w# 1 swxY w Y   d S )N)opnamesourceorigin)transactiongrpcF)typehandled)	mechanism)hint)r   
sentry_sdkcontinue_tracedictinvocation_metadatar   GRPC_SERVERr   CUSTOMr   start_transactionunary_unaryr   	Exceptionr   capture_event)	r&   r'   r*   r-   exceventr2   handlerr   s	          r   wrappedz4ServerInterceptor.intercept_service.<locals>.wrapped-   s     --g66 ;!('!:!:::::::: )7446677~,3&    1kJJJ  
%,%8%8'%J%JJJJJJJJ        &   $   &:/5%&H&H' ' 't #0TBBBB         s0   DB>>D.D  DDDDc                T   K                        | |          2 3 d {V }|W V  6 d S r   )unary_streamr&   r'   rr?   s      r   r@   z4ServerInterceptor.intercept_service.<locals>.wrappedK   sX      &33GWEE       !GGGGG  FEE   'c                 D   K                        | |          }| d {V S r   )stream_unary)r&   r'   responser?   s      r   r@   z4ServerInterceptor.intercept_service.<locals>.wrappedR   s.      "//AA%~~~~~~%r    c                T   K                        | |          2 3 d {V }|W V  6 d S r   )stream_streamrC   s      r   r@   z4ServerInterceptor.intercept_service.<locals>.wrappedY   sX      &44WgFF       !GGGGG  GFFrE   )request_deserializerresponse_serializer)r&   r   r'   r   r   r   )
_handler_call_detailsrequest_streamingresponse_streamingr.   unary_unary_rpc_method_handlerunary_stream_rpc_method_handlerstream_unary_rpc_method_handler stream_stream_rpc_method_handlerrK   rL   )r   r!   r#   handler_factoryr@   r?   s   `    @r   intercept_servicez#ServerInterceptor.intercept_service    sn     
 &:"$%9::::::::?4( 1	1K 1	"AO       6 * 	w/I 	"BO       & 	w/I 	"BO& & & & & & & & 	7+E 	"CO      !(!= ' ;
 
 
 	
r    r'   r   c                     | j         j        S r   )rM   method)r   r'   s     r   r   zServerInterceptor._find_namec   s    )00r    r   )r   r   r   r   r   N)r   r   r!   r"   r#   r   r   r$   )__name__
__module____qualname__r   rU   strr   __classcell__)r   s   @r   r   r      s         @D!< 
     A
!A
SA
 3A
 
1	A
 A
 A
 A
F1"3 1 1 1 1 1 1 1 1 1r    r   )r3   sentry_sdk.constsr   sentry_sdk.integrationsr   #sentry_sdk.integrations.grpc.constsr   sentry_sdk.tracingr   r   sentry_sdk.utilsr   typingr	   collections.abcr
   r   r   r   r.   r   r   grpc.aior   r   ImportErroraior    r    r   <module>rh      sk                   0 0 0 0 0 0 ; ; ; ; ; ; = = = = = = = = 1 1 1 1 1 1             %33333333$$$$$$$$2KKK99999999444444444 2 2 2
,0
1
112M1 M1 M1 M1 M12 M1 M1 M1 M1 M1s   A A$