
    Xjk?                        d dl mZmZ d dlmZmZ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 d dl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           G d d                      Z edd          Z eegee         f         eee         edf         z  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 d0 d1e$e-         e-          Z/ G d2 d3e&          Z0 G d4 d5e0          Z1 G d6 d7e$e0         e0          Z2 G d8 d9e%          Z3 G d: d;e3          Z4 G d< d=e#e3         e3          Z5 G d> d?e&          Z6 G d@ dAe6          Z7 G dB dCe$e6         e6          Z8 G dD dEe%          Z9 G dF dGe9          Z: G dH dIe#e9         e9          Z;dS )J    )ABCabstractmethod)Callable	GeneratorIterableSequence)	dataclass)	getLogger)compile)GenericTypeVar)metrics)Context)Observation)
Attributesz[a-zA-Z][-_./a-zA-Z0-9]{0,254}z[\x00-\x7F]{0,63}T)frozenc                   0    e Zd ZU dZee         dz  ed<   dS )_MetricsHistogramAdvisoryNexplicit_bucket_boundaries)__name__
__module____qualname__r   r   float__annotations__     g/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/opentelemetry/metrics/_internal/instrument.pyr   r      s,         9=$ 6=====r   r   c                   "    e Zd ZU dZdZeed<   dS )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)r   r   r   __doc__r    r   r   r   r   r   r   r   $   s.           #NE"""""r   r   InstrumentT
Instrument)boundNc                   ~    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dz  f         fd	            Z	dS )r#   z7Abstract class that serves as base for all instruments. nameunitdescriptionreturnNc                     d S Nr   selfr'   r(   r)   s       r   __init__zInstrument.__init__;   s	     	r   c                     i }t                               |           | |d<   nd|d<   |d}t                              |          ||d<   nd|d<   |d|d<   n||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(   r)   )_name_regex	fullmatch_unit_regex)r'   r(   r)   results       r   _check_name_unit_descriptionz'Instrument._check_name_unit_descriptionD   s     )+  &&2!F6NN!F6N<D  &&2!F6NN!F6N$&F=!!$/F=!r   r&   r&   )
r   r   r   r!   r   strr/   staticmethoddictr5   r   r   r   r#   r#   8   s        AA 	   	
 
   ^    +. 	c3:o	      \     r   c            	       T    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dS )_ProxyInstrumentr&   r'   r(   r)   r*   Nc                 >    || _         || _        || _        d | _        d S r,   )_name_unit_description_real_instrumentr-   s       r   r/   z_ProxyInstrument.__init__i   s(     

'48r   metermetrics.Meterc                 :    |                      |          | _        dS )z;Called when a real meter is set on the creating _ProxyMeterN)_create_real_instrumentr@   r.   rA   s     r   on_meter_setz_ProxyInstrument.on_meter_sett   s      !% < <U C Cr   c                     dS )z:Create an instance of the real instrument. Implement this.Nr   rE   s     r   rD   z(_ProxyInstrument._create_real_instrument|         r   r6   )rA   rB   r*   N)	r   r   r   r7   r/   rF   r   r"   rD   r   r   r   r;   r;   h   s         		9 	9	9 	9 		9
 
	9 	9 	9 	9D D D D I_ I I I I ^I I Ir   r;   c                   N     e Zd Z	 	 	 d	dedee         dz  dededdf
 fdZ xZS )
_ProxyAsynchronousInstrumentNr&   r'   	callbacksr(   r)   r*   c                 \    t                                          |||           || _        d S r,   )superr/   
_callbacksr.   r'   rK   r(   r)   	__class__s        r   r/   z%_ProxyAsynchronousInstrument.__init__   s,     	t[111#r   Nr&   r&   )r   r   r   r7   r   	CallbackTr/   __classcell__rP   s   @r   rJ   rJ      s         15$ $$ I&-$ 	$
 $ 
$ $ $ $ $ $ $ $ $ $r   rJ   c                       e Zd ZdZdS )Synchronousz*Base class for all synchronous instrumentsNr   r   r   r!   r   r   r   rV   rV      s        4444r   rV   c                   b     e Zd ZdZe	 	 	 d
dedee         dz  dededdf
 fd	            Z xZ	S )Asynchronousz+Base class for all asynchronous instrumentsNr&   r'   rK   r(   r)   r*   c                 P    t                                          |||           d S N)r(   r)   rM   r/   rO   s        r   r/   zAsynchronous.__init__   s*     	DkBBBBBr   rQ   )
r   r   r   r!   r   r7   r   rR   r/   rS   rT   s   @r   rY   rY      s        55 15C CC I&-C 	C
 C 
C C C C C ^C C C C Cr   rY   c            
       R    e Zd ZdZe	 	 ddeez  dedz  dedz  ddfd            Z	dS )	CounterzOA Counter is a synchronous `Instrument` which supports non-negative increments.Namount
attributescontextr*   c                     dS )ak  Records an increment to the counter.

        Args:
            amount: The amount to increment the counter by. Must be non-negative.
            attributes: Optional set of attributes to associate with the measurement.
            context: Optional context to associate with the measurement. If not
                provided, the current context is used.
        Nr   r.   r_   r`   ra   s       r   addzCounter.add   rH   r   NN
r   r   r   r!   r   intr   r   r   rd   r   r   r   r^   r^      sx        YY )-"&	 e % 4	
 
   ^  r   r^   c            	       n     e Zd ZdZ	 	 ddedededdf fdZ	 	 dd	eez  d
edz  de	dz  ddf fdZ
 xZS )NoOpCounterz"No-op implementation of `Counter`.r&   r'   r(   r)   r*   Nc                 P    t                                          |||           d S r[   r\   r.   r'   r(   r)   rP   s       r   r/   zNoOpCounter.__init__   *     	DkBBBBBr   r_   r`   ra   c                 L    t                                          |||          S N)r`   ra   rM   rd   r.   r_   r`   ra   rP   s       r   rd   zNoOpCounter.add   !     ww{{6j'{JJJr   r6   re   r   r   r   r!   r7   r/   rg   r   r   r   rd   rS   rT   s   @r   ri   ri              ,,
 	C CC C 	C
 
C C C C C C )-"&	K KeK %K 4	K
 
K K K K K K K K K Kr   ri   c            	       N    e Zd Z	 	 d
deez  dedz  dedz  ddfdZdddefd	Z	dS )_ProxyCounterNr_   r`   ra   r*   c                 P    | j         r| j                             |||           d S d S r,   r@   rd   rc   s       r   rd   z_ProxyCounter.add   =       	C!%%fj'BBBBB	C 	Cr   rA   rB   c                 N    |                     | j        | j        | j                  S r,   )create_counterr=   r>   r?   rE   s     r   rD   z%_ProxyCounter._create_real_instrument   s*    ##JJ
 
 	
r   re   )
r   r   r   rg   r   r   r   rd   r^   rD   r   r   r   ru   ru      s         )-"&	C CeC %C 4	C
 
C C C C
_ 
 
 
 
 
 
 
r   ru   c            
       R    e Zd ZdZe	 	 ddeez  dedz  dedz  ddfd            Z	dS )	UpDownCounterzXAn UpDownCounter is a synchronous `Instrument` which supports increments and decrements.Nr_   r`   ra   r*   c                     dS )a/  Records an increment or decrement to the counter.

        Unlike `Counter`, the ``amount`` may be negative, allowing the
        instrument to track values that go up and down (e.g. number of
        active requests, queue depth).

        Args:
            amount: The amount to add to the counter. May be positive or negative.
            attributes: Optional set of attributes to associate with the measurement.
            context: Optional context to associate with the measurement. If not
                provided, the current context is used.
        Nr   rc   s       r   rd   zUpDownCounter.add   rH   r   re   rf   r   r   r   r|   r|      sx        bb )-"&	 e % 4	
 
   ^  r   r|   c            	       n     e Zd ZdZ	 	 ddedededdf fdZ	 	 dd	eez  d
edz  de	dz  ddf fdZ
 xZS )NoOpUpDownCounterz(No-op implementation of `UpDownCounter`.r&   r'   r(   r)   r*   Nc                 P    t                                          |||           d S r[   r\   rk   s       r   r/   zNoOpUpDownCounter.__init__   rl   r   r_   r`   ra   c                 L    t                                          |||          S rn   ro   rp   s       r   rd   zNoOpUpDownCounter.add   rq   r   r6   re   rr   rT   s   @r   r   r      s        22
 	C CC C 	C
 
C C C C C C )-"&	K KeK %K 4	K
 
K K K K K K K K K Kr   r   c            	       N    e Zd Z	 	 d
deez  dedz  dedz  ddfdZdddefd	Z	dS )_ProxyUpDownCounterNr_   r`   ra   r*   c                 P    | j         r| j                             |||           d S d S r,   rw   rc   s       r   rd   z_ProxyUpDownCounter.add  rx   r   rA   rB   c                 N    |                     | j        | j        | j                  S r,   )create_up_down_counterr=   r>   r?   rE   s     r   rD   z+_ProxyUpDownCounter._create_real_instrument  s*    ++JJ
 
 	
r   re   )
r   r   r   rg   r   r   r   rd   r|   rD   r   r   r   r   r     s         )-"&	C CeC %C 4	C
 
C C C C
_ 
 
 
 
 
 
 
r   r   c                       e Zd ZdZdS )ObservableCounterzAn ObservableCounter is an asynchronous `Instrument` which reports monotonically
    increasing value(s) when the instrument is being observed.
    NrW   r   r   r   r   r     s           r   r   c                   R     e Zd ZdZ	 	 	 d
dedee         dz  dededdf
 fd	Z xZS )NoOpObservableCounterz,No-op implementation of `ObservableCounter`.Nr&   r'   rK   r(   r)   r*   c                 R    t                                          ||||           d S r[   r\   rO   s        r   r/   zNoOpObservableCounter.__init__   <     	#	 	 	
 	
 	
 	
 	
r   rQ   	r   r   r   r!   r7   r   rR   r/   rS   rT   s   @r   r   r     s        66
 15
 

 I&-
 	

 
 

 
 
 
 
 
 
 
 
 
r   r   c                       e Zd ZdddefdZdS )_ProxyObservableCounterrA   rB   r*   c                 Z    |                     | j        | j        | j        | j                  S r,   )create_observable_counterr=   rN   r>   r?   rE   s     r   rD   z/_ProxyObservableCounter._create_real_instrument2  s1     ..JOJ	
 
 	
r   N)r   r   r   r   rD   r   r   r   r   r   /  s8        
$
	
 
 
 
 
 
r   r   c                       e Zd ZdZdS )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.
    NrW   r   r   r   r   r   =             r   r   c                   R     e Zd ZdZ	 	 	 d
dedee         dz  dededdf
 fd	Z xZS )NoOpObservableUpDownCounterz2No-op implementation of `ObservableUpDownCounter`.Nr&   r'   rK   r(   r)   r*   c                 R    t                                          ||||           d S r[   r\   rO   s        r   r/   z$NoOpObservableUpDownCounter.__init__G  r   r   rQ   r   rT   s   @r   r   r   D  s        <<
 15
 

 I&-
 	

 
 

 
 
 
 
 
 
 
 
 
r   r   c                       e Zd ZdddefdZdS )_ProxyObservableUpDownCounterrA   rB   r*   c                 Z    |                     | j        | j        | j        | j                  S r,   )!create_observable_up_down_counterr=   rN   r>   r?   rE   s     r   rD   z5_ProxyObservableUpDownCounter._create_real_instrumentZ  s1     66JOJ	
 
 	
r   N)r   r   r   r   rD   r   r   r   r   r   V  s8        
$
	 
 
 
 
 
 
r   r   c                       e Zd ZdZe	 	 	 ddedededee         dz  ddf
d	            Ze	 	 dd
e	ez  de
dz  dedz  ddfd            ZdS )	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.
    r&   Nr'   r(   r)   #explicit_bucket_boundaries_advisoryr*   c                     d S r,   r   )r.   r'   r(   r)   r   s        r   r/   zHistogram.__init__k  s	     	r   r_   r`   ra   c                     dS )a  Records a measurement.

        Used to report measurements that are likely to be statistically
        meaningful, such as request durations, payload sizes, or any value
        for which a distribution (e.g. percentiles) is useful.

        Args:
            amount: The measurement to record. Should be non-negative in most
                cases; negative values are only meaningful when the histogram
                is used to track signed deltas.
            attributes: Optional set of attributes to associate with the measurement.
            context: Optional context to associate with the measurement. If not
                provided, the current context is used.
        Nr   rc   s       r   recordzHistogram.recordu  rH   r   r&   r&   Nre   )r   r   r   r!   r   r7   r   r   r/   rg   r   r   r   r   r   r   r   r   e  s         
  FJ   	
 .6e_t-C 
   ^  )-"&	 e % 4	
 
   ^  r   r   c                        e Zd ZdZ	 	 	 ddedededee         dz  ddf
 fd	Z	 	 dd
eez  de	dz  de
dz  ddf fdZ xZS )NoOpHistogramz$No-op implementation of `Histogram`.r&   Nr'   r(   r)   r   r*   c                 R    t                                          ||||           d S )N)r(   r)   r   r\   r.   r'   r(   r)   r   rP   s        r   r/   zNoOpHistogram.__init__  s<     	#0S	 	 	
 	
 	
 	
 	
r   r_   r`   ra   c                 L    t                                          |||          S rn   )rM   r   rp   s       r   r   zNoOpHistogram.record  s!     ww~~fW~MMMr   r   re   )r   r   r   r!   r7   r   r   r/   rg   r   r   r   rS   rT   s   @r   r   r     s        ..
 FJ
 

 
 	

 .6e_t-C
 

 
 
 
 
 
" )-"&	N NeN %N 4	N
 
N N N N N N N N N Nr   r   c                        e Zd Z	 	 	 ddedededee         dz  ddf
 fdZ	 	 dd	eez  d
edz  de	dz  ddfdZ
dddefdZ xZS )_ProxyHistogramr&   Nr'   r(   r)   r   r*   c                 ^    t                                          |||           || _        d S r[   )rM   r/   $_explicit_bucket_boundaries_advisoryr   s        r   r/   z_ProxyHistogram.__init__  s5     	DkBBB/ 	111r   r_   r`   ra   c                 P    | j         r| j                             |||           d S d S r,   )r@   r   rc   s       r   r   z_ProxyHistogram.record  s=       	F!((WEEEEE	F 	Fr   rA   rB   c                 \    |                     | j        | j        | j        | j                  S )N)r   )create_histogramr=   r>   r?   r   rE   s     r   rD   z'_ProxyHistogram._create_real_instrument  s5    %%JJ040Y	 & 
 
 	
r   r   re   )r   r   r   r7   r   r   r/   rg   r   r   r   r   rD   rS   rT   s   @r   r   r     s        FJ

 



 

 	


 .6e_t-C

 


 

 

 

 

 

 )-"&	F FeF %F 4	F
 
F F F F
_ 
 
 
 
 
 
 
 
 
r   r   c                       e Zd ZdZdS )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.
    NrW   r   r   r   r   r     r   r   r   c                   R     e Zd ZdZ	 	 	 d
dedee         dz  dededdf
 fd	Z xZS )NoOpObservableGaugez*No-op implementation of `ObservableGauge`.Nr&   r'   rK   r(   r)   r*   c                 R    t                                          ||||           d S r[   r\   rO   s        r   r/   zNoOpObservableGauge.__init__  r   r   rQ   r   rT   s   @r   r   r     s        44
 15
 

 I&-
 	

 
 

 
 
 
 
 
 
 
 
 
r   r   c                       e Zd ZdddefdZdS )_ProxyObservableGaugerA   rB   r*   c                 Z    |                     | j        | j        | j        | j                  S r,   )create_observable_gauger=   rN   r>   r?   rE   s     r   rD   z-_ProxyObservableGauge._create_real_instrument  s1     ,,JOJ	
 
 	
r   N)r   r   r   r   rD   r   r   r   r   r     s8        
$
	
 
 
 
 
 
r   r   c            
       R    e Zd ZdZe	 	 ddeez  dedz  dedz  ddfd            Z	dS )	GaugezdA Gauge is a synchronous `Instrument` which can be used to record non-additive values as they occur.Nr_   r`   ra   r*   c                     dS )a&  Records the current value of the gauge.

        The gauge reports the last recorded value when observed. It is
        intended for non-additive measurements where only the current
        value matters (e.g. CPU utilisation percentage, room temperature).

        Args:
            amount: The current value to record.
            attributes: Optional set of attributes to associate with the measurement.
            context: Optional context to associate with the measurement. If not
                provided, the current context is used.
        Nr   rc   s       r   setz	Gauge.set  rH   r   re   )
r   r   r   r!   r   rg   r   r   r   r   r   r   r   r   r     sx        nn )-"&	 e % 4	
 
   ^  r   r   c            	       n     e Zd ZdZ	 	 ddedededdf fdZ	 	 dd	eez  d
edz  de	dz  ddf fdZ
 xZS )	NoOpGaugez"No-op implementation of ``Gauge``.r&   r'   r(   r)   r*   Nc                 P    t                                          |||           d S r[   r\   rk   s       r   r/   zNoOpGauge.__init__  rl   r   r_   r`   ra   c                 L    t                                          |||          S rn   )rM   r   rp   s       r   r   zNoOpGauge.set  rq   r   r6   re   )r   r   r   r!   r7   r/   rg   r   r   r   r   rS   rT   s   @r   r   r     rs   r   r   c            	       N    e Zd Z	 	 d
deez  dedz  dedz  ddfdZdddefd	Z	dS )_ProxyGaugeNr_   r`   ra   r*   c                 P    | j         r| j                             |||           d S d S r,   )r@   r   rc   s       r   r   z_ProxyGauge.set  rx   r   rA   rB   c                 N    |                     | j        | j        | j                  S r,   )create_gauger=   r>   r?   rE   s     r   rD   z#_ProxyGauge._create_real_instrument&  s*    !!JJ
 
 	
r   re   )
r   r   r   rg   r   r   r   r   r   rD   r   r   r   r   r     s         )-"&	C CeC %C 4	C
 
C C C C
_ 
 
 
 
 
 
 
r   r   )<abcr   r   collections.abcr   r   r   r   dataclassesr	   loggingr
   rer   
re_compiletypingr   r   opentelemetryr   opentelemetry.contextr   +opentelemetry.metrics._internal.observationr   opentelemetry.util.typesr   r   _loggerr1   r3   r   r   r"   rR   r#   r;   rJ   rV   rY   r^   ri   ru   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s   $ # # # # # # # C C C C C C C C C C C C ! ! ! ! ! !       $ $ $ $ $ $        " ! ! ! ! ! ) ) ) ) ) ) C C C C C C      )H

j:;;j-.. $> > > > > > > > $# # # # # # # # gm<888 o 556%<=> 
- - - - - - - -`I I I I IsGK0 I I I2	$ 	$ 	$ 	$ 	$#3K#@ 	$ 	$ 	$5 5 5 5 5* 5 5 5C C C C C: C C C    k   (K K K K K' K K K(
 
 
 
 
$W-w 
 
 
$    K   0K K K K K K K K(
 
 
 
 
*=9= 
 
 
$       
 
 
 
 
- 
 
 
$
 
 
 
 
 !235F
 
 
    l   
 
 
 
 
"9 
 
 
$
 
 
 
 
 !89
 
 
$ $ $ $ $ $ $ $NN N N N NI N N N4
 
 
 
 
&y19 
 
 
>    l   
 
 
 
 
/ 
 
 
$
 
 
 
 
 1
 
 
    K   0K K K K K K K K(
 
 
 
 
U	
 
 
 
 
r   