o
    Á¿iÐ  ã                	   @   s`  d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d
dlmZ dddefdd„Zdefdd„Zdefdd„Zeƒ deeeef defdd„ƒZdeeef dee deeeef  fdd„Zdedededefdd „Zdadefd!d"„Zdedefd#d$„Z deeeeef  fd%d&„Z!dS )'é    N)ÚTYPE_CHECKING)ÚIterable)Úprocess_tags)ÚDEFAULT_SERVICE_NAME)Ú get_module_distribution_versions)Úget_container_info)Úcached)Ú__version__é   )Úget_hostnameÚvizsys._version_infoÚreturnc                 C   s   d| j | j| jf S )z=Converts sys.version_info into a string with the format x.x.xz%d.%d.%d)ÚmajorÚminorÚmicro)r   © r   úS/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/telemetry/data.pyÚ_format_version_info   s   r   c                  C   s   t ƒ } | r
| jp	dS dS )zGet ID from docker containerÚ )r   Úcontainer_id)Úcontainer_infor   r   r   Ú_get_container_id   s   
r   c                  C   sN   zt  ¡ \} }}| r| W S t  ¡ \}}}}|r|W S W dS  ty&   Y dS w )zHReturns the os version for applications running on Mac or Windows 32-bitr   )ÚplatformÚmac_verÚ	win32_verÚOSError)ÚmverÚ_Úwverr   r   r   Ú_get_os_version   s   ÿüür   Úkeyc              	   C   sT   | \}}}|pt |pd|pddttjƒtt ¡ ttjjƒdœ}t	j	 }r(||d< |S )z—
    This helper packs and unpacks get_application arguments to support caching.
    Cached() annotation only supports functions with one argument
    r   Úpython)Úservice_nameÚservice_versionÚenvÚlanguage_nameÚlanguage_versionÚtracer_versionÚruntime_nameÚruntime_versionr   )
r   r   ÚsysÚversion_infor	   r   Úpython_implementationÚimplementationÚversionr   )r    Úservicer.   r$   ÚapplicationÚp_tagsr   r   r   Ú_get_application/   s   

ø
r2   Úalready_importedÚnew_modulesc                 C   sT   g }|D ]#}t |ƒ}|sq|\}}|dkrq|| v rq|| |< | ||dœ¡ q|S )NÚddtrace)Únamer.   )r   Úappend)r3   r4   ÚdepsÚmodule_nameÚdistsr6   r.   r   r   r   Úupdate_imported_dependenciesH   s   r;   r/   r.   r$   c                 C   s   t | ||fƒS )zjCreates a dictionary to store application data using ddtrace configurations and the System-Specific module)r2   )r/   r.   r$   r   r   r   Úget_application]   s   r<   c                   C   s6   t du rt ¡ tƒ tƒ t ¡ t ¡ t ¡ tƒ dœa t S )zACreates a dictionary to store host data using the platform moduleN)ÚosÚhostnameÚ
os_versionÚkernel_nameÚkernel_releaseÚkernel_versionr   )Ú
_host_infor   Úsystemr   r   Úreleaser.   r   r   r   r   r   Úget_host_infog   s   ù	rF   c                 C   s   t  | ¡pdS )Nr   )Ú	sysconfigÚget_config_var)r    r   r   r   Ú_get_sysconfig_varw   s   rI   c                   C   s(   dt dƒdfdt dƒdfdt dƒdfgS )NÚpython_soabiÚSOABIÚunknownÚpython_host_gnu_typeÚHOST_GNU_TYPEÚpython_build_gnu_typeÚBUILD_GNU_TYPE)rI   r   r   r   r   Úget_python_config_vars{   s   ýrQ   )"r   r*   rG   Útypingr   r   Úddtrace.internalr   Úddtrace.internal.constantsr   Úddtrace.internal.packagesr   Ú"ddtrace.internal.runtime.containerr   Úddtrace.internal.utils.cacher   Úddtrace.versionr	   r>   r   Ústrr   r   r   ÚtupleÚdictr2   Úlistr;   r<   rC   rF   rI   rQ   r   r   r   r   Ú<module>   s.    . 