
    9Yf9                         d dl mZ 	 d dlmZ d dlmZ d dlmZ  G d de	      Z
 G d d	e
      Zy
# e$ r	 d dlmZ Y 0w xY w)    )wraps)	monotonic)time)_get_wrapped_co)iscoroutinefunctionc                   <    e Zd ZdZd
dZd Zd Zd Zd Zd Z	d	 Z
y)TimedContextManagerDecoratorzx
    A context manager and a decorator which will report the elapsed time in
    the context OR in a function call.
    Nc                 z    || _         |j                  | _        || _        || _        || _        || _        d | _        y N)statsdtimingtiming_funcmetrictagssample_rateuse_mselapsed)selfr   r   r   r   r   s         Y/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/datadog/dogstatsd/context.py__init__z%TimedContextManagerDecorator.__init__   s9    !==	&    c                       j                   s j                  dj                   _         t              rt	               S t               fd       }|S )z
        Decorator which returns the elapsed time of the function call.

        Default to the function name if metric was not provided.
        .c                  x    t               }	  | i |j                  |       S # j                  |       w xY wr   )r   _send)argskwargsstartfuncr   s      r   wrappedz6TimedContextManagerDecorator.__call__.<locals>.wrapped.   s5    KE"T,V,

5!

5!s   & 9)r   
__module____name__r   r   r   )r   r   r    s   `` r   __call__z%TimedContextManagerDecorator.__call__    sV     {{%)__dmmDDK t$"4.. 
t	" 
	" r   c                 R    | j                   st        d      t               | _        | S )Nz#Cannot used timed without a metric!)r   	TypeErrorr   _startr   s    r   	__enter__z&TimedContextManagerDecorator.__enter__8   s#    {{ABBkr   c                 :    | j                  | j                         y r   )r   r&   )r   typevalue	tracebacks       r   __exit__z%TimedContextManagerDecorator.__exit__>   s    

4;;r   c                 "   t               |z
  }| j                  | j                  n| j                  j                  }|rt        t	        d|z              n|}| j                  | j                  || j                  | j                         || _	        y )Ni  )
r   r   r   introundr   r   r   r   r   )r   r   r   r   s       r   r   z"TimedContextManagerDecorator._sendB   sl    +% $ 7T[[=O=O06#eD7N+,Ggtyy$:J:JKr   c                 $    | j                          y r   )r(   r'   s    r   r   z"TimedContextManagerDecorator.startI   s    r   c                 *    | j                  d d d        y r   )r-   r'   s    r   stopz!TimedContextManagerDecorator.stopL   s    dD$'r   NN   N)r"   r!   __qualname____doc__r   r#   r(   r-   r   r   r3    r   r   r	   r	      s*    
0 (r   r	   c                   $     e Zd ZdZd fd	Z xZS )"DistributedContextManagerDecoratorz
    A context manager and a decorator which will report the elapsed time in
    the context OR in a function call using the custom distribution metric.
    c                 V    t         t        |   |||||       |j                  | _        y r   )superr:   r   distributionr   )r   r   r   r   r   r   	__class__s         r   r   z+DistributedContextManagerDecorator.__init__V   s,    0$@QUWbdjk!..r   r4   )r"   r!   r6   r7   r   __classcell__)r>   s   @r   r:   r:   P   s    
/ /r   r:   N)	functoolsr   r   r   ImportErrordatadog.dogstatsd.context_asyncr   datadog.util.compatr   objectr	   r:   r8   r   r   <module>rE      sI   
 '
 < 3<(6 <(~/)E /O  '&'s   1 ??