o
    #fx,                     @   s  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dG dd dZedddZeeegee f eee edf f Z G dd deZ!G dd deee Z"G dd de"e Z#G dd de!Z$G dd de!Z%G dd de$Z&G dd de&Z'G d d! d!e"e& e&Z(G d"d# d#e$Z)G d$d% d%e)Z*G d&d' d'e"e) e)Z+G d(d) d)e%Z,G d*d+ d+e,Z-G d,d- d-e#e, e,Z.G d.d/ d/e%Z/G d0d1 d1e/Z0G d2d3 d3e#e/ e/Z1G d4d5 d5e$Z2G d6d7 d7e2Z3G d8d9 d9e"e2 e2Z4G d:d; d;e%Z5G d<d= d=e5Z6G d>d? d?e#e5 e5Z7dS )@    )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                   @   s   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)__name__
__module____qualname____doc__r   float__annotations__ r   r   f/home/ubuntu/dev/venv/lib/python3.10/site-packages/mysql/opentelemetry/metrics/_internal/instrument.pyr   -   s   
 r   InstrumentT
Instrument)boundNc                   @   s^   e Zd ZdZe		ddedededdfdd	Zededededeee	e f fd
dZ
dS )r   z7Abstract class that serves as base for all instruments. nameunitdescriptionreturnNc                 C      d S Nr   selfr"   r#   r$   r   r   r   __init__C   s   zInstrument.__init__c                 C   sp   i }t | dur| |d< nd|d< |du rd}t|dur$||d< nd|d< |du r2d|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#   r$   )_name_regex	fullmatch_unit_regex)r"   r#   r$   resultr   r   r   _check_name_unit_descriptionL   s   

z'Instrument._check_name_unit_descriptionr!   r!   )r   r   r   r   r   strr*   staticmethodr   r   r/   r   r   r   r   r   @   s0    c                	   @   sL   e Zd Z		ddedededdfddZdddZed	d
defddZdS )_ProxyInstrumentr!   r"   r#   r$   r%   Nc                 C   s   || _ || _|| _d | _d S r'   )_name_unit_description_real_instrumentr(   r   r   r   r*   q   s   
z_ProxyInstrument.__init__metermetrics.Meterc                 C   s   |  || _dS )z;Called when a real meter is set on the creating _ProxyMeterN)_create_real_instrumentr7   r)   r8   r   r   r   on_meter_set|   s   z_ProxyInstrument.on_meter_setc                 C   s   dS )z:Create an instance of the real instrument. Implement this.Nr   r;   r   r   r   r:      s    z(_ProxyInstrument._create_real_instrumentr0   )r8   r9   r%   N)	r   r   r   r1   r*   r<   r   r   r:   r   r   r   r   r3   p   s    

r3   c                       sB   e Zd Z			d
dedeee  dededdf
 fdd	Z  ZS )_ProxyAsynchronousInstrumentNr!   r"   	callbacksr#   r$   r%   c                    s   t  ||| || _d S r'   )superr*   
_callbacksr)   r"   r>   r#   r$   	__class__r   r   r*      s   
z%_ProxyAsynchronousInstrument.__init__Nr!   r!   )	r   r   r   r1   r   r   	CallbackTr*   __classcell__r   r   rB   r   r=      s    
r=   c                   @      e Zd ZdZdS )Synchronousz*Base class for all synchronous instrumentsNr   r   r   r   r   r   r   r   rH          rH   c                       sJ   e Zd ZdZe			ddedeee  dededdf
 fd	d
Z	  Z
S )Asynchronousz+Base class for all asynchronous instrumentsNr!   r"   r>   r#   r$   r%   c                    s   t  j|||d d S N)r#   r$   r?   r*   rA   rB   r   r   r*      s   zAsynchronous.__init__rD   )r   r   r   r   r   r1   r   r   rE   r*   rF   r   r   rB   r   rK      s"    
rK   c                   @   :   e Zd ZdZe	ddeeef dee	 ddfddZ
dS )	CounterzOA Counter is a synchronous `Instrument` which supports non-negative increments.Namount
attributesr%   c                 C   r&   r'   r   r)   rP   rQ   r   r   r   add      zCounter.addr'   r   r   r   r   r   r   intr   r   r   rS   r   r   r   r   rO          
rO   c                	       b   e Zd ZdZ		ddedededdf fdd	Z	dd
eeef de	e
 ddf fddZ  ZS )NoOpCounterz"No-op implementation of `Counter`.r!   r"   r#   r$   r%   Nc                       t  j|||d d S rL   rM   r(   rB   r   r   r*         zNoOpCounter.__init__rP   rQ   c                       t  j||dS N)rQ   r?   rS   rR   rB   r   r   rS         zNoOpCounter.addr0   r'   r   r   r   r   r1   r*   r   rV   r   r   r   rS   rF   r   r   rB   r   rY      *    
rY   c                   @   D   e Zd Z	ddeeef dee ddfddZddde	fd	d
Z
dS )_ProxyCounterNrP   rQ   r%   c                 C      | j r| j || d S d S r'   r7   rS   rR   r   r   r   rS         z_ProxyCounter.addr8   r9   c                 C      | | j| j| jS r'   )create_counterr4   r5   r6   r;   r   r   r   r:         z%_ProxyCounter._create_real_instrumentr'   )r   r   r   r   rV   r   r   r   rS   rO   r:   r   r   r   r   rc          

rc   c                   @   rN   )	UpDownCounterzXAn UpDownCounter is a synchronous `Instrument` which supports increments and decrements.NrP   rQ   r%   c                 C   r&   r'   r   rR   r   r   r   rS      rT   zUpDownCounter.addr'   rU   r   r   r   r   rk      rW   rk   c                	       rX   )NoOpUpDownCounterz(No-op implementation of `UpDownCounter`.r!   r"   r#   r$   r%   Nc                    rZ   rL   rM   r(   rB   r   r   r*      r[   zNoOpUpDownCounter.__init__rP   rQ   c                    r\   r]   r^   rR   rB   r   r   rS      r_   zNoOpUpDownCounter.addr0   r'   r`   r   r   rB   r   rl      ra   rl   c                   @   rb   )_ProxyUpDownCounterNrP   rQ   r%   c                 C   rd   r'   re   rR   r   r   r   rS      rf   z_ProxyUpDownCounter.addr8   r9   c                 C   rg   r'   )create_up_down_counterr4   r5   r6   r;   r   r   r   r:      ri   z+_ProxyUpDownCounter._create_real_instrumentr'   )r   r   r   r   rV   r   r   r   rS   rk   r:   r   r   r   r   rm      rj   rm   c                   @   rG   )ObservableCounterzAn ObservableCounter is an asynchronous `Instrument` which reports monotonically
    increasing value(s) when the instrument is being observed.
    NrI   r   r   r   r   ro      rJ   ro   c                       F   e Zd ZdZ			ddedeee  dededdf
 fd	d
Z  Z	S )NoOpObservableCounterz,No-op implementation of `ObservableCounter`.Nr!   r"   r>   r#   r$   r%   c                       t  j||||d d S rL   rM   rA   rB   r   r   r*        zNoOpObservableCounter.__init__rD   
r   r   r   r   r1   r   r   rE   r*   rF   r   r   rB   r   rq          
rq   c                   @      e Zd ZdddefddZdS )_ProxyObservableCounterr8   r9   r%   c                 C      | | j| j| j| jS r'   )create_observable_counterr4   r@   r5   r6   r;   r   r   r   r:        z/_ProxyObservableCounter._create_real_instrumentN)r   r   r   ro   r:   r   r   r   r   rw     s    rw   c                   @   rG   )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.
    NrI   r   r   r   r   r{     rJ   r{   c                       rp   )NoOpObservableUpDownCounterz2No-op implementation of `ObservableUpDownCounter`.Nr!   r"   r>   r#   r$   r%   c                    rr   rL   rM   rA   rB   r   r   r*   %  rs   z$NoOpObservableUpDownCounter.__init__rD   rt   r   r   rB   r   r|   "  ru   r|   c                   @   rv   )_ProxyObservableUpDownCounterr8   r9   r%   c                 C   rx   r'   )!create_observable_up_down_counterr4   r@   r5   r6   r;   r   r   r   r:   3  s   z5_ProxyObservableUpDownCounter._create_real_instrumentN)r   r   r   r{   r:   r   r   r   r   r}   /  s    r}   c                   @   rN   )		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.
    NrP   rQ   r%   c                 C   r&   r'   r   rR   r   r   r   recordA  rT   zHistogram.recordr'   )r   r   r   r   r   r   rV   r   r   r   r   r   r   r   r   r   ;  s    
r   c                	       rX   )NoOpHistogramz$No-op implementation of `Histogram`.r!   r"   r#   r$   r%   Nc                    rZ   rL   rM   r(   rB   r   r   r*   M  r[   zNoOpHistogram.__init__rP   rQ   c                    r\   r]   )r?   r   rR   rB   r   r   r   U  r_   zNoOpHistogram.recordr0   r'   )r   r   r   r   r1   r*   r   rV   r   r   r   r   rF   r   r   rB   r   r   J  ra   r   c                   @   rb   )_ProxyHistogramNrP   rQ   r%   c                 C   rd   r'   )r7   r   rR   r   r   r   r   ^  rf   z_ProxyHistogram.recordr8   r9   c                 C   rg   r'   )create_histogramr4   r5   r6   r;   r   r   r   r:   f  ri   z'_ProxyHistogram._create_real_instrumentr'   )r   r   r   r   rV   r   r   r   r   r   r:   r   r   r   r   r   ]  rj   r   c                   @   rG   )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.
    NrI   r   r   r   r   r   j  rJ   r   c                       rp   )NoOpObservableGaugez*No-op implementation of `ObservableGauge`.Nr!   r"   r>   r#   r$   r%   c                    rr   rL   rM   rA   rB   r   r   r*   t  rs   zNoOpObservableGauge.__init__rD   rt   r   r   rB   r   r   q  ru   r   c                   @   rv   )_ProxyObservableGauger8   r9   r%   c                 C   rx   r'   )create_observable_gauger4   r@   r5   r6   r;   r   r   r   r:     rz   z-_ProxyObservableGauge._create_real_instrumentN)r   r   r   r   r:   r   r   r   r   r   ~  s    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   _loggerr+   r-   r   r   rE   r   r3   r=   rH   rK   rO   rY   rc   rk   rl   rm   ro   rq   rw   r{   r|   r}   r   r   r   r   r   r   r   r   r   r   <module>   sd   ,0
	

