o
    Zh	                     @   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
 er0d 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yK   ed
w G dd dejZdS )    )Hub)MYPY)OP)DidNotEnable)TransactionTRANSACTION_SOURCE_CUSTOM)CallableOptional)MessageN)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t |   d S N)r   
_find_name_find_method_namesuper__init__)selfZ	find_name	__class__ Z/var/www/html/lang_env/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 t j}|}|rJt| }tj|tj|t	d}|j
|d z | |W W  d    S  ty? } z|d }~ww 1 sCw   Y  d S  | |S )N)opnamesource)transaction)r   currentr   dictZinvocation_metadatar   Zcontinue_from_headersr   ZGRPC_SERVERr   Zstart_transactionunary_unaryBaseException)requestcontextZhubr   metadatar   ehandlerr   r   r   behavior   s(   

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   )Z
sentry_sdkr   Zsentry_sdk._typesr   Zsentry_sdk.constsr   Zsentry_sdk.integrationsr   Zsentry_sdk.tracingr   r   typingr   r	   Zgoogle.protobuf.messager
   r*   r   r   r   ImportErrorr   r   r   r   r   <module>   s    