o
    i`                     @   s   d dl Z d dlmZ d dlmZ d dlmZ e jddG dd dZd	ee	e
ef  d
ee
ef fddZG dd deZe  G dd dedZe ZdS )    N)	monotonic)Any)SequenceT)frozenc                       s   e Zd ZU eed< eed< ejddZeed< ejddZeed< eje	dZ
ee ed	< eje	dZee ed
< ejdddZeed< d fddZdefddZ  ZS )HttpEndPointmethodpath )defaultresource_namehttp.requestoperation_name)default_factoryresponse_body_typeresponse_codeF)initrepr_hashreturnNc                    sT   t  d| j  | jst  d| j d| j  t  dt| j| jf d S )Nr   r    r   )super__setattr__r   upperr   r   hashself	__class__ N/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/endpoints.py__post_init__   s   zHttpEndPoint.__post_init__c                 C   s   | j S N)r   r   r   r   r   __hash__   s   zHttpEndPoint.__hash__r   N)__name__
__module____qualname__str__annotations__dataclassesfieldr   r   tupler   r   r   intr   r    r"   __classcell__r   r   r   r   r      s   
 r   lstr   c                 C   s   dd | D S )Nc                 S   s$   i | ]\}}|d g dfvr||qS )r   Nr   ).0kvr   r   r   
<dictcomp>   s   $ z!_dict_factory.<locals>.<dictcomp>r   )r.   r   r   r   _dict_factory   s   r3   c                       s6   e Zd ZU dZi Zeeef ed<  fddZ	  Z
S )	SingletonzSingleton Class.
_instancesc                    s0   | | j vrtt| j|i || j | < | j |  S r!   )r5   r   r4   __call__)clsargskwargsr   r   r   r6   %   s   

zSingleton.__call__)r$   r%   r&   __doc__r5   dicttypeobjectr(   r6   r-   r   r   r   r   r4       s   
 r4   c                   @   s   e Zd ZU dZejeddZee e	d< ejdddZ
ee	d< ejdddZee	d	< ejeddZee	d
< ejdddZee	d< dddZ				d dededededee dee ddfddZdedefddZdS )!HttpEndPointsCollectiona5  A collection of HTTP endpoints that can be modified and flushed to a telemetry payload.

    The collection collects HTTP endpoints at startup and can be flushed to a telemetry payload.
    It maintains a maximum size and drops endpoints after a certain time period in case of a hot reload of the server.
    F)r   r   	endpointsT)r
   r   is_firstg     V@drop_time_secondslast_modification_timei  max_size_lengthr   Nc                 C   s   | j   d| _t | _dS )z*Reset the collection to its initial state.TN)r?   clearr@   r   rB   r   r   r   r   reset9   s   
zHttpEndPointsCollection.resetr	   r   r   r   r   r   r   r   r   c              
   C   s~   t  }|| j | jkr|   | jt||||||d dS t| j| jk r=|| _| jt||||||d || _dS dS )z4
        Add an endpoint to the collection.
        )r   r   r   r   r   r   N)	r   rB   rA   rE   r?   addr   lenrC   )r   r   r   r   r   r   r   current_timer   r   r   add_endpoint?   s6   


z$HttpEndPointsCollection.add_endpoint
max_lengthc                 C   sX   g }| j r!t||k r!|tj| j  td | j r!t||k s| j|d}d| _|S )zX
        Flush the endpoints to a payload, returning the first `max` endpoints.
        )dict_factory)r@   r?   F)r?   rG   appendr)   asdictpopr3   r@   )r   rJ   endpoints_resresr   r   r   flushf   s   zHttpEndPointsCollection.flushr#   )r	   r   r   r   )r$   r%   r&   r:   r)   r*   setr?   r   r(   r@   boolrA   floatr   rB   rC   r,   rE   r'   r   rI   r;   rQ   r   r   r   r   r>   +   s8   
 


'r>   )	metaclass)r)   timer   typingr   r   	dataclassr   listr+   r'   r;   r3   r<   r4   r>   endpoint_collectionr   r   r   r   <module>   s    
&
F