o
    ٰiL                     @   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 er,d dlm	Z	m
Z
mZmZmZ z d dlZd dlmZmZ d dlmZ d d	lmZ d d
lmZ W n eyW   edw G dd dejejZdS )    N)OP)DidNotEnable)SPAN_ORIGIN)TYPE_CHECKING)AnyCallableIteratorIterableUnion)ClientCallDetailsCall)_UnaryOutcome)UnaryStreamCall)Messagezgrpcio is not installedc                   @   s^   e Zd Z		 									dd
dZ		 								dddZe				dddZdS )ClientInterceptorselfcontinuation5Callable[[ClientCallDetails, Message], _UnaryOutcome]client_call_detailsr   requestr   returnr   c                 C   s   |j }tjtjd| td)}|dd |d| | |}|||}|d| j	 |W  d    S 1 s:w   Y  d S )Nzunary unary call to %sopnameorigintypezunary unarymethodcode)
r   
sentry_sdk
start_spanr   GRPC_CLIENTr   set_data/_update_client_call_details_metadata_from_scoper   r   r   r   r   r   r   spanresponse r&   W/home/ubuntu/.local/lib/python3.10/site-packages/sentry_sdk/integrations/grpc/client.pyintercept_unary_unary   s    
$z'ClientInterceptor.intercept_unary_unaryMCallable[[ClientCallDetails, Message], Union[Iterable[Any], UnaryStreamCall]]Union[Iterator[Message], Call]c                 C   sp   |j }tjtjd| td }|dd |d| | |}|||}|W  d    S 1 s1w   Y  d S )Nzunary stream call to %sr   r   zunary streamr   )r   r   r   r   r    r   r!   r"   r#   r&   r&   r'   intercept_unary_stream2   s   
$z(ClientInterceptor.intercept_unary_streamc                 C   s^   | j rt| j ng }t  D ]\}}|||f qtjj| j	| j
|| j| j| jd} | S )N)r   timeoutmetadatacredentialswait_for_readycompression)r-   listr   get_current_scopeiter_trace_propagation_headersappendgrpc_interceptor_ClientCallDetailsr   r,   r.   r/   r0   )r   r-   keyvaluer&   r&   r'   r"   L   s    
	zAClientInterceptor._update_client_call_details_metadata_from_scopeN)
r   r   r   r   r   r   r   r   r   r   )
r   r   r   r)   r   r   r   r   r   r*   )r   r   r   r   )__name__
__module____qualname__r(   r+   staticmethodr"   r&   r&   r&   r'   r      s:    

r   )r   sentry_sdk.constsr   sentry_sdk.integrationsr   #sentry_sdk.integrations.grpc.constsr   typingr   r   r   r   r	   r
   r5   r   r   grpc._interceptorr   grpc.aio._interceptorr   google.protobuf.messager   ImportErrorUnaryUnaryClientInterceptorUnaryStreamClientInterceptorr   r&   r&   r&   r'   <module>   s(    
