o
    h	                     @   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__)self	find_name	__class__ e/var/www/html/pro-man-master/venv/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_sdkisolation_scoper   dictinvocation_metadatar   continue_from_headersr   GRPC_SERVERr   CUSTOMr   start_transactionunary_unaryBaseException)requestcontextr   metadatar   ehandlerr   r   r   behavior!   s2   


"z5ServerInterceptor.intercept_service.<locals>.behavior)request_deserializerresponse_serializer)r'   grpcunary_unary_rpc_method_handlerr0   r1   )r   continuationhandler_call_detailsr/   r   r-   r   intercept_service   s   
z#ServerInterceptor.intercept_servicec                 C   s   | j jj S r   )
_rpc_eventcall_detailsmethoddecode)r*   r   r   r   r   ?   s   zServerInterceptor._find_namer   )__name__
__module____qualname__r   r6   staticmethodr   __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
   r2   r   r   r   ImportErrorr   r   r   r   r   <module>   s     