o
    ٰi                  
   @   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deddddddf
ddZdddeddddf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)Anypipeline_clsr   
is_clusterget_command_args_fnset_db_data_fnzCallable[[Span, Any], None]returnc                    s2   | j ddlm  d
 fdd	}|| _ d S )Nr   RedisIntegrationselfr   argskwargsr   c              
      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)r   r   r   spancommand_seqr   r   r   old_executer    ^/home/ubuntu/.local/lib/python3.10/site-packages/sentry_sdk/integrations/redis/_sync_common.pysentry_patched_execute!   s4   

$z4patch_redis_pipeline.<locals>.sentry_patched_execute)r   r   r   r   r   r   r   r   )executesentry_sdk.integrations.redisr   )r   r   r   r   r,   r*   r(   r+   patch_redis_pipeline   s   
r/   clsc              
      sD   | j ddlm  dddtddddddf
 fd	d
}|| _ dS )z`
    This function can be used to instrument custom redis client classes or
    subclasses.
    r   r   r   r   r   r   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_commandJ   s@   
z:patch_redis_client.<locals>.sentry_patched_execute_commandN)execute_commandr.   r   str)r0   r   r   r=   r*   r;   r+   patch_redis_client?   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   boolr/   r@   r*   r*   r*   r+   <module>   s@    
(