o
    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                       s\   e Zd Z	d	 				d fddZ		 				
			dddZedddefddZ  ZS )ServerInterceptorNself	find_name*Optional[Callable[[ServicerContext], str]]returnc                    s   |pt j| _t   d S N)r   
_find_name_find_method_namesuper__init__)r   r   	__class__ `/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/sentry_sdk/integrations/grpc/server.pyr      s   zServerInterceptor.__init__continuation0Callable[[HandlerCallDetails], RpcMethodHandler]handler_call_detailsr   r   c                    s:   ||  r	 j s S d	 fdd}tj| j jdS )
Nrequestr
   contextr   r   c                    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_sdkisolation_scoper   dictinvocation_metadatacontinue_tracer   GRPC_SERVERr   CUSTOMr   start_transactionunary_unaryBaseException)r   r    r"   metadatar%   ehandlerr   r   r   behavior&   s2   


"z5ServerInterceptor.intercept_service.<locals>.behavior)request_deserializerresponse_serializer)r   r
   r    r   r   r
   )r.   grpcunary_unary_rpc_method_handlerr5   r6   )r   r   r   r4   r   r2   r   intercept_service   s   
z#ServerInterceptor.intercept_servicer    r   c                 C   s   | j jj S r   )
_rpc_eventcall_detailsmethoddecode)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   r9   staticmethodstrr   __classcell__r   r   r   r   r      s(    
&r   )r&   sentry_sdk.constsr   sentry_sdk.integrationsr   #sentry_sdk.integrations.grpc.constsr   sentry_sdk.tracingr   r   typingr   r   r	   google.protobuf.messager
   r7   r   r   r   ImportErrorr   r   r   r   r   <module>   s     