o
    ii                     @  s   d dl mZ d dlZd dlmZmZ zd dlmZ d dlm	Z	m
Z
 W n ey-   edw d dlmZ d dlmZ erHd d	lmZ d d
lmZ dddZddddZdS )    )annotationsN)TYPE_CHECKINGAny)RedisInstrumentor)RequestHookResponseHookz`logfire.instrument_redis()` requires the `opentelemetry-instrumentation-redis` package.
You can install this with:
    pip install 'logfire[redis]')ATTRIBUTES_MESSAGE_KEY)truncate_string)Span)
Connectioncapture_statementboolrequest_hookRequestHook | Noneresponse_hookResponseHook | Nonekwargsr   returnNonec                 K  s(   | rt |}t jd||d| dS )zInstrument the `redis` module so that spans are automatically created for each operation.

    See the `Logfire.instrument_redis` method for details.
    )r   r   N )_capture_statement_hookr   
instrument)r   r   r   r   r   r   j/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/_internal/integrations/redis.pyinstrument_redis   s   r   r   c                   s$   t jtdddd fdd}|S )N   z...)
max_lengthmiddlespanr
   instancer   commandtuple[object, ...]argsr   r   r   r   c                   sb   t tt|}| dd| | tdt|  d ur/ | ||g|R i | d S d S )Nzdb.statement )listmapstrset_attributejoinr   )r   r   r   r!   r   str_commandr   truncate_valuer   r   _capture_statement-   s   z3_capture_statement_hook.<locals>._capture_statement)r   r
   r   r   r   r    r!   r   r   r   r   r   )	functoolspartialr	   )r   r+   r   r)   r   r   *   s   	r   )
r   r   r   r   r   r   r   r   r   r   )N)r   r   r   r   )
__future__r   r,   typingr   r   #opentelemetry.instrumentation.redisr   logfire.integrations.redisr   r   ImportErrorRuntimeErrorlogfire._internal.constantsr   logfire._internal.utilsr	   opentelemetry.tracer
   redisr   r   r   r   r   r   r   <module>   s$    
