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rXd d
lmZ d dlmZmZ d dlmZmZ d dlmZ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Union)PipelineStrictRedis)ClusterPipelineRedisClusterpipeline_clsz6Union[type[Pipeline[Any]], type[ClusterPipeline[Any]]]
is_clusterget_command_args_fnr   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 |I d H S t jtjdtdT}t 3 z| jj	}W n t
y>   r9| j}n| j}Y nw ||  t|rLdn| j| W d    n1 s[w   Y  | g|R i |I d H W  d    S 1 sxw   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_stackcommand_stackr   is_transaction)r   r   r   spancommand_seqr   r   r   old_executer    _/home/ubuntu/.local/lib/python3.10/site-packages/sentry_sdk/integrations/redis/_async_common.py_sentry_execute#   s:   
$z3patch_redis_async_pipeline.<locals>._sentry_execute)r   r   r   r   r   r   r   r   )executesentry_sdk.integrations.redisr   )r   r   r   r   r2   r0   r.   r1   patch_redis_async_pipeline   s   
r5   clsz6Union[type[StrictRedis[Any]], type[RedisCluster[Any]]]c              
      sD   | j ddlm  dddtddddddf
 fd	d
}|| _ d S )Nr   r   r   r   r   r   r   r   c           
         s  t   }|d u r| |g|R i |I d H 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 |I d H }	|	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   r0   r1   _sentry_execute_commandL   sB   
z9patch_redis_async_client.<locals>._sentry_execute_command)execute_commandr4   r   str)r6   r   r   rC   r0   rA   r1   patch_redis_async_clientC   s   
-rF   ) 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   redis.asyncio.clientr   r   redis.asyncio.clusterr   r   boolr5   rF   r0   r0   r0   r1   <module>   sD    
*