o
    Zh=                     @   s   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	m
Z
 d dlmZ er6d dlmZmZ d dlmZ zd d	lZd d
lmZmZ d dlmZmZ W n eyW   edw G dd dejjZd	S )    )Hub)MYPY)OP)DidNotEnable)TransactionTRANSACTION_SOURCE_CUSTOM)event_from_exception)	AwaitableCallable)AnyN)HandlerCallDetailsRpcMethodHandler)
AbortErrorServicerContextzgrpcio is not installedc                       s.   e Zd Zd fdd	Zdd Zdd Z  ZS )	ServerInterceptorNc                    s   |p| j | _tt|   d S N)
_find_name_find_method_namesuperr   __init__)selfZ	find_name	__class__ ^/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/integrations/grpc/aio/server.pyr      s   zServerInterceptor.__init__c                    s   |_ ||I d H   js jstj} fdd}n/ js, jr,tj} fdd}n jr< js<tj} fdd}n jrK jrKtj} fdd}|| j j	dS )Nc                    s    |}|s | |I d H S tj}tjt| tj|t	d}|j
|d9 z | |I d H W W  d    S  tyA     ty_ } zt|dddd\}}|j||d  d }~ww 1 scw   Y  d S )N)opnamesource)transactiongrpcF)typeZhandled)Z	mechanism)hint)r   r   currentr   Zcontinue_from_headersdictZinvocation_metadatar   ZGRPC_SERVERr   Zstart_transactionZunary_unaryr   	Exceptionr   Zcapture_event)requestcontextr   Zhubr   exceventr!   handlerr   r   r   wrapped$   s6   


z4ServerInterceptor.intercept_service.<locals>.wrappedc                   (     | |2 z	3 d H W }|V  q6 d S r   )Zunary_streamr%   r&   rr*   r   r   r+   D      c                    s     | |}|I d H S r   )Zstream_unary)r%   r&   responser/   r   r   r+   L   s   
c                   r,   r   )Zstream_streamr-   r/   r   r   r+   T   r0   )request_deserializerresponse_serializer)
_handler_call_detailsZrequest_streamingZresponse_streamingr   Zunary_unary_rpc_method_handlerZunary_stream_rpc_method_handlerZstream_unary_rpc_method_handlerZ stream_stream_rpc_method_handlerr2   r3   )r   ZcontinuationZhandler_call_detailsZhandler_factoryr+   r   r)   r   intercept_service   s(   z#ServerInterceptor.intercept_servicec                 C   s   | j jS r   )r4   method)r   r&   r   r   r   r   _   s   zServerInterceptor._find_namer   )__name__
__module____qualname__r   r5   r   __classcell__r   r   r   r   r      s    Cr   )Z
sentry_sdkr   Zsentry_sdk._typesr   Zsentry_sdk.constsr   Zsentry_sdk.integrationsr   Zsentry_sdk.tracingr   r   Zsentry_sdk.utilsr   collections.abcr	   r
   typingr   r   r   r   Zgrpc.aior   r   ImportErrorZaior   r   r   r   r   <module>   s"    