
    G)fx,                     b   d dl mZmZ d dlmZ d dlmZ d dlmZ	 d dl
mZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ  ee      Z e	d	      Z e	d
      Z ed       G d d             Z edd      Zeeegee   f   eee   edf   f   Z  G d de      Z! G d deee         Z" G d de"e         Z# G d de!      Z$ G d de!      Z% G d de$      Z& G d de&      Z' G d  d!e"e&   e&      Z( G d" d#e$      Z) G d$ d%e)      Z* G d& d'e"e)   e)      Z+ G d( d)e%      Z, G d* d+e,      Z- G d, d-e#e,   e,      Z. G d. d/e%      Z/ G d0 d1e/      Z0 G d2 d3e#e/   e/      Z1 G d4 d5e$      Z2 G d6 d7e2      Z3 G d8 d9e"e2   e2      Z4 G d: d;e%      Z5 G d< d=e5      Z6 G d> d?e#e5   e5      Z7y)@    )ABCabstractmethod)	dataclass)	getLogger)compile)	CallableDict	GeneratorGenericIterableOptionalSequenceTypeVarUnion)metrics)Observation)
Attributesz[a-zA-Z][-_.a-zA-Z0-9]{0,62}z[\x00-\x7F]{0,63}T)frozenc                        e Zd ZU dZdZeed<   y)CallbackOptionszOptions for the callback

    Args:
        timeout_millis: Timeout for the callback's execution. If the callback does asynchronous
            work (e.g. HTTP requests), it should respect this timeout.
    i'  timeout_millisN)__name__
__module____qualname____doc__r   float__annotations__     m/var/www/html/flask-app/venv/lib/python3.12/site-packages/mysql/opentelemetry/metrics/_internal/instrument.pyr   r   -   s     #NE"r   r   InstrumentT
Instrument)boundNc                   j    e Zd ZdZe	 	 d	dedededdfd       Zededededeee	e   f   fd       Z
y)
r"   z7Abstract class that serves as base for all instruments.nameunitdescriptionreturnNc                      y Nr   selfr%   r&   r'   s       r    __init__zInstrument.__init__C   s     	r   c                     i }t         j                  |       | |d<   nd|d<   |d}t        j                  |      ||d<   nd|d<   |d|d<   |S ||d<   |S )as  
        Checks the following instrument name, unit and description for
        compliance with the spec.

        Returns a dict with keys "name", "unit" and "description", the
        corresponding values will be the checked strings or `None` if the value
        is invalid. If valid, the checked strings should be used instead of the
        original values.
        Nr%    r&   r'   )_name_regex	fullmatch_unit_regex)r%   r&   r'   results       r    _check_name_unit_descriptionz'Instrument._check_name_unit_descriptionL   s     ,.  &2!F6N!F6N<D  &2!F6N!F6N$&F=!  %0F=!r   r/   r/   )r   r   r   r   r   strr-   staticmethodr	   r   r4   r   r   r    r"   r"   @   s    A 	  	
 
     +. 	c8C= 	!   r   c            	       L    e Zd Z	 	 ddedededdfdZdd	Zedddefd
       Zy)_ProxyInstrumentr%   r&   r'   r(   Nc                 <    || _         || _        || _        d | _        y r*   )_name_unit_description_real_instrumentr+   s       r    r-   z_ProxyInstrument.__init__q   s"     

'7;r   metermetrics.Meterc                 0    | j                  |      | _        y)z;Called when a real meter is set on the creating _ProxyMeterN)_create_real_instrumentr>   r,   r?   s     r    on_meter_setz_ProxyInstrument.on_meter_set|   s     !% < <U Cr   c                      y)z:Create an instance of the real instrument. Implement this.Nr   rC   s     r    rB   z(_ProxyInstrument._create_real_instrument   s    r   r5   )r?   r@   r(   N)	r   r   r   r6   r-   rD   r   r!   rB   r   r   r    r9   r9   p   sa     		<	< 	< 		<
 
	<D I_ I I Ir   r9   c                   H     e Zd Z	 	 	 ddedeee      dededdf
 fdZ xZS )	_ProxyAsynchronousInstrumentNr%   	callbacksr&   r'   r(   c                 6    t         |   |||       || _        y r*   )superr-   
_callbacksr,   r%   rH   r&   r'   	__class__s        r    r-   z%_ProxyAsynchronousInstrument.__init__   s     	t[1#r   Nr/   r/   )	r   r   r   r6   r   r   	CallbackTr-   __classcell__rM   s   @r    rG   rG      sR     48$$ HY/0$ 	$
 $ 
$ $r   rG   c                       e Zd ZdZy)Synchronousz*Base class for all synchronous instrumentsNr   r   r   r   r   r   r    rS   rS      s    4r   rS   c                   V     e Zd ZdZe	 	 	 d	dedeee      dededdf
 fd       Z	 xZ
S )
Asynchronousz+Base class for all asynchronous instrumentsNr%   rH   r&   r'   r(   c                 *    t         |   |||       y N)r&   r'   rJ   r-   rL   s        r    r-   zAsynchronous.__init__   s     	DkBr   rN   )r   r   r   r   r   r6   r   r   rO   r-   rP   rQ   s   @r    rV   rV      sd    5 48CC HY/0C 	C
 C 
C Cr   rV   c                   B    e Zd ZdZe	 ddeeef   dee	   ddfd       Z
y)CounterzOA Counter is a synchronous `Instrument` which supports non-negative increments.Namount
attributesr(   c                      y r*   r   r,   r\   r]   s      r    addzCounter.add        	r   r*   r   r   r   r   r   r   intr   r   r   r`   r   r   r    r[   r[      sF    Y ,0c5j! Z( 
	 r   r[   c            	       f     e Zd ZdZ	 	 ddedededdf fdZ	 ddeeef   d	e	e
   ddf fd
Z xZS )NoOpCounterz"No-op implementation of `Counter`.r%   r&   r'   r(   Nc                 *    t         |   |||       y rX   rY   r,   r%   r&   r'   rM   s       r    r-   zNoOpCounter.__init__        	DkBr   r\   r]   c                 &    t         |   ||      S N)r]   rJ   r`   r,   r\   r]   rM   s      r    r`   zNoOpCounter.add       
 w{6j{99r   r5   r*   r   r   r   r   r6   r-   r   rc   r   r   r   r`   rP   rQ   s   @r    re   re      sw    ,
 	CC C 	C
 
C ,0:c5j!: Z(: 
	: :r   re   c                   D    e Zd Z	 d	deeef   dee   ddfdZddde	fdZ
y)
_ProxyCounterNr\   r]   r(   c                 V    | j                   r| j                   j                  ||       y y r*   r>   r`   r_   s      r    r`   z_ProxyCounter.add   (    
   !!%%fj9 !r   r?   r@   c                 d    |j                  | j                  | j                  | j                        S r*   )create_counterr;   r<   r=   rC   s     r    rB   z%_ProxyCounter._create_real_instrument   s%    ##DJJ

D<M<MNNr   r*   )r   r   r   r   rc   r   r   r   r`   r[   rB   r   r   r    rp   rp      sL     ,0:c5j!: Z(: 
	:O_ O Or   rp   c                   B    e Zd ZdZe	 ddeeef   dee	   ddfd       Z
y)UpDownCounterzXAn UpDownCounter is a synchronous `Instrument` which supports increments and decrements.Nr\   r]   r(   c                      y r*   r   r_   s      r    r`   zUpDownCounter.add   ra   r   r*   rb   r   r   r    rw   rw      sF    b ,0c5j! Z( 
	 r   rw   c            	       f     e Zd ZdZ	 	 ddedededdf fdZ	 ddeeef   d	e	e
   ddf fd
Z xZS )NoOpUpDownCounterz(No-op implementation of `UpDownCounter`.r%   r&   r'   r(   Nc                 *    t         |   |||       y rX   rY   rg   s       r    r-   zNoOpUpDownCounter.__init__   rh   r   r\   r]   c                 &    t         |   ||      S rj   rk   rl   s      r    r`   zNoOpUpDownCounter.add   rm   r   r5   r*   rn   rQ   s   @r    rz   rz      sw    2
 	CC C 	C
 
C ,0:c5j!: Z(: 
	: :r   rz   c                   D    e Zd Z	 d	deeef   dee   ddfdZddde	fdZ
y)
_ProxyUpDownCounterNr\   r]   r(   c                 V    | j                   r| j                   j                  ||       y y r*   rr   r_   s      r    r`   z_ProxyUpDownCounter.add   rs   r   r?   r@   c                 d    |j                  | j                  | j                  | j                        S r*   )create_up_down_counterr;   r<   r=   rC   s     r    rB   z+_ProxyUpDownCounter._create_real_instrument   s%    ++DJJ

DDUDUVVr   r*   )r   r   r   r   rc   r   r   r   r`   rw   rB   r   r   r    r~   r~      sL     ,0:c5j!: Z(: 
	:W_ W Wr   r~   c                       e Zd ZdZy)ObservableCounterzAn ObservableCounter is an asynchronous `Instrument` which reports monotonically
    increasing value(s) when the instrument is being observed.
    NrT   r   r   r    r   r      s    r   r   c                   L     e Zd ZdZ	 	 	 d	dedeee      dededdf
 fdZ xZ	S )
NoOpObservableCounterz,No-op implementation of `ObservableCounter`.Nr%   rH   r&   r'   r(   c                 ,    t         |   ||||       y rX   rY   rL   s        r    r-   zNoOpObservableCounter.__init__       	ytMr   rN   
r   r   r   r   r6   r   r   rO   r-   rP   rQ   s   @r    r   r     s\    6
 48NN HY/0N 	N
 N 
N Nr   r   c                       e Zd ZdddefdZy)_ProxyObservableCounterr?   r@   r(   c                 z    |j                  | j                  | j                  | j                  | j                        S r*   )create_observable_counterr;   rK   r<   r=   rC   s     r    rB   z/_ProxyObservableCounter._create_real_instrument  s0    ..JJT5F5F
 	
r   N)r   r   r   r   rB   r   r   r    r   r     s    
_ 
AR 
r   r   c                       e Zd ZdZy)ObservableUpDownCountera  An ObservableUpDownCounter is an asynchronous `Instrument` which reports additive value(s) (e.g.
    the process heap size - it makes sense to report the heap size from multiple processes and sum them
    up, so we get the total heap usage) when the instrument is being observed.
    NrT   r   r   r    r   r         r   r   c                   L     e Zd ZdZ	 	 	 d	dedeee      dededdf
 fdZ xZ	S )
NoOpObservableUpDownCounterz2No-op implementation of `ObservableUpDownCounter`.Nr%   rH   r&   r'   r(   c                 ,    t         |   ||||       y rX   rY   rL   s        r    r-   z$NoOpObservableUpDownCounter.__init__%  r   r   rN   r   rQ   s   @r    r   r   "  s\    <
 48NN HY/0N 	N
 N 
N Nr   r   c                       e Zd ZdddefdZy)_ProxyObservableUpDownCounterr?   r@   r(   c                 z    |j                  | j                  | j                  | j                  | j                        S r*   )!create_observable_up_down_counterr;   rK   r<   r=   rC   s     r    rB   z5_ProxyObservableUpDownCounter._create_real_instrument3  s2     66JJT5F5F
 	
r   N)r   r   r   r   rB   r   r   r    r   r   /  s    
$
	 
r   r   c                   B    e Zd ZdZe	 ddeeef   dee	   ddfd       Z
y)	HistogramzHistogram is a synchronous `Instrument` which can be used to report arbitrary values
    that are likely to be statistically meaningful. It is intended for statistics such as
    histograms, summaries, and percentile.
    Nr\   r]   r(   c                      y r*   r   r_   s      r    recordzHistogram.recordA  ra   r   r*   )r   r   r   r   r   r   rc   r   r   r   r   r   r   r    r   r   ;  sJ    
  ,0c5j! Z( 
	 r   r   c            	       f     e Zd ZdZ	 	 ddedededdf fdZ	 ddeeef   d	e	e
   ddf fd
Z xZS )NoOpHistogramz$No-op implementation of `Histogram`.r%   r&   r'   r(   Nc                 *    t         |   |||       y rX   rY   rg   s       r    r-   zNoOpHistogram.__init__M  rh   r   r\   r]   c                 &    t         |   ||      S rj   )rJ   r   rl   s      r    r   zNoOpHistogram.recordU  s    
 w~f~<<r   r5   r*   )r   r   r   r   r6   r-   r   rc   r   r   r   r   rP   rQ   s   @r    r   r   J  sw    .
 	CC C 	C
 
C ,0=c5j!= Z(= 
	= =r   r   c                   D    e Zd Z	 d	deeef   dee   ddfdZddde	fdZ
y)
_ProxyHistogramNr\   r]   r(   c                 V    | j                   r| j                   j                  ||       y y r*   )r>   r   r_   s      r    r   z_ProxyHistogram.record^  s(    
   !!((< !r   r?   r@   c                 d    |j                  | j                  | j                  | j                        S r*   )create_histogramr;   r<   r=   rC   s     r    rB   z'_ProxyHistogram._create_real_instrumentf  s%    %%djj$**d>O>OPPr   r*   )r   r   r   r   rc   r   r   r   r   r   rB   r   r   r    r   r   ]  sL     ,0=c5j!= Z(= 
	=Q_ Q Qr   r   c                       e Zd ZdZy)ObservableGaugezAsynchronous Gauge is an asynchronous `Instrument` which reports non-additive value(s) (e.g.
    the room temperature - it makes no sense to report the temperature value from multiple rooms
    and sum them up) when the instrument is being observed.
    NrT   r   r   r    r   r   j  r   r   r   c                   L     e Zd ZdZ	 	 	 d	dedeee      dededdf
 fdZ xZ	S )
NoOpObservableGaugez*No-op implementation of `ObservableGauge`.Nr%   rH   r&   r'   r(   c                 ,    t         |   ||||       y rX   rY   rL   s        r    r-   zNoOpObservableGauge.__init__t  r   r   rN   r   rQ   s   @r    r   r   q  s\    4
 48NN HY/0N 	N
 N 
N Nr   r   c                       e Zd ZdddefdZy)_ProxyObservableGauger?   r@   r(   c                 z    |j                  | j                  | j                  | j                  | j                        S r*   )create_observable_gauger;   rK   r<   r=   rC   s     r    rB   z-_ProxyObservableGauge._create_real_instrument  s0    ,,JJT5F5F
 	
r   N)r   r   r   r   rB   r   r   r    r   r   ~  s    
_ 
 
r   r   )8abcr   r   dataclassesr   loggingr   rer   
re_compiletypingr   r	   r
   r   r   r   r   r   r   mysql.opentelemetryr   1mysql.opentelemetry.metrics._internal.observationr   mysql.opentelemetry.util.typesr   r   _loggerr0   r2   r   r!   rO   r"   r9   rG   rS   rV   r[   re   rp   rw   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    <module>r      s  $ $ !  $
 
 
 ( I 5
H
89-. $# # # m<8o 556h{#_d:;=	- -`IsGK0 I2	$#3K#@ 	$5* 5C: C	k 	:' :&
O$W-w 
O	K 	: :&
W*=9= 
W 
N- 
N
 !235F
l 
N"9 
N	
 !89	
 =I =&
Q&y19 
Ql 
N/ 
N
 1
r   