o
    ii=                     @   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__)self	find_name	__class__ f/var/www/html/pca-backend/venv/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)typehandled)	mechanism)hint)r   r   currentr   continue_from_headersdictinvocation_metadatar   GRPC_SERVERr   start_transactionunary_unaryr   	Exceptionr   capture_event)requestcontextr   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   )unary_streamr.   r/   rr4   r   r   r5   D      c                    s     | |}|I d H S r   )stream_unary)r.   r/   responser:   r   r   r5   L   s   
c                   r6   r   )stream_streamr8   r:   r   r   r5   T   r;   )request_deserializerresponse_serializer)
_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_handlerr?   r@   )r   continuationhandler_call_detailshandler_factoryr5   r   r3   r   intercept_service   s(   z#ServerInterceptor.intercept_servicec                 C   s   | j jS r   )rA   method)r   r/   r   r   r   r   _   s   zServerInterceptor._find_namer   )__name__
__module____qualname__r   rK   r   __classcell__r   r   r   r   r      s    Cr   )
sentry_sdkr   sentry_sdk._typesr   sentry_sdk.constsr   sentry_sdk.integrationsr   sentry_sdk.tracingr   r   sentry_sdk.utilsr   collections.abcr	   r
   typingr   r    r   r   grpc.aior   r   ImportErroraior   r   r   r   r   <module>   s"    