
    3i                        % S SK JrJr  S SKJr  S SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJrJrJrJrJrJrJr  S S	KJrJrJrJrJrJrJrJrJ r J!r!  S S
K"J#r#J$r$  S SK%J&r&  S SK'J(r(  S SK)J*r*  S SK+J,r,  S SK-J.r.  S SK/J&r0  S SK/J1r1J2r2J3r3J4r4  S SK/J5r6  S SK/Jr7  S SK8J9r9  \" S\3\25      r:\
" \;5      r< " S S\5      r= " S S\\\:   5      r> " S S\>5      r? " S S\>\4   5      r@ " S S\>\6   5      rASrB\\C   \DS '    " S! S"\>\7   5      rE " S# S$\>\7   5      rF " S% S&\5      rG " S' S(\G5      rH " S) S*\G5      rI " S+ S,\G5      rJ " S- S.\G5      rK " S/ S0\G5      rL " S1 S2\G5      rMg3)4    )ABCabstractmethod)bisect_left)IntEnum)partial)	getLogger)inf)Lock)CallableGenericListOptionalSequenceTypeTypeVar)
AsynchronousCounter	Histogram
InstrumentObservableCounterObservableGaugeObservableUpDownCounterSynchronousUpDownCounter_Gauge)ExemplarExemplarReservoirBuilder)Buckets)Mapping)ExponentMapping)LogarithmMapping)Measurement)ExponentialHistogramDataPointHistogramDataPointNumberDataPointSum)Gauge)r   )
Attributes_DataPointVarTc                   $    \ rS rSrSrSrSrSrSrg)AggregationTemporalityQ   zT
The temporality to use when aggregating data.

Can be one of the following values:
r          N)	__name__
__module____qualname____firstlineno____doc__UNSPECIFIEDDELTA
CUMULATIVE__static_attributes__r/       i/home/james-whalen/.local/lib/python3.13/site-packages/opentelemetry/sdk/metrics/_internal/aggregation.pyr+   r+   Q   s     KEJr9   r+   c                       \ rS rSrS\S\4S jr\ SS\S\	SS4S	 jj5       r
\S
\S\S\\   4S j5       rS\\   4S jrS\S\	SS4S jrSrg)_Aggregation]   
attributesreservoir_builderc                 T    [        5       U l        Xl        U" 5       U l        S U l        g N)r
   _lock_attributes
_reservoir_previous_point)selfr>   r?   s      r:   __init___Aggregation.__init__^   s%    
 V
%+-#r9   measurementshould_sample_exemplarreturnNc                     g)zAggregate a measurement.

Args:
    measurement: Measurement to aggregate
    should_sample_exemplar: Whether the measurement should be sampled by the exemplars reservoir or not.
Nr/   rF   rI   rJ   s      r:   	aggregate_Aggregation.aggregateh       r9   "collection_aggregation_temporalitycollection_start_nanoc                     g rA   r/   rF   rQ   rR   s      r:   collect_Aggregation.collects   s     	r9   c                 L    U R                   R                  U R                  5      $ )zXReturns the collected exemplars.

Returns:
    The exemplars collected by the reservoir
)rD   rU   rC   rF   s    r:   _collect_exemplars_Aggregation._collect_exemplars{   s     &&t'7'788r9   c                     U(       aG  U R                   R                  UR                  UR                  UR                  UR
                  5        gg)a  Offer the measurement to the exemplar reservoir for sampling.

It should be called within the each :ref:`aggregate` call.

Args:
    measurement: The new measurement
    should_sample_exemplar: Whether the measurement should be sampled by the exemplars reservoir or not.
N)rD   offervaluetime_unix_nanor>   contextrM   s      r:   _sample_exemplar_Aggregation._sample_exemplar   sB     "OO!!!!**&&##	 "r9   )rC   rB   rE   rD   T)r0   r1   r2   r3   r(   r   rG   r   r"   boolrN   r+   intr   r)   rU   r   r   rY   r`   r8   r/   r9   r:   r<   r<   ]   s    $$ 4$ GK&@D	  ,B  # 
.	!	 9HX$6 9&@D	r9   r<   c                   L    \ rS rSr SS\S\SS4S jjrS\S\S\	\
   4S	 jrS
rg)_DropAggregation   rI   rJ   rK   Nc                     g rA   r/   rM   s      r:   rN   _DropAggregation.aggregate   s     	r9   rQ   rR   c                     g rA   r/   rT   s      r:   rU   _DropAggregation.collect   s    
 	r9   r/   rb   )r0   r1   r2   r3   r"   rc   rN   r+   rd   r   r)   rU   r8   r/   r9   r:   rf   rf      sH    GK&@D	
,B  # 
.	!	r9   rf   c            
       x   ^  \ rS rSrS\S\S\S\S\4
U 4S jjr	 SS\
S	\S
S4S jjrS\S\S
\\   4S jrSrU =r$ )_SumAggregation   r>   instrument_is_monotonic"instrument_aggregation_temporalitystart_time_unix_nanor?   c                    > [         TU ]  X5        X@l        UU l        X l        S U l        U R                  U l        SU l        g Nr   )superrG   _start_time_unix_nano#_instrument_aggregation_temporality_instrument_is_monotonic_value_previous_collection_start_nano_previous_value)rF   r>   ro   rp   rq   r?   	__class__s         r:   rG   _SumAggregation.__init__   sI     	7%9". 	0 )@%/3/I/I, r9   rI   rJ   rK   Nc                     U R                      U R                  c  SU l        U R                  UR                  -   U l        S S S 5        U R                  X5        g ! , (       d  f       N = frs   )rB   rx   r]   r`   rM   s      r:   rN   _SumAggregation.aggregate   sO     ZZ{{"++(9(99DK	  	kB Zs   3A
A(rQ   rR   c           	      l   U R                      U R                  nSU l        U R                  [        R                  L a  U[        R                  L aN  U R
                  nUU l        Uc
   SSS5        g[        U R                  U R                  5       UUUS9sSSS5        $ Uc  SnX0R                  -   U l	        [        U R                  U R                  5       U R                  UU R                  S9sSSS5        $ Uc
   SSS5        gU[        R                  L aT  X0R                  -
  nX0l	        U R
                  nX l        [        U R                  U R                  5       UUUS9sSSS5        $ [        U R                  U R                  5       U R                  UUS9sSSS5        $ ! , (       d  f       g= f)a  
Atomically return a point for the current value of the metric and
reset the aggregation value.

Synchronous instruments have a method which is called directly with
increments for a given quantity:

For example, an instrument that counts the amount of passengers in
every vehicle that crosses a certain point in a highway:

synchronous_instrument.add(2)
collect(...)  # 2 passengers are counted
synchronous_instrument.add(3)
collect(...)  # 3 passengers are counted
synchronous_instrument.add(1)
collect(...)  # 1 passenger is counted

In this case the instrument aggregation temporality is DELTA because
every value represents an increment to the count,

Asynchronous instruments have a callback which returns the total value
of a given quantity:

For example, an instrument that measures the amount of bytes written to
a certain hard drive:

callback() -> 1352
collect(...) # 1352 bytes have been written so far
callback() -> 2324
collect(...) # 2324 bytes have been written so far
callback() -> 4542
collect(...) # 4542 bytes have been written so far

In this case the instrument aggregation temporality is CUMULATIVE
because every value represents the total of the measurement.

There is also the collection aggregation temporality, which is passed
to this method. The collection aggregation temporality defines the
nature of the returned value by this aggregation.

When the collection aggregation temporality matches the
instrument aggregation temporality, then this method returns the
current value directly:

synchronous_instrument.add(2)
collect(DELTA) -> 2
synchronous_instrument.add(3)
collect(DELTA) -> 3
synchronous_instrument.add(1)
collect(DELTA) -> 1

callback() -> 1352
collect(CUMULATIVE) -> 1352
callback() -> 2324
collect(CUMULATIVE) -> 2324
callback() -> 4542
collect(CUMULATIVE) -> 4542

When the collection aggregation temporality does not match the
instrument aggregation temporality, then a conversion is made. For this
purpose, this aggregation keeps a private attribute,
self._previous_value.

When the instrument is synchronous:

self._previous_value is the sum of every previously
collected (delta) value. In this case, the returned (cumulative) value
will be:

self._previous_value + value

synchronous_instrument.add(2)
collect(CUMULATIVE) -> 2
synchronous_instrument.add(3)
collect(CUMULATIVE) -> 5
synchronous_instrument.add(1)
collect(CUMULATIVE) -> 6

Also, as a diagram:

time ->

self._previous_value
|-------------|

value (delta)
              |----|

returned value (cumulative)
|------------------|

When the instrument is asynchronous:

self._previous_value is the value of the previously
collected (cumulative) value. In this case, the returned (delta) value
will be:

value - self._previous_value

callback() -> 1352
collect(DELTA) -> 1352
callback() -> 2324
collect(DELTA) -> 972
callback() -> 4542
collect(DELTA) -> 2218

Also, as a diagram:

time ->

self._previous_value
|-------------|

value (cumulative)
|------------------|

returned value (delta)
              |----|
Nr>   	exemplarsrq   r^   r]   r   )rB   rx   rv   r+   r6   ry   r%   rC   rY   rz   ru   )rF   rQ   rR   r]   previous_collection_start_nanoresult_values         r:   rU   _SumAggregation.collect   s   z ZZKKEDK 88)//0 7-334 << 3 . 8 }#- Z0 +#'#3#3"&"9"9";-K'<#1 Z@ =E',/C/C'C$&#//"557)-)C)C#8..K Z` } g Zl 3)//0  %';';;',$ 88 / 8M4&#//"557)G#8&E ZT #++113%)%?%?4U ZZs,   AF%1$F%AF%9F%AF%-.F%%
F3)rv   rw   ry   rz   ru   rx   rb   )r0   r1   r2   r3   r(   rc   r+   rd   r   rG   r"   rN   r   r%   rU   r8   __classcell__r{   s   @r:   rm   rm      s    !! "&! -C	!
 "! 4!, HL	C&	C@D	C		CM,BM  #M 
/	"	M Mr9   rm   c                   h   ^  \ rS rSrS\S\4U 4S jjr SS\S\4S jjr	S\
S	\S
\\   4S jrSrU =r$ )_LastValueAggregationi  r>   r?   c                 2   > [         TU ]  X5        S U l        g rA   )rt   rG   rx   )rF   r>   r?   r{   s      r:   rG   _LastValueAggregation.__init__  s    
 	7r9   rI   rJ   c                     U R                      UR                  U l        S S S 5        U R                  X5        g ! , (       d  f       N = frA   )rB   r]   rx   r`   rM   s      r:   rN   _LastValueAggregation.aggregate  s5     ZZ%++DK  	kB Zs	   9
ArQ   rR   rK   c                     U R                      U R                  c
   SSS5        gU R                  nSU l        SSS5        U R                  5       n[        U R                  USUWS9$ ! , (       d  f       N5= f)@
Atomically return a point for the current value of the metric.
Nr   )rB   rx   rY   r%   rC   )rF   rQ   rR   r]   r   s        r:   rU   _LastValueAggregation.collect  sp     ZZ{{" Z KKEDK	  ++-	''!%0
 	
 Zs   A'A''
A5)rx   rb   )r0   r1   r2   r3   r(   r   rG   r"   rc   rN   r+   rd   r   r)   rU   r8   r   r   s   @r:   r   r     sd     4 HLC&C@DC
,B
  #
 
.	!	
 
r9   r   )g        g      @g      $@g      9@g      I@g     R@g      Y@g     @o@g     @@g     p@g     @@g     @g     @g     L@g     @9_DEFAULT_EXPLICIT_BUCKET_HISTOGRAM_AGGREGATION_BOUNDARIESc                      ^  \ rS rSr  SS\S\S\S\S\\	\
      S\4U 4S	 jjjrS
\\   4S jr SS\S\S
S4S jjrS\S\S
\\   4S jrSrU =r$ )#_ExplicitBucketHistogramAggregationi  Nr>   rp   rq   r?   
boundariesrecord_min_maxc                 >  > Uc  [         n[        TU ]	  U[        XES9S9  UU l        X0l        [        U5      U l        X`l        S U l	        [        U l        [        * U l        SU l        S U l        [        U l        [        * U l        SU l        U R
                  U l        g )N)r   r?   r   )r   rt   rG   r   rv   ru   tuple_boundaries_record_min_maxrx   r	   _min_max_sumrz   _previous_min_previous_max_previous_sumry   )rF   r>   rp   rq   r?   r   r   r{   s          r:   rG   ,_ExplicitBucketHistogramAggregation.__init__  s     I  	%! 	 	
 / 	0 &:" ,-	D		# !T/3/I/I,r9   rK   c                 :    S/[        U R                  5      S-   -  $ Nr   r-   )lenr   rX   s    r:   _get_empty_bucket_counts<_ExplicitBucketHistogramAggregation._get_empty_bucket_counts  s    sc$**+a/00r9   rI   rJ   c                    U R                      U R                  c  U R                  5       U l        UR                  nU =R                  U-  sl        U R
                  (       a6  [        U R                  U5      U l        [        U R                  U5      U l	        U R                  [        U R                  U5      ==   S-  ss'   S S S 5        U R                  X5        g ! , (       d  f       N = f)Nr-   )rB   rx   r   r]   r   r   minr   maxr   r   r   r`   )rF   rI   rJ   measurement_values       r:   rN   -_ExplicitBucketHistogramAggregation.aggregate  s     ZZ{{"";;= + 1 1II**I##		+<=			+<=	KKD$4$46GHIQNI  	kB Zs   B6C
C+rQ   rR   c                    U R                      U R                  nU R                  nU R                  nU R                  nSU l        SU l        [
        U l        [
        * U l        U R                  [        R                  L Ga  U[        R                  L ao  U R                  nUU l	        Uc
   SSS5        g[        U R                  U R                  5       UU[        U5      U[        U5      U R                  UUS9
sSSS5        $ Uc  U R!                  5       nU R"                  c  U R!                  5       U l        [%        X0R"                  5       VV	s/ s H
  u  nn	X-   PM     sn	nU l        ['        XPR(                  5      U l        [+        X`R,                  5      U l        X@R.                  -   U l        [        U R                  U R                  5       U R0                  U[        U R"                  5      U R.                  [        U R"                  5      U R                  U R(                  U R,                  S9
sSSS5        $  SSS5        gs  sn	nf ! , (       d  f       g= f)r   Nr   )
r>   r   rq   r^   countsumbucket_countsexplicit_boundsr   r   )rB   rx   r   r   r   r	   rv   r+   r6   ry   r$   rC   rY   r   r   r   r   rz   zipr   r   r   r   r   ru   )
rF   rQ   rR   r]   sum_min_max_r   value_elementprevious_value_elements
             r:   rU   +_ExplicitBucketHistogramAggregation.collect  s*    ZZKKE99D99D99DDKDIDIDI 88)//0 7-334 << 3 . 8 }#; Z> .#'#3#3"&"9"9";-K'<!%j &+El(,(8(8  ? ZX = 99;E''/+/+H+H+JD( U$8$89(
 :%. ": :($ &)/A/A%B"%(/A/A%B"%),>,>%>")#//"557)-)C)C#8d223**"'(<(<"=$($4$4****{ ZT U Zd(e Zs3   BI4AIAII!CI<II
I)r   rv   r   r   ry   r   r   r   rz   r   ru   r   rx   NTrb   )r0   r1   r2   r3   r(   r+   rd   r   r   r   floatrc   rG   r   r   r"   rN   r)   rU   r8   r   r   s   @r:   r   r     s     15#%J%J -C%J "	%J
 4%J Xe_-%J %J %JN1$s) 1 HLC&C@DC	C&S,BS  #S 
.	!	S Sr9   r   c                      ^  \ rS rSrSrSr  SS\S\S\S\	S\	S	\	4U 4S
 jjjr
 SS\S\SS4S jjrS\S\	S\\   4S jrS r\S 5       r\S\	S\4S j5       rS r\S\	4S j5       rS\S\4S jrSrU =r$ ) &_ExponentialBucketHistogramAggregationih  r.   i @  r>   r?   rp   rq   max_size	max_scalec           
        > XPR                   :  a  [        SU S35      eXPR                  :  a  [        SU S35      eUS:  a  [        R	                  SU5        [
        TU ]  U[        U[        SU5      S9S9  UU l	        X@l
        XPl        X`l        S U l        S U l        [        U l        [        * U l        SU l        SU l        SU l        S U l        S U l        S U l        [        U l        [        * U l        SU l        SU l        SU l        S U l        U R                  U l        U R?                  U R                  5      U l         g )	NzBuckets max size z6 is smaller than minimum max size {self._min_max_size}z5 is larger than maximum max size {self._max_max_size}   zGmax_scale is set to %s which is larger than the recommended value of 20)sizer   r   )!_min_max_size
ValueError_max_max_size_loggerwarningrt   rG   r   r   rv   ru   	_max_size
_max_scale_value_positive_value_negativer	   r   r   r   _count_zero_count_scale_previous_value_positive_previous_value_negativer   r   r   _previous_count_previous_zero_count_previous_scalery   _new_mapping_mapping)rF   r>   r?   rp   rq   r   r   r{   s          r:   rG   /_ExponentialBucketHistogramAggregation.__init__t  se   . (((#H: .8 8 
 (((#H: .8 8  r>OO: 	%!B(9 	 	
 / 	0 &:"!###	D		(,%(,% !T $%!#/3/I/I,))$//:r9   rI   rJ   rK   Nc                 .   U R                      U R                  c  [        5       U l        U R                  c  [        5       U l        UR                  nU =R
                  U-  sl        [        U R                  U5      U l        [        U R                  U5      U l	        U =R                  S-  sl
        US:X  a@  U =R                  S-  sl        U R                  U R                  :X  a  SU l         S S S 5        g US:  a  U R                  nOU* nU R                  nU R                  R                  U5      nSnSu  px[        U5      S:X  a  XTl        XTl        XTl        OxXTR                   :  a.  UR"                  U-
  U R&                  :  a  SnUnUR"                  nO;XTR"                  :  a,  XTR                   -
  U R&                  :  a  SnUR                   nUnU(       a  U R)                  Xx5      n	U R+                  U	U R                  U R                  5        U R-                  U R                  R.                  U	-
  5      U l        U R                  R                  U5      nU R                  R.                  U l        XTR                   :  aN  UR"                  U-
  n
U
[        UR0                  5      :  a  UR3                  U
S-   U R&                  5        XTl        O[XTR"                  :  aL  XTR                   -
  n
U
[        UR0                  5      :  a  UR3                  U
S-   U R&                  5        XTl        XTR$                  -
  nUS:  a  U[        UR0                  5      -  nUR5                  U5        S S S 5        U R7                  X5        g ! , (       d  f       N = f)Nr-   r   F)r   r   T)rB   r   r   r   r]   r   r   r   r   r   r   r   r   r   map_to_indexr   index_start	index_end
index_baser   _get_scale_change
_downscaler   scalecountsgrowincrement_bucketr`   )rF   rI   rJ   r   r]   indexis_rescaling_neededlowhighscale_changespanbucket_indexs               r:   rN   0_ExponentialBucketHistogramAggregation.aggregate  s   
 ZZ##+'.y$##+'.y$ + 1 1II**IDII'89DIDII'89DIKK1K A%  A% ;;$"2"22"#DK+ Z. !1$,, &7$6!,, MM../@AE"'IC5zQ$)!"'#(  )))__u,?&*# '...4>>A&*#''"#55c@ ((((
 !% 1 1MM'',6! 223DE----DK(((.3u||,,JJtax8$)!(0003u||,,JJtax8"' #3#33LaELL 11 ""<0Q T 	kBU Zs   C"N8I4N
NrQ   rR   c                 ~
   U R                      U R                  nU R                  nU R                  nU R                  nU R
                  nU R                  nU R                  n	U R                  n
SU l        SU l        SU l        [        U l        [        * U l        SU l        SU l        SU l        U R                  [        R                  L GaW  U[        R                  L a  U R                  nUU l        Uc  Uc
   SSS5        g[        U R                  U R!                  5       UUUUU
U	[#        UR$                  UR'                  5       S9[#        UR$                  UR'                  5       S9SUUS9sSSS5        $ Uc,  U R(                  c  [+        5       nUR-                  5       U l        Uc,  U R.                  c  [+        5       nUR-                  5       U l        U
c)  U R0                  c  U R2                  R4                  n
Xl        Ub"  U R(                  c  UR-                  5       U l        Ub"  U R.                  c  UR-                  5       U l        U
b  U R0                  c  Xl        Uc'  U R(                  b  U R(                  R-                  5       nUc'  U R.                  b  U R.                  R-                  5       nU
c  U R0                  b  U R0                  n
[7        U R0                  U
5      nU R9                  U R(                  UU
U5      u  pU R9                  U R.                  UU
U5      u  nn[7        UU R;                  X5      -
  UU R;                  UU5      -
  5      nU R=                  U R0                  U-
  U R(                  U R.                  5        U R?                  U R(                  UU
UU5        U R?                  U R.                  UU
UU5        [7        X`R@                  5      U l         [C        XpRD                  5      U l"        XPRF                  -   U l#        XRH                  -   U l$        XRJ                  -   U l%        Xl        [        U R                  U R!                  5       U RL                  UU RH                  U RF                  U R0                  U RJ                  [#        U R(                  R$                  U R(                  R'                  5       S9[#        U R.                  R$                  U R.                  R'                  5       S9SU R@                  U RD                  S9sSSS5        $  SSS5        g! , (       d  f       g= f)r   Nr   )offsetr   )r>   r   rq   r^   r   r   r   
zero_countpositivenegativeflagsr   r   )'rB   r   r   r   r   r   r   r   r   r	   rv   r+   r6   ry   r#   rC   rY   BucketsPointr   get_offset_countsr   r   
copy_emptyr   r   r   r   r   _get_low_high_previous_currentr   r   _merger   r   r   r   r   r   ru   )rF   rQ   rR   value_positivevalue_negativer   r   r   r   r   r   r   	min_scalelow_positivehigh_positivelow_negativehigh_negatives                    r:   rU   ._ExponentialBucketHistogramAggregation.collect8  s    ZZ!11N!11N99D99D99DKKE))JKKE#'D #'D DIDIDIDK DDK 88)//0 7-334 << 3 . 8 &-.2H#K ZN 9#'#3#3"&"9"9";-K'<# ##-!-#1#8#8+9+K+K+M" ".#1#8#8+9+K+K+M"
    )O ZV #*55= &-YN4B4M4M4OD1"*55=%,YN4B4M4M4OD1=T%9%9%A MM//E+0( #.55=* 5C4M4M4OD1".55=4B4M4M4OD1$)=)=)E+0( #*55A%)%B%B%M%M%ON"*55A%)%B%B%M%M%ON=T%9%9%E 00E 4 4e<	 7755&!	 , 7755&!	 ,m  ,,\IJ,,\=IJ	 ((941111  11"6 11"6 &)/A/A%B"%(/A/A%B"%),>,>%>"',/C/C'C$!:!:: ) (1$4#//"557)-)C)C#8..**..#88)#<<CC 99KKM *#<<CC 99KKM ****1W ZL M ZZs    C-T.A,T.9N!T.$T..
T<c                     U R                  XR                  U5      u  pVU R                  X#U5      u  pxXx:  a  Un	Un
X4$ XV:  a  Un	Un
X4$ [        XW5      n	[        Xh5      n
X4$ rA   )_get_low_highr   r   r   )rF   previous_point_bucketscurrent_point_bucketscurrent_scaler   previous_point_lowprevious_point_highcurrent_point_lowcurrent_point_highr   r   s              r:   r   E_ExponentialBucketHistogramAggregation._get_low_high_previous_current*  s     594F4F"$8$8)5
1	 372D2D!)3
/	 1$C&D y  5#C%D y (<C*?Dyr9   c                 j    U R                   S/:X  a  gX-
  nU R                  U-	  U R                  U-	  4$ )Nr   )r   )r   r   r   )bucketsr   r   shifts       r:   r   4_ExponentialBucketHistogramAggregation._get_low_highF  s<    >>aS !""e+W->->%-GGGr9   r   c                 :    U S::  a  [        U 5      $ [        U 5      $ rs   )r    r!   )r   s    r:   r   3_ExponentialBucketHistogramAggregation._new_mappingO  s    A:"5))&&r9   c                 t    SnX!-
  U R                   :  a#  US-	  nUS-	  nUS-  nX!-
  U R                   :  a  M#  U$ r   )r   )rF   r   r   changes       r:   r   8_ExponentialBucketHistogramAggregation._get_scale_changeU  sG    jDNN*19D(CaKF	 jDNN* r9   r  c                 x    U S:X  a  g U S:  a  [        S5      eUR                  U 5        UR                  U 5        g )Nr   zInvalid change of scale)	Exception	downscale)r  r   r   s      r:   r   1_ExponentialBucketHistogramAggregation._downscale`  s;    Q;A:5666"6"r9   previous_bucketscurrent_bucketsc                 H   X4-
  n[        UR                  5       GH  u  pxUS:X  a  M  UR                  U-   n	XR                  :  a  U	[	        UR                  5      -  n	X-	  n
XR
                  :  ag  UR                  U
-
  nXR                  :  a  [        S5      eU[	        UR                  5      :  a  UR                  US-   U R                  5        Xl        XR                  :  af  XR
                  -
  nXR                  :  a  [        S5      eU[	        UR                  5      :  a  UR                  US-   U R                  5        Xl        XR                  -
  nUS:  a  U[	        UR                  5      -  nU[        R                  L a  U* nUR                  XS9  GM     g )Nr   zIncorrect merge scaler-   )	increment)	enumerater   r   r   r   r   r   r  r   r+   r6   r   )rF   r  r  r   r   aggregation_temporalitycurrent_changecurrent_bucket_indexcurrent_bucketcurrent_indexr   r   r   s                r:   r   -_ExponentialBucketHistogramAggregation._mergel  s    '24=""5
0  " ,669MMM888_%;%;!<<!3E333'11E9>>)#$;<<3/6677$))$(DNNC/4,111;;;>>)#$;<<3/6677$))$(DNNC-2* #>#>>La$4$;$; <<&*@*F*FF"0-- . a5
r9   )r   rv   r   r   r   r   r   ry   r   r   r   r   r   r   r   r   r   ru   r   r   r   r      r   rb   )r0   r1   r2   r3   r   r   r(   r   r+   rd   rG   r"   rc   rN   r   r)   rU   r   staticmethodr   r   r   r   r   r   r   r8   r   r   s   @r:   r   r   h  s8    M M Q;Q; 4Q; -C	Q;
 "Q; Q; Q; Q;h HLoC&oC@DoC	oCbp,Bp  #p 
.	!	pd8 H H 'C 'G ' '
	 	#3 	# 	#<!< !< <r9   r   c                   R    \ rS rSrSr\S\S\S\\	\
   /\4   S\S\
4
S j5       rS	rg
)Aggregationi  z'
Base class for all aggregation types.

instrumentr>   reservoir_factoryrq   rK   c                     g)zCreates an aggregationNr/   rF   r"  r>   r#  rq   s        r:   _create_aggregationAggregation._create_aggregation  rP   r9   r/   N)r0   r1   r2   r3   r4   r   r   r(   r   r   r<   r   rd   r&  r8   r/   r9   r:   r!  r!    sa     	%	% 	% $, "::
		% "	% 
	% 	%r9   r!  c            
       H    \ rS rSrSrS\S\S\\\	   /\
4   S\S\	4
S jrS	rg
)DefaultAggregationi  a  
The default aggregation to be used in a `View`.

This aggregation will create an actual aggregation depending on the
instrument type, as specified next:

==================================================== ====================================
Instrument                                           Aggregation
==================================================== ====================================
`opentelemetry.sdk.metrics.Counter`                  `SumAggregation`
`opentelemetry.sdk.metrics.UpDownCounter`            `SumAggregation`
`opentelemetry.sdk.metrics.ObservableCounter`        `SumAggregation`
`opentelemetry.sdk.metrics.ObservableUpDownCounter`  `SumAggregation`
`opentelemetry.sdk.metrics.Histogram`                `ExplicitBucketHistogramAggregation`
`opentelemetry.sdk.metrics.ObservableGauge`          `LastValueAggregation`
==================================================== ====================================
r"  r>   r#  rq   rK   c                 F   [        U[        5      (       a%  [        UU" [        5      S[        R                  US9$ [        U[
        5      (       a%  [        UU" [        5      S[        R                  US9$ [        U[        5      (       a%  [        UU" [        5      S[        R                  US9$ [        U[        5      (       a%  [        UU" [        5      S[        R                  US9$ [        U[        5      (       a;  UR                  R                  n[        UU" [        5      [        R                  UUS9$ [        U[        5      (       a  [        UU" [        5      S9$ [        U[        5      (       a  [        UU" [        5      S9$ [!        S[#        U5       S35      e)NT)r?   ro   rp   rq   F)r?   rp   r   rq   r   zInvalid instrument type z found)
isinstancer   rm   r+   r6   r   r   r7   r   r   	_advisoryexplicit_bucket_boundariesr   r   r   r   r  type)rF   r"  r>   r#  rq   r   s         r:   r&  &DefaultAggregation._create_aggregation  s    j'**""3O"D(,*00%9  j-00""3O"D(-*00%9  j"344""3O"D(,*55%9  j"9::""3O"D(-*55%9  j),,#--HHJ6"37# +00%%9
 
 j/22("34I"J 
 j&))("34I"J  24
3C2DFKLLr9   r/   Nr0   r1   r2   r3   r4   r   r(   r   r   r<   r   rd   r&  r8   r/   r9   r:   r)  r)    s^    $PMPM PM $, "::
	PM "PM 
PMr9   r)  c            
       ^    \ rS rSr  SS\S\4S jjrS\S\S\\	\
   /\4   S\S	\
4
S
 jrSrg)%ExponentialBucketHistogramAggregationi#  r   r   c                     Xl         X l        g rA   )r   r   )rF   r   r   s      r:   rG   .ExponentialBucketHistogramAggregation.__init__$  s    
 "#r9   r"  r>   r#  rq   rK   c           	         [         R                  n[        U[        5      (       a  [         R                  nO%[        U[
        5      (       a  [         R                  n[        UU" [        5      UUU R                  U R                  S9$ )N)r   r   )
r+   r5   r+  r   r6   r   r7   r   r   r   rF   r"  r>   r#  rq   rp   s         r:   r&  9ExponentialBucketHistogramAggregation._create_aggregation,  st     .D-O-O*j+..1G1M1M.
L11&11 / 6DE. ^^oo
 	
r9   )r   r   Nr  )r0   r1   r2   r3   rd   rG   r   r(   r   r   r<   r   r&  r8   r/   r9   r:   r2  r2  #  sl     $$ $

 
 $, "::
	
 "
 

r9   r2  c            
       r    \ rS rSrSr  SS\\\      S\SS4S jjr	S\
S	\S
\\\   /\4   S\S\4
S jrSrg)"ExplicitBucketHistogramAggregationiG  a'  This aggregation informs the SDK to collect:

- Count of Measurement values falling within explicit bucket boundaries.
- Arithmetic sum of Measurement values in population. This SHOULD NOT be collected when used with instruments that record negative measurements, e.g. UpDownCounter or ObservableGauge.
- Min (optional) Measurement value in population.
- Max (optional) Measurement value in population.


Args:
    boundaries: Array of increasing values representing explicit bucket boundary values.
    record_min_max: Whether to record min and max.
Nr   r   rK   c                     Xl         X l        g rA   r   r   )rF   r   r   s      r:   rG   +ExplicitBucketHistogramAggregation.__init__U  s    
 &-r9   r"  r>   r#  rq   c                 `   [         R                  n[        U[        5      (       a  [         R                  nO%[        U[
        5      (       a  [         R                  nU R                  b  U R                  nOUR                  R                  n[        UUUU" [        5      UU R                  5      $ rA   )r+   r5   r+  r   r6   r   r7   r   r,  r-  r   r   )rF   r"  r>   r#  rq   rp   r   s          r:   r&  6ExplicitBucketHistogramAggregation._create_aggregation]  s     .D-O-O*j+..1G1M1M.
L11&11 / '))J#--HHJ2. AB  
 	
r9   r;  r   )r0   r1   r2   r3   r4   r   r   r   rc   rG   r   r(   r   r   r<   r   rd   r&  r8   r/   r9   r:   r9  r9  G  s     15#.Xe_-. . 
	.

 
 $, "::
	
 "
 

r9   r9  c            
       H    \ rS rSrSrS\S\S\\\	   /\
4   S\S\	4
S jrS	rg
)SumAggregationi}  zZThis aggregation informs the SDK to collect:

- The arithmetic sum of Measurement values.
r"  r>   r#  rq   rK   c           	         [         R                  n[        U[        5      (       a  [         R                  nO%[        U[
        5      (       a  [         R                  n[        U[        U[        [        45      UUU" [        5      5      $ rA   )
r+   r5   r+  r   r6   r   r7   rm   r   r   r6  s         r:   r&  "SumAggregation._create_aggregation  su     .D-O-O*j+..1G1M1M.
L11&11 / zG->#?@. o.
 	
r9   r/   Nr0  r/   r9   r:   r@  r@  }  sR    


 
 $, "::
	
 "
 

r9   r@  c            
       H    \ rS rSrSrS\S\S\\\	   /\
4   S\S\	4
S jrS	rg
)LastValueAggregationi  zp
This aggregation informs the SDK to collect:

- The last Measurement.
- The timestamp of the last Measurement.
r"  r>   r#  rq   rK   c                 *    [        UU" [         5      S9$ )Nr   )r   r%  s        r:   r&  (LastValueAggregation._create_aggregation  s     %/0EF
 	
r9   r/   Nr0  r/   r9   r:   rD  rD    sR    

 
 $, "::
	
 "
 

r9   rD  c            
       H    \ rS rSrSrS\S\S\\\	   /\
4   S\S\	4
S jrS	rg
)DropAggregationi  z=Using this aggregation will make all measurements be ignored.r"  r>   r#  rq   rK   c                 ,    [        X#" [         5      5      $ rA   )rf   r%  s        r:   r&  #DropAggregation._create_aggregation  s      )*:;
 	
r9   r/   Nr0  r/   r9   r:   rH  rH    sP    G

 
 $, "::
	
 "
 

r9   rH  N)Nabcr   r   bisectr   enumr   	functoolsr   loggingr   mathr	   	threadingr
   typingr   r   r   r   r   r   r   opentelemetry.metricsr   r   r   r   r   r   r   r   r   r   ,opentelemetry.sdk.metrics._internal.exemplarr   r   Aopentelemetry.sdk.metrics._internal.exponential_histogram.bucketsr   Aopentelemetry.sdk.metrics._internal.exponential_histogram.mappingr   Ropentelemetry.sdk.metrics._internal.exponential_histogram.mapping.exponent_mappingr    Sopentelemetry.sdk.metrics._internal.exponential_histogram.mapping.logarithm_mappingr!   /opentelemetry.sdk.metrics._internal.measurementr"   )opentelemetry.sdk.metrics._internal.pointr   r#   r$   r%   r&   r'   
GaugePointHistogramPointopentelemetry.util.typesr(   r)   r0   r   r+   r<   rf   rm   r   r   r   __annotations__r   r   r!  r)  r2  r9  r@  rD  rH  r/   r9   r:   <module>r_     s}  " $ #           H M  J 0)?<NO
H
	W 	73/ 7t| nl3' nb'
L4 '
TN 98E? &Q,~*F Qj@	\.-I @	F%# %$cM cML!
K !
H3
 3
l
[ 
@
; 
.
k 
r9   