o
    Á¿i»  ã                   @   s<   d dl Z d dlmZ ddlmZ eeƒZG dd„ deƒZdS )é    N)ÚOptionalé   )Ú
get_loggerc                	   @   sÀ   e Zd ZU dZdZdZg Zee e	d< dZ
eeeeef   e	d< dZ			ddee dee deee  d	dfd
d„Zdd„ Zdd„ Zddeee  d	eeeeef   fdd„Zdd„ ZdS )ÚValueCollectorau  A basic state machine useful for collecting, caching and updating data
    obtained from different Python modules.

    The two primary use-cases are
    1) data loaded once (like tagging information)
    2) periodically updating data sources (like thread count)

    Functionality is provided for requiring and importing modules which may or
    may not be installed.
    TFÚrequired_modulesNÚvalueÚenabledÚperiodicÚreturnc                 C   sb   |d u r| j n|| _ |d u r| jn|| _|d u r| jn|| _d| _|  ¡ | _| jr/|  ¡  d S d S )NF)r   r	   r   Ú_modules_successfully_loadedÚ_load_modulesÚmodulesÚ_on_modules_load)Úselfr   r	   r   © r   úV/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/runtime/collector.pyÚ__init__   s   
ÿzValueCollector.__init__c                 C   s   dS )zHHook triggered after all required_modules have been successfully loaded.Nr   ©r   r   r   r   r   +   s    zValueCollector._on_modules_loadc                 C   sT   i }z| j D ]	}t |¡||< qd| _W |S  ty)   d| _t d|| ¡ Y d S w )NTFz9Could not import module "%s" for %s. Disabling collector.)r   Ú	importlibÚimport_moduler   ÚImportErrorr   ÚlogÚwarning)r   r   Úmoduler   r   r   r   .   s   
ûüzValueCollector._load_modulesÚkeysc                    sn   | j s| jS ˆ p
tƒ ‰ | js| jr| jS |  ˆ ¡| _tˆ ƒdkr1t| jtƒr1‡ fdd„| jD ƒ| _d| _| jS )zpReturns metrics as collected by `collect_fn`.

        :param keys: The keys of the metrics to collect.
        r   c                    s    g | ]\}}|ˆ v r||f‘qS r   r   )Ú.0ÚkÚv©r   r   r   Ú
<listcomp>N   s     z*ValueCollector.collect.<locals>.<listcomp>T)	r   r   Úsetr	   Úvalue_loadedÚ
collect_fnÚlenÚ
isinstanceÚlist)r   r   r   r   r   Úcollect;   s   
zValueCollector.collectc                 C   s   d  | jj| j| j| j¡S )Nz0<{}(enabled={},periodic={},required_modules={})>)ÚformatÚ	__class__Ú__name__r   r	   r   r   r   r   r   Ú__repr__S   s   üzValueCollector.__repr__)NNN)N)r)   Ú
__module__Ú__qualname__Ú__doc__r   r	   r   r%   ÚstrÚ__annotations__r   r   Útupler!   Úboolr   r   r   r    r&   r*   r   r   r   r   r   
   s.   
 üþý
ü
û,r   )	r   Útypingr   Úloggerr   r)   r   Úobjectr   r   r   r   r   Ú<module>   s
    