Ë
    §Œje5  ã                   ó’  — d Z ddlmZ ddlmZmZmZmZmZ ddl	Z	erddl
mZ ddlmZ ddlmZ ddlmZ d	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(d Z)d!Z*d"Z+d#Z,d$Z-d%Z.d&Z/d'Z0 G d(„ d)e«      Z1 G d*„ d+e«      Z2 G d,„ d-e«      Z3 G d.„ d/e«      Z4 G d0„ d1e«      Z5 G d2„ d3«      Z6d4ed5   d6e7fd7„Z8d8ed9   fd:„Z9y);a  
OpenTelemetry semantic convention attributes for Redis.

This module provides constants and helper functions for building OTel attributes
according to the semantic conventions for database clients.

Reference: https://opentelemetry.io/docs/specs/semconv/database/redis/
é    )ÚEnum)ÚTYPE_CHECKINGÚAnyÚDictÚOptionalÚUnionN)ÚConnectionPool)ÚAsyncDatabase)ÚConnectionPoolInterface)ÚSyncDatabasez	db.systemzdb.namespacezdb.operation.namezdb.response.status_codezdb.stored_procedure.namez
error.typeznetwork.peer.addressznetwork.peer.portzserver.addresszserver.portzdb.client.connection.pool.namezdb.client.connection.statezdb.client.connection.namezdb.client.geofailover.fail_fromzdb.client.geofailover.fail_tozdb.client.geofailover.reasonzredis.client.libraryzredis.client.connection.pubsubz$redis.client.connection.close.reasonz$redis.client.connection.notificationz%redis.client.operation.retry_attemptszredis.client.operation.blockingz%redis.client.pubsub.message.directionzredis.client.pubsub.channelzredis.client.pubsub.shardedzredis.client.errors.internalzredis.client.errors.categoryzredis.client.stream.namezredis.client.consumer_groupzredis.client.csc.resultzredis.client.csc.reasonc                   ó   — e Zd ZdZdZy)ÚConnectionStateÚidleÚusedN)Ú__name__Ú
__module__Ú__qualname__ÚIDLEÚUSED© ó    úh/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/redis/observability/attributes.pyr   r   C   s   „ Ø€DØ�Dr   r   c                   ó   — e Zd ZdZdZy)ÚPubSubDirectionÚpublishÚreceiveN)r   r   r   ÚPUBLISHÚRECEIVEr   r   r   r   r   H   s   „ Ø€GØ�Gr   r   c                   ó   — e Zd ZdZdZy)Ú	CSCResultÚhitÚmissN)r   r   r   ÚHITÚMISSr   r   r   r    r    M   s   „ Ø
€CØ�Dr   r    c                   ó   — e Zd ZdZdZy)Ú	CSCReasonÚfullÚinvalidationN)r   r   r   ÚFULLÚINVALIDATIONr   r   r   r&   r&   R   s   „ Ø€DØ!�Lr   r&   c                   ó   — e Zd ZdZdZy)ÚGeoFailoverReasonÚ	automaticÚmanualN)r   r   r   Ú	AUTOMATICÚMANUALr   r   r   r,   r,   W   s   „ Ø€IØ�Fr   r,   c                   óŠ  — e Zd ZdZe	 	 	 d(dee   dee   dee   deee	f   fd„«       Z
e	 	 	 	 	 	 	 d)deeeef      d	ee   d
ee   dee   dee   dee   dee   deee	f   fd„«       Ze	 	 	 	 d*dee   dee   dee   dee   deee	f   f
d„«       Ze	 	 d+dee   dee   deee	f   fd„«       Ze	 	 d+dedee   dee   deee	f   fd„«       Ze	 	 	 d(dee   dee   dee   deee	f   fd„«       Ze	 	 	 d(dee   d ee   d!ee   deee	f   fd"„«       Zed#ed$   d%ed$   d!edeee	f   fd&„«       Ze	 d,dedededefd'„«       Zy)-ÚAttributeBuilderzY
    Helper class to build OTel semantic convention attributes for Redis operations.
    NÚserver_addressÚserver_portÚdb_namespaceÚreturnc                 ó˜   — t         dt        dt        j                  › �i}| �	| |t        <   |�	||t
        <   |�t        |«      |t        <   |S )a*  
        Build base attributes common to all Redis operations.

        Args:
            server_address: Redis server address (FQDN or IP)
            server_port: Redis server port
            db_namespace: Redis database index

        Returns:
            Dictionary of base attributes
        Úredisz
redis-py:v)Ú	DB_SYSTEMÚREDIS_CLIENT_LIBRARYr8   Ú__version__ÚSERVER_ADDRESSÚSERVER_PORTÚstrÚDB_NAMESPACE)r3   r4   r5   Úattrss       r   Úbuild_base_attributesz&AttributeBuilder.build_base_attributesa   s_   € ô$ �wÜ  J¬u×/@Ñ/@Ð.AÐ"Bð!
ˆð
 Ð%Ø$2ˆE”.Ñ!àÐ"Ø!,ˆE”+ÑàÐ#Ü"% lÓ"3ˆE”,Ñàˆr   Úcommand_nameÚ
batch_sizeÚnetwork_peer_addressÚnetwork_peer_portÚstored_procedure_nameÚretry_attemptsÚis_blockingc                 óú   — i }| �:t        | t        «      r| j                  dd¬«      } | j                  «       |t        <   |�	||t
        <   |�	||t        <   |�	||t        <   |�|dkD  r	||t        <   |�	||t        <   |S )aw  
        Build attributes for a Redis operation (command execution).

        Args:
            command_name: Redis command name (e.g., 'GET', 'SET', 'MULTI'), can be str or bytes
            batch_size: Number of commands in batch (for pipelines/transactions)
            network_peer_address: Resolved peer address
            network_peer_port: Peer port number
            stored_procedure_name: Lua script name or SHA1 digest
            retry_attempts: Number of retry attempts made
            is_blocking: Whether the operation is a blocking command

        Returns:
            Dictionary of operation attributes
        zutf-8Úreplace)Úerrorsr   )
Ú
isinstanceÚbytesÚdecodeÚupperÚDB_OPERATION_NAMEÚNETWORK_PEER_ADDRESSÚNETWORK_PEER_PORTÚDB_STORED_PROCEDURE_NAMEÚ%REDIS_CLIENT_OPERATION_RETRY_ATTEMPTSÚREDIS_CLIENT_OPERATION_BLOCKING)rB   rC   rD   rE   rF   rG   rH   r@   s           r   Úbuild_operation_attributesz+AttributeBuilder.build_operation_attributes‚   s£   € ð2 !#ˆàÐ#ä˜,¬Ô.Ø+×2Ñ2°7À9Ð2ÓM�Ø'3×'9Ñ'9Ó';ˆEÔ#Ñ$àÐ+Ø*>ˆEÔ&Ñ'àÐ(Ø'8ˆEÔ#Ñ$à Ð,Ø.CˆEÔ*Ñ+àÐ%¨.¸1Ò*<Ø;IˆEÔ7Ñ8àÐ"Ø5@ˆEÔ1Ñ2àˆr   Ú	pool_nameÚconnection_stateÚconnection_nameÚ	is_pubsubc                 óš   — t         j                  «       }| �	| |t        <   |�|j                  |t        <   |�	||t
        <   |�	||t        <   |S )ay  
        Build attributes for connection pool metrics.

        Args:
            pool_name: Unique connection pool name
            connection_state: Connection state ('idle' or 'used')
            is_pubsub: Whether this is a PubSub connection
            connection_name: Unique connection name

        Returns:
            Dictionary of connection pool attributes
        )r2   rA   ÚDB_CLIENT_CONNECTION_POOL_NAMEÚvalueÚDB_CLIENT_CONNECTION_STATEÚREDIS_CLIENT_CONNECTION_PUBSUBÚDB_CLIENT_CONNECTION_NAME)rW   rX   rY   rZ   r@   s        r   Úbuild_connection_attributesz,AttributeBuilder.build_connection_attributes´   sa   € ô& !1× FÑ FÓ HˆàÐ Ø4=ˆEÔ0Ñ1àÐ'Ø0@×0FÑ0FˆEÔ,Ñ-àÐ Ø4=ˆEÔ0Ñ1àÐ&Ø/>ˆEÔ+Ñ,àˆr   Ú
error_typeÚis_internalc                 óF  — i }| �‘| j                   j                  |t        <   t        | d«      r | j                  �| j                  |t
        <   n	d|t
        <   t        | d«      r*| j                  �| j                  j                  |t        <   n	d|t        <   |�	||t        <   |S )zÿ
        Build error attributes.

        Args:
            is_internal: Whether the error is internal (e.g., timeout, network error)
            error_type: The exception that occurred

        Returns:
            Dictionary of error attributes
        Ústatus_codeÚerrorrb   Úother)
Ú	__class__r   Ú
ERROR_TYPEÚhasattrre   ÚDB_RESPONSE_STATUS_CODErb   r]   ÚREDIS_CLIENT_ERROR_CATEGORYÚREDIS_CLIENT_ERROR_INTERNAL)rb   rc   r@   s      r   Úbuild_error_attributesz'AttributeBuilder.build_error_attributes×   s¦   € ð !#ˆàÐ!Ø *× 4Ñ 4× =Ñ =ˆE”*Ñô ˜
 MÔ2Ø×*Ñ*Ð6à1;×1GÑ1G�Ô-Ò.à18�Ô-Ñ.ä�z <Ô0°Z×5JÑ5JÐ5VØ5?×5JÑ5J×5PÑ5P�Ô1Ò2à5<�Ô1Ñ2àÐ"Ø1<ˆEÔ-Ñ.àˆr   Ú	directionÚchannelÚshardedc                 ó€   — t         j                  «       }| j                  |t        <   |�	||t        <   |�	||t
        <   |S )a.  
        Build attributes for a PubSub message.

        Args:
            direction: Message direction ('publish' or 'receive')
            channel: Pub/Sub channel name
            sharded: True if sharded Pub/Sub channel

        Returns:
            Dictionary of PubSub message attributes
        )r2   rA   r]   Ú%REDIS_CLIENT_PUBSUB_MESSAGE_DIRECTIONÚREDIS_CLIENT_PUBSUB_CHANNELÚREDIS_CLIENT_PUBSUB_SHARDED)ro   rp   rq   r@   s       r   Úbuild_pubsub_message_attributesz0AttributeBuilder.build_pubsub_message_attributesý   sH   € ô" !1× FÑ FÓ HˆØ7@·±ˆÔ3Ñ4àÐØ18ˆEÔ-Ñ.àÐØ18ˆEÔ-Ñ.àˆr   Ústream_nameÚconsumer_groupÚconsumer_namec                 óZ   — t         j                  «       }| �	| |t        <   |�	||t        <   |S )a   
        Build attributes for a streaming operation.

        Args:
            stream_name: Name of the stream
            consumer_group: Name of the consumer group
            consumer_name: Name of the consumer

        Returns:
            Dictionary of streaming attributes
        )r2   rA   ÚREDIS_CLIENT_STREAM_NAMEÚREDIS_CLIENT_CONSUMER_GROUP)rw   rx   ry   r@   s       r   Úbuild_streaming_attributesz+AttributeBuilder.build_streaming_attributes  s9   € ô" !1× FÑ FÓ HˆàÐ"Ø.9ˆEÔ*Ñ+àÐ%Ø1?ˆEÔ-Ñ.àˆr   ÚresultÚreasonc                 ó˜   — t         j                  «       }| �	| |t        <   |�|j                  |t        <   |�|j                  |t
        <   |S )a\  
        Build attributes for a Client Side Caching (CSC) operation.

        Args:
            pool_name: Connection pool name (used only for csc_items metric)
            result: CSC result ('hit' or 'miss')
            reason: Reason for CSC eviction ('full' or 'invalidation')

        Returns:
            Dictionary of CSC attributes
        )r2   rA   r\   r]   ÚREDIS_CLIENT_CSC_RESULTÚREDIS_CLIENT_CSC_REASON)rW   r~   r   r@   s       r   Úbuild_csc_attributesz%AttributeBuilder.build_csc_attributes4  sR   € ô" !1× FÑ FÓ HˆàÐ Ø4=ˆEÔ0Ñ1àÐØ-3¯\©\ˆEÔ)Ñ*àÐØ-3¯\©\ˆEÔ)Ñ*àˆr   Ú	fail_from©r   r
   Úfail_toc                 óœ   — t         j                  «       }t        | «      |t        <   t        |«      |t        <   |j
                  |t        <   |S )a	  
        Build attributes for a geo failover.

        Args:
            fail_from: Database failed from
            fail_to: Database failed to
            reason: Reason for the failover

        Returns:
            Dictionary of geo failover attributes
        )r2   rA   Úget_db_nameÚDB_CLIENT_GEOFAILOVER_FAIL_FROMÚDB_CLIENT_GEOFAILOVER_FAIL_TOr]   ÚDB_CLIENT_GEOFAILOVER_REASON)r„   r†   r   r@   s       r   Úbuild_geo_failover_attributesz.AttributeBuilder.build_geo_failover_attributesR  sF   € ô" !1× FÑ FÓ Hˆä1<¸YÓ1GˆÔ-Ñ.Ü/:¸7Ó/CˆÔ+Ñ,Ø.4¯l©lˆÔ*Ñ+àˆr   c                 ó   — | › d|› d|› �S )a  
        Build a unique connection pool name.

        Args:
            server_address: Redis server address
            server_port: Redis server port
            db_namespace: Redis database index

        Returns:
            Unique pool name in format "address:port/db"
        Ú:Ú/r   )r3   r4   r5   s      r   Úbuild_pool_namez AttributeBuilder.build_pool_namek  s   € ð" !Ð!  ; -¨q°°Ð?Ð?r   )NNN)NNNNNNN)NNNN)NN)r   )r   r   r   Ú__doc__Ústaticmethodr   r>   Úintr   r   rA   r   rM   ÚboolrV   r   ra   Ú	Exceptionrn   r   rv   r}   r    r&   rƒ   r,   rŒ   r�   r   r   r   r2   r2   \   s:  „ ñð à(,Ø%)Ø&*ñØ  ™ðà˜c‘]ðð ˜s‘mðð 
ˆc�3ˆh‰ò	ó ðð@ à48Ø$(Ø.2Ø+/Ø/3Ø(,Ø&*ñ/Ø˜u S¨% ZÑ0Ñ1ð/à˜S‘Mð/ð ' s™mð/ð $ C™=ð	/ð
  (¨™}ð/ð ! ™ð/ð ˜d‘^ð/ð 
ˆc�3ˆh‰ò/ó ð/ðb à#'Ø6:Ø)-Ø$(ñ	 Ø˜C‘=ð à" ?Ñ3ð ð " #™ð ð ˜D‘>ð	 ð
 
ˆc�3ˆh‰ò ó ð ðD à*.Ø&*ñ#Ø˜YÑ'ð#à˜d‘^ð#ð 
ˆc�3ˆh‰ò#ó ð#ðJ ð "&Ø"&ñØ"ðà˜#‘ðð ˜$‘ðð 
ˆc�3ˆh‰ò	ó ðð6 à%)Ø(,Ø'+ñØ˜c‘]ðà  ™ðð   ‘}ðð 
ˆc�3ˆh‰ò	ó ðð4 à#'Ø&*Ø&*ñØ˜C‘=ðà˜Ñ#ðð ˜Ñ#ðð 
ˆc�3ˆh‰ò	ó ðð: ðØÐ8Ñ9ðàÐ6Ñ7ðð "ðð 
ˆc�3ˆh‰ò	ó ðð0 ð ñ@Øð@àð@ð ð@ð 
ò	@ó ñ@r   r2   Úpool)r   r	   r6   c                 ó²   — | j                   j                  dd«      }| j                   j                  dd«      }t        | dd«      }|r
|› d|› d|› �S |› d|› �S )	aõ  
    Get a short string representation of a connection pool for observability.

    This provides a concise pool identifier suitable for use as a metric attribute,
    in the format: host:port_uniqueID (matching go-redis format)

    Args:
        pool: Connection pool instance

    Returns:
        Short pool name in format "host:port_uniqueID"

    Example:
        >>> pool = ConnectionPool(host='localhost', port=6379, db=0)
        >>> get_pool_name(pool)
        'localhost:6379_a1b2c3d4'
    ÚhostÚunknownÚportië  Ú_pool_idÚ rŽ   Ú_)Úconnection_kwargsÚgetÚgetattr)r–   r˜   rš   Úpool_ids       r   Úget_pool_namer¢     so   € ð$ ×!Ñ!×%Ñ% f¨iÓ8€DØ×!Ñ!×%Ñ% f¨dÓ3€Dô �d˜J¨Ó+€GáØ��q˜˜˜a ˜yÐ)Ð)à��q˜˜ÐÐr   Údatabaser…   c                 ó¢   — | j                   j                  «       d   }| j                   j                  «       d   }| j                  }|› d|› d|› �S )zÈ
    Get a short string representation of a database for observability.

    Args:
        database: Database instance

    Returns:
        Short database name in format "{host}:{port}/{weight}"
    r˜   rš   rŽ   r�   )ÚclientÚget_connection_kwargsÚweight)r£   r˜   rš   r§   s       r   rˆ   rˆ   �  sR   € ð �?‰?×0Ñ0Ó2°6Ñ:€DØ�?‰?×0Ñ0Ó2°6Ñ:€DØ�_‰_€FàˆV�1�T�F˜!˜F˜8Ð$Ð$r   ):r‘   Úenumr   Útypingr   r   r   r   r   r8   Úredis.asyncio.connectionr	   Úredis.asyncio.multidb.databaser
   Úredis.connectionr   Úredis.multidb.databaser   r9   r?   rP   rk   rS   ri   rQ   rR   r<   r=   r\   r^   r`   r‰   rŠ   r‹   r:   r_   Ú$REDIS_CLIENT_CONNECTION_CLOSE_REASONÚ$REDIS_CLIENT_CONNECTION_NOTIFICATIONrT   rU   rs   rt   ru   rm   rl   r{   r|   r�   r‚   r   r   r    r&   r,   r2   r>   r¢   rˆ   r   r   r   Ú<module>r°      sb  ðñõ ß <Õ <ã áÝ7Ý<Ý8Ý3ð €	Ø€Ø'Ð Ø3Ð Ø5Ð ð €
ð .Ð Ø'Ð ð "€Ø€ð "BÐ Ø9Ð Ø7Ð ð #DÐ Ø ?Ð Ø=Ð ð .Ð Ø!AÐ Ø'MÐ $Ø'MÐ $Ø(OÐ %Ø"CÐ Ø(OÐ %Ø;Ð Ø;Ð Ø<Ð Ø<Ð Ø5Ð Ø;Ð Ø3Ð Ø3Ð ô�dô ô
�dô ô
�ô ô
"�ô "ô
˜ô ÷
`@ñ `@ðF	 ˜ÐIÑJð  Èsó  ð<%˜%Ð ?Ñ@ô %r   