o
    aie                     @   s   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 zd dlZd d
lmZmZ d dlmZmZ W n ey[   edw G dd dejjZdS )    N)OP)DidNotEnable)SPAN_ORIGIN)TransactionSource)event_from_exception)TYPE_CHECKING)	AwaitableCallable)AnyOptional)HandlerCallDetailsRpcMethodHandler)
AbortErrorServicerContextzgrpcio is not installedc                       sX   e Zd Z	d	 				d fddZ		 				
			dddZdddefddZ  ZS )ServerInterceptorNself	find_name'Callable[[ServicerContext], str] | Nonereturnc                    s   |p| j | _t   d S N)
_find_name_find_method_namesuper__init__)r   r   	__class__ e/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/sentry_sdk/integrations/grpc/aio/server.pyr      s   zServerInterceptor.__init__continuation;Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler]]handler_call_detailsr   %Optional[Awaitable[RpcMethodHandler]]c                    s   |_ ||I d H   d u rd S  js# js#tj}d fdd}n2 js4 jr4tj}d fdd}n! jrE jsEtj}d fd	d}n jrU jrUtj}d fd
d}|| j j	dS )Nrequestr
   contextr   r   c                    s    |}|s | |I d H S tjt| tj|tjt	d}tj
|d9 z | |I d H W W  d    S  ty@     ty^ } zt|dddd\}}tj||d  d }~ww 1 sbw   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eventr-   handlerr   r   r   wrapped-   s6   


z4ServerInterceptor.intercept_service.<locals>.wrappedc                   (     | |2 z	3 d H W }|V  q6 d S r   )unary_streamr"   r#   rr;   r   r   r<   K      c                    s     | |}|I d H S r   )stream_unary)r"   r#   responserA   r   r   r<   R   s   
c                   r=   r   )stream_streamr?   rA   r   r   r<   Y   rB   )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_handlerrF   rG   )r   r   r    handler_factoryr<   r   r:   r   intercept_service    s,   z#ServerInterceptor.intercept_servicer#   r   c                 C   s   | j jS r   )rH   method)r   r#   r   r   r   r   c   s   zServerInterceptor._find_namer   )r   r   r   r   r   N)r   r   r   r   r    r   r   r!   )__name__
__module____qualname__r   rP   strr   __classcell__r   r   r   r   r      s&    
Cr   )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   r   r   <module>   s$    