
    ng\je5                        S r SSKJr  SSKJrJrJrJrJr  SSK	r	\(       a  SSK
Jr  SSKJr  SSKJr  SSKJr  S	rS
rSrSrSrSrSrSrSrSrSrSrSrSrSr Sr!Sr"Sr#Sr$Sr%Sr&Sr'Sr(S r)S!r*S"r+S#r,S$r-S%r.S&r/S'r0 " S( S)\5      r1 " S* S+\5      r2 " S, S-\5      r3 " S. S/\5      r4 " S0 S1\5      r5 " S2 S35      r6S4\S5   S6\74S7 jr8S8\S9   4S: jr9g);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                       \ rS rSrSrSrSrg)ConnectionStateC   idleused N)__name__
__module____qualname____firstlineno__IDLEUSED__static_attributes__r       Y/home/edenadmin/noVNC/venv/lib/python3.13/site-packages/redis/observability/attributes.pyr   r   C   s    DDr   r   c                       \ rS rSrSrSrSrg)PubSubDirectionH   publishreceiver   N)r   r   r   r   PUBLISHRECEIVEr   r   r   r   r   r   H   s    GGr   r   c                       \ rS rSrSrSrSrg)	CSCResultM   hitmissr   N)r   r   r   r   HITMISSr   r   r   r   r$   r$   M   s    
CDr   r$   c                       \ rS rSrSrSrSrg)	CSCReasonR   fullinvalidationr   N)r   r   r   r   FULLINVALIDATIONr   r   r   r   r+   r+   R   s    D!Lr   r+   c                       \ rS rSrSrSrSrg)GeoFailoverReasonW   	automaticmanualr   N)r   r   r   r   	AUTOMATICMANUALr   r   r   r   r2   r2   W   s    IFr   r2   c                      \ rS rSrSr\   S*S\\   S\\   S\\   S\	\\
4   4S jj5       r\       S+S	\\\\4      S
\\   S\\   S\\   S\\   S\\   S\\   S\	\\
4   4S jj5       r\    S,S\\   S\\   S\\   S\\   S\	\\
4   4
S jj5       r\  S-S\\   S\\   S\	\\
4   4S jj5       r\  S-S\S\\   S\\   S\	\\
4   4S jj5       r\   S*S\\   S\\   S\\   S\	\\
4   4S  jj5       r\   S*S\\   S!\\   S"\\   S\	\\
4   4S# jj5       r\S$\S%   S&\S%   S"\S\	\\
4   4S' j5       r\ S.S\S\S\S\4S( jj5       rS)rg)/AttributeBuilder\   zQ
Helper class to build OTel semantic convention attributes for Redis operations.
Nserver_addressserver_portdb_namespacereturnc                     [         S[        S[        R                   30nU b  X[        '   Ub  X[
        '   Ub  [        U5      U[        '   U$ )z
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_LIBRARYr@   __version__SERVER_ADDRESSSERVER_PORTstrDB_NAMESPACE)r;   r<   r=   attrss       r   build_base_attributes&AttributeBuilder.build_base_attributesa   s[    $ w Ju/@/@.A"B!

 %$2.!"!,+#"%l"3E,r   command_name
batch_sizenetwork_peer_addressnetwork_peer_portstored_procedure_nameretry_attemptsis_blockingc                    0 nU b<  [        U [        5      (       a  U R                  SSS9n U R                  5       U[        '   Ub  X'[
        '   Ub  X7[        '   Ub  XG[        '   Ub  US:  a  XW[        '   Ub  Xg[        '   U$ )a  
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)rK   rL   rM   rN   rO   rP   rQ   rH   s           r   build_operation_attributes+AttributeBuilder.build_operation_attributes   s    2 !##,..+22792M'3'9'9';E#$+*>&'('8#$ ,.C*+%.1*<;I78"5@12r   	pool_nameconnection_stateconnection_name	is_pubsubc                     [         R                  5       nU b  X[        '   Ub  UR                  U[        '   Ub  X4[
        '   Ub  X$[        '   U$ )a1  
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
)r9   rI   DB_CLIENT_CONNECTION_POOL_NAMEvalueDB_CLIENT_CONNECTION_STATEREDIS_CLIENT_CONNECTION_PUBSUBDB_CLIENT_CONNECTION_NAME)ra   rb   rc   rd   rH   s        r   build_connection_attributes,AttributeBuilder.build_connection_attributes   s[    & !1 F F H 4=01'0@0F0FE,- 4=01&/>+,r   
error_typeis_internalc                 `   0 nU b  U R                   R                  U[        '   [        U S5      (       a!  U R                  b  U R                  U[
        '   O	SU[
        '   [        U S5      (       a+  U R                  b  U R                  R                  U[        '   O	SU[        '   Ub  X[        '   U$ )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errorrm   other)
	__class__r   
ERROR_TYPEhasattrrp   DB_RESPONSE_STATUS_CODErm   rg   REDIS_CLIENT_ERROR_CATEGORYREDIS_CLIENT_ERROR_INTERNAL)rm   rn   rH   s      r   build_error_attributes'AttributeBuilder.build_error_attributes   s     !#! * 4 4 = =E* 
M22**61;1G1G-.18-.z<00Z5J5J5V5?5J5J5P5P125<12"1<-.r   	directionchannelshardedc                     [         R                  5       nU R                  U[        '   Ub  X[        '   Ub  X#[
        '   U$ )z
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
)r9   rI   rg   %REDIS_CLIENT_PUBSUB_MESSAGE_DIRECTIONREDIS_CLIENT_PUBSUB_CHANNELREDIS_CLIENT_PUBSUB_SHARDED)r{   r|   r}   rH   s       r   build_pubsub_message_attributes0AttributeBuilder.build_pubsub_message_attributes   sD    " !1 F F H7@3418-.18-.r   stream_nameconsumer_groupconsumer_namec                 Z    [         R                  5       nU b  X[        '   Ub  X[        '   U$ )z
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
)r9   rI   REDIS_CLIENT_STREAM_NAMEREDIS_CLIENT_CONSUMER_GROUP)r   r   r   rH   s       r   build_streaming_attributes+AttributeBuilder.build_streaming_attributes  s5    " !1 F F H".9*+%1?-.r   resultreasonc                     [         R                  5       nU b  X[        '   Ub  UR                  U[        '   Ub  UR                  U[
        '   U$ )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
)r9   rI   rf   rg   REDIS_CLIENT_CSC_RESULTREDIS_CLIENT_CSC_REASON)ra   r   r   rH   s       r   build_csc_attributes%AttributeBuilder.build_csc_attributes4  sP    " !1 F F H 4=01-3\\E)*-3\\E)*r   	fail_fromr   r
   fail_toc                     [         R                  5       n[        U 5      U[        '   [        U5      U[        '   UR
                  U[        '   U$ )z
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
)r9   rI   get_db_nameDB_CLIENT_GEOFAILOVER_FAIL_FROMDB_CLIENT_GEOFAILOVER_FAIL_TOrg   DB_CLIENT_GEOFAILOVER_REASON)r   r   r   rH   s       r   build_geo_failover_attributes.AttributeBuilder.build_geo_failover_attributesR  sF    " !1 F F H1<Y1G-./:7/C+,.4ll*+r   c                     U  SU SU 3$ )z
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   )r;   r<   r=   s      r   build_pool_name AttributeBuilder.build_pool_namek  s    " !!;-q??r   r   )NNN)NNNNNNN)NNNN)NN)r   )r   r   r   r   __doc__staticmethodr   rF   intr   r   rI   r   rV   boolr_   r   rk   	Exceptionry   r   r   r   r$   r+   r   r2   r   r   r   r   r   r   r9   r9   \   s:    (,%)&* c] sm 
c3h	 @ 48$(.2+//3(,&*/uS%Z01/SM/ 'sm/ $C=	/
  (}/ !/ d^/ 
c3h/ /b #'6:)-$(	 C= "?3  "#  D>	 
 
c3h   D *.&*#Y'#d^# 
c3h# #J  "&"&"# $ 
c3h	 6 %)(,'+c]   } 
c3h	 4 #'&*&*C=# # 
c3h	 : 8967 " 
c3h	 0  @@@ @ 
	@ @r   r9   pool)r   r	   r>   c                     U R                   R                  SS5      nU R                   R                  SS5      n[        U SS5      nU(       a
  U SU SU 3$ U SU 3$ )	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    $ !!%%fi8D!!%%fd3D dJ+Gqay))qr   databaser   c                     U R                   R                  5       S   nU R                   R                  5       S   nU R                  nU SU SU 3$ )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26:D??0026:D__FV1TF!F8$$r   ):r   enumr   typingr   r   r   r   r   r@   redis.asyncio.connectionr	   redis.asyncio.multidb.databaser
   redis.connectionr   redis.multidb.databaser   rA   rG   rY   rv   r\   rt   rZ   r[   rD   rE   rf   rh   rj   r   r   r   rB   ri   $REDIS_CLIENT_CONNECTION_CLOSE_REASON$REDIS_CLIENT_CONNECTION_NOTIFICATIONr]   r^   r   r   r   rx   rw   r   r   r   r   r   r   r$   r+   r2   r9   rF   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   