o
    BDi                     @   s   d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d d	lmZ erFd d
lmZ d dlmZ dd Zdd ZdS )    N)OP)SPAN_ORIGIN)_compile_cache_span_properties_set_cache_data)_compile_db_span_properties)_set_client_data_set_pipeline_data)Span)capture_internal_exceptions)TYPE_CHECKING)Callable)Anyc                    s0   | j ddlm   fdd}|| _ d S )Nr   RedisIntegrationc              
      s   t   d u r| g|R i |S t jtjdtdM}t / d }z| jj	}W n t
y6   | j}Y nw ||  t|rDdn| j| W d    n1 sSw   Y  | g|R i |W  d    S 1 smw   Y  d S )Nzredis.pipeline.executeopnameoriginF)
sentry_sdk
get_clientget_integration
start_spanr   DB_REDISr   r
   _execution_strategycommand_queueAttributeErrorcommand_stackr   transaction)selfargskwargsspancommand_seqr   get_command_args_fn
is_clusterold_executeset_db_data_fn c/var/www/Datamplify/venv/lib/python3.10/site-packages/sentry_sdk/integrations/redis/_sync_common.pysentry_patched_execute"   s4   

$z4patch_redis_pipeline.<locals>.sentry_patched_execute)executesentry_sdk.integrations.redisr   )pipeline_clsr%   r$   r'   r*   r(   r#   r)   patch_redis_pipeline   s   
r.   c                    s.   | j ddlm   fdd}|| _ dS )z`
    This function can be used to instrument custom redis client classes or
    subclasses.
    r   r   c           
         s  t   }|d u r| |g|R i |S t||||}d }|d r:|d d ur:t j|d |d td}|  t|||}t j|d |d td}|  ||  t||g|R   | |g|R i |}	|	d d d  |rt
|| ||	 |	d d d  |	S )Nis_cache_keyr   descriptionr   )r   r   r   r   r   r   	__enter__r   r   __exit__r   )
r   r   r   r    integrationcache_properties
cache_spandb_propertiesdb_spanvaluer   r%   old_execute_commandr'   r(   r)   sentry_patched_execute_commandK   s@   
z:patch_redis_client.<locals>.sentry_patched_execute_commandN)execute_commandr,   r   )clsr%   r'   r;   r(   r9   r)   patch_redis_clientA   s   
,r>   )r   sentry_sdk.constsr   $sentry_sdk.integrations.redis.constsr   ,sentry_sdk.integrations.redis.modules.cachesr   r   -sentry_sdk.integrations.redis.modules.queriesr   #sentry_sdk.integrations.redis.utilsr   r   sentry_sdk.tracingr	   sentry_sdk.utilsr
   typingr   collections.abcr   r   r.   r>   r(   r(   r(   r)   <module>   s    *