o
    0 i	                     @   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m	Z	 d dl
mZ er4d dl
mZmZ d dlmZ zd dlZd d	lmZmZmZ W n eyO   ed
w G dd dejZdS )    N)OP)DidNotEnable)SPAN_ORIGIN)TransactionTransactionSource)TYPE_CHECKING)CallableOptional)Message)ServicerContextHandlerCallDetailsRpcMethodHandlerzgrpcio is not installedc                       s2   e Zd Zd fdd	Zdd Zedd Z  ZS )	ServerInterceptorNc                    s   |pt j| _t   d S N)r   
_find_name_find_method_namesuper__init__)selfZ	find_name	__class__ o/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/sentry_sdk/integrations/grpc/server.pyr      s   zServerInterceptor.__init__c                    s8   ||  r	 j s S  fdd}tj| j jdS )Nc                    s   t  c |}|rRt| }tj|tj|t	j
td}t j|d% z | |W W  d    W  d    S  tyH } z|d }~ww 1 sLw   Y  n | |W  d    S W d    d S 1 sjw   Y  d S )N)opnamesourceorigin)transaction)
sentry_sdkZisolation_scoper   dictZinvocation_metadatar   Zcontinue_from_headersr   ZGRPC_SERVERr   ZCUSTOMr   Zstart_transactionunary_unaryBaseException)requestcontextr   metadatar   ehandlerr   r   r   behavior!   s2   


"z5ServerInterceptor.intercept_service.<locals>.behavior)request_deserializerresponse_serializer)r    grpcZunary_unary_rpc_method_handlerr)   r*   )r   ZcontinuationZhandler_call_detailsr(   r   r&   r   intercept_service   s   
z#ServerInterceptor.intercept_servicec                 C   s   | j jj S r   )Z
_rpc_eventZcall_detailsmethoddecode)r#   r   r   r   r   ?   s   zServerInterceptor._find_namer   )__name__
__module____qualname__r   r,   staticmethodr   __classcell__r   r   r   r   r      s
    $r   )r   Zsentry_sdk.constsr   Zsentry_sdk.integrationsr   Z#sentry_sdk.integrations.grpc.constsr   Zsentry_sdk.tracingr   r   typingr   r   r	   Zgoogle.protobuf.messager
   r+   r   r   r   ImportErrorr   r   r   r   r   <module>   s     