o
    h	                     @   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__)self	find_name	__class__ f/var/www/html/aiguide_backend/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 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   dictinvocation_metadatar   continue_from_headersr   GRPC_SERVERr   start_transactionunary_unaryBaseException)requestcontexthubr   metadatar   ehandlerr   r   r   behavior   s(   

z5ServerInterceptor.intercept_service.<locals>.behavior)request_deserializerresponse_serializer)r$   grpcunary_unary_rpc_method_handlerr.   r/   )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   r4   staticmethodr   __classcell__r   r   r   r   r      s
    $r   )
sentry_sdkr   sentry_sdk._typesr   sentry_sdk.constsr   sentry_sdk.integrationsr   sentry_sdk.tracingr   r   typingr   r	   google.protobuf.messager
   r0   r   r   r   ImportErrorr   r   r   r   r   <module>   s    