o
    S۷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                       sF   e Zd Z	d	 				d fddZ		 				
			dddZ  ZS )ServerInterceptorNself	find_name*Optional[Callable[[ServicerContext], str]]returnc                    s   || _ t   d S N)_custom_find_namesuper__init__)r   r   	__class__ Y/home/ubuntu/vllm_env/lib/python3.10/site-packages/sentry_sdk/integrations/grpc/server.pyr      s   zServerInterceptor.__init__continuation0Callable[[HandlerCallDetails], RpcMethodHandler]handler_call_detailsr   r   c                    sH   ||r	j sS |j| j d	 fdd}tj|jjdS )
Nrequestr
   contextr   r   c                    s   t  f  r |n}|rUt| }t j|tj|tjt	d}t j
|d% z| |W W  d    W  d    S  tyK } z|d }~ww 1 sOw   Y  n| |W  d    S W d    d S 1 smw   Y  d S )N)opnamesourceorigin)transaction)
sentry_sdkisolation_scopedictinvocation_metadatacontinue_tracer   GRPC_SERVERr   CUSTOMr   start_transactionunary_unaryBaseException)r   r   r!   metadatar$   ecustom_find_namehandlermethod_namer   r   behavior)   s2   

"z5ServerInterceptor.intercept_service.<locals>.behavior)request_deserializerresponse_serializer)r   r
   r   r   r   r
   )r-   methodr   grpcunary_unary_rpc_method_handlerr6   r7   )r   r   r   r5   r   r1   r   intercept_service   s   
z#ServerInterceptor.intercept_servicer   )r   r   r   r   r   N)r   r   r   r   r   r   r   r   )__name__
__module____qualname__r   r;   __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
   r9   r   r   r   ImportErrorr   r   r   r   r   <module>   s     