
    \j                        d dl Z d dlmZ d dlmZ d dlmZ d dl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  G d dej2                  j4                        Zy# e$ r	  ed      w xY w)    N)OP)DidNotEnable)SPAN_ORIGIN)TransactionSource)event_from_exception)TYPE_CHECKING)	AwaitableCallable)AnyOptional)HandlerCallDetailsRpcMethodHandler)
AbortErrorServicerContextzgrpcio is not installedc                   F     e Zd Z	 d	 	 	 	 	 d fdZ	 	 	 	 	 	 	 	 ddZ xZS )ServerInterceptorc                 0    || _         t        | 	          y N)_custom_find_namesuper__init__)self	find_name	__class__s     Q/root/env/lib/python3.12/site-packages/sentry_sdk/integrations/grpc/aio/server.pyr   zServerInterceptor.__init__   s     "+    c                 "  K    ||       d {   y |j                   | j                  j                  s%j                  st        j
                  }dfd}nj                  s#j                  rt        j                  }dfd}n]j                  r#j                  st        j                  }dfd}n.j                  r"j                  rt        j                  }dfd} j                  j                        S 7 w)Nc           	        K   t        j                         5  r |      n	}|s | |       d {   cd d d        S t        j                  t        |j	                               t
        j                  |t        j                  t              }t        j                  |      5  	 j                  | |       d {   cd d d        cd d d        S 7 7 # t        $ r  t        $ r0}t        |ddd      \  }}t        j                  ||        d }~ww xY w# 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY ww)N)opnamesourceorigin)transactiongrpcF)typehandled)	mechanism)hint)
sentry_sdkisolation_scopecontinue_tracedictinvocation_metadatar   GRPC_SERVERr   CUSTOMr   start_transactionunary_unaryr   	Exceptionr   capture_event)
requestcontextr    r#   exceventr(   custom_find_namehandlermethod_names
          r   wrappedz4ServerInterceptor.intercept_service.<locals>.wrapped/   s4    //1 "5E(1;   %,Wg%>>" " #-";";W88:;>>!077*#K $55+N "
")0)<)<Wg)N#N" "!" "
  ? $O) "!( "*> #39e*L+KE4 '44UF!"" " "!" " "s   ED5CD5
EA'D5(D*C?C C	D5
ED5CD,+DDDD(	$D5,	E5D>:Ec                V   K   j                  | |      2 3 d {   }| 7 
6 y wr   )unary_streamr4   r5   rr9   s      r   r;   z4ServerInterceptor.intercept_service.<locals>.wrappedP   s1     &33GWE  !GE   )'%')')c                 H   K   j                  | |      }| d {   S 7 wr   )stream_unary)r4   r5   responser9   s      r   r;   z4ServerInterceptor.intercept_service.<locals>.wrappedW   s#     "//A%~%~s   " "c                V   K   j                  | |      2 3 d {   }| 7 
6 y wr   )stream_streamr>   s      r   r;   z4ServerInterceptor.intercept_service.<locals>.wrapped^   s1     &44WgF  !GFr@   )request_deserializerresponse_serializer)r4   r   r5   r   returnr   )methodr   request_streamingresponse_streamingr$   unary_unary_rpc_method_handlerunary_stream_rpc_method_handlerstream_unary_rpc_method_handler stream_stream_rpc_method_handlerrF   rG   )r   continuationhandler_call_detailshandler_factoryr;   r8   r9   r:   s        @@@r   intercept_servicez#ServerInterceptor.intercept_service    s     
 %%9::?*1111((1K1K"AAO" "< **w/I/I"BBO &&w/I/I"BBO& &&7+E+E"CCO !(!=!= ' ; ;
 	
{ ;s   DDC<Dr   )r   r   r   z'Callable[[ServicerContext], str] | NonerH   N)r   r   rP   z;Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler]]rQ   r   rH   z%Optional[Awaitable[RpcMethodHandler]])__name__
__module____qualname__r   rS   __classcell__)r   s   @r   r   r      sW     @D!< 
F
!F
SF
 3F
 
1	F
r   r   )r)   sentry_sdk.constsr   sentry_sdk.integrationsr   #sentry_sdk.integrations.grpc.constsr   sentry_sdk.tracingr   sentry_sdk.utilsr   typingr   collections.abcr	   r
   r   r   r$   r   r   grpc.aior   r   ImportErroraior    r   r   <module>rc      sf       0 ; 0 1  3$294
O
22 O
	  2
0
112s   A0 0A>