o
    iF                     @   s   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Zd	Zd
ZdZdZedZdeeef defddZdddefddZdddefddZG dd deZe ZdefddZdefddZdS )    N)Optional)TypeVar)Union)urlparse)DEFAULT_TIMEOUT)DDConfig	localhosti  /var/run/datadog/apm.socket/var/run/datadog/dsd.socketi  Thostnamereturnc                 C   s:   t | tsdS z
ttj|  W dS  tjy   Y dS w )NFT)
isinstancestrsocket	inet_ptonAF_INET6error)r    r   T/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/settings/_agent.pyis_ipv6_hostname   s   
r   configAgentConfigc                 C   s   | j p| j}| jp| j}| j}|sG|d us|d ur3|pt}|p t}t|r+d| d}d||f }|S tj	
dr?dt }|S dt dt }|S )N[]zhttp://%s:%sr	   	unix://%szhttp://:)_trace_agent_hostname_agent_host_trace_agent_port_agent_port_trace_agent_urlDEFAULT_HOSTNAMEDEFAULT_TRACE_PORTr   ospathexistsDEFAULT_UNIX_TRACE_PATH)r   user_supplied_hostuser_supplied_porturlhostportr   r   r   _derive_trace_url    s    r-   c                 C   s   | j p| j}| jp| j}| j}|sI|d us|d ur5|pt}|p t}t|r+d| d}d| d| }|S tj	
drAdt }|S dt dt }|S )Nr   r   zudp://r   r
   r   )_dogstatsd_hostr   _dogstatsd_portr    _dogstatsd_urlDEFAULT_STATS_PORTr"   r   r$   r%   r&   DEFAULT_UNIX_DSD_PATH)r   r(   r)   r*   r,   r+   r   r   r   _derive_stats_url4   s    r3   c                   @   s  e Zd ZdZejee dddddZejee	 dddd	dZ
ejee d
ddddZejededddZejee dddddZejee	 dddddZejee dddddZejee dddddZejee	 dddddZejedddddZeeeZeeeZdS )r   ddtrace_agent_hostnameNStringz<Legacy configuration, stores the hostname of the trace agent)default	help_typehelptrace_agent_portIntz8Legacy configuration, stores the port of the trace agenttrace_agent_urlz!Stores the URL of the trace agenttrace_agent_timeout_secondsFloatz1Stores the timeout in seconds for the trace agentdogstatsd_hostz<Stores the hostname of the agent receiving DogStatsD metricsdogstatsd_portz8Stores the port of the agent receiving DogStatsD metricsdogstatsd_urlz%Stores the URL of the DogStatsD agent
agent_hostz Stores the hostname of the agent
agent_portzStores the port of the agenttrace_native_span_eventsFBooleanz-Stores whether native span events are enabled)__name__
__module____qualname__
__prefix__r   vr   r   r   intr   r!   floatr   r=   r.   r/   r0   r   r    boolrD   dr-   r<   r3   rA   r   r   r   r   r   G   s    c                  C      t tj} | jr| jS tS )zO
    Returns the hostname of the agent using the resolved trace_agent_url.
    )r   r   r<   r   r"   r*   r   r   r   get_agent_hostname      
rQ   c                  C   rO   )zK
    Returns the port of the agent using the resolved trace_agent_url.
    )r   r   r<   r,   r#   rP   r   r   r   get_agent_port   rR   rS   )r$   r   typingr   r   r   urllib.parser   ddtrace.internal.constantsr   ddtrace.internal.settings._corer   r"   r#   r'   r2   r1   r   r   rM   r   r-   r3   r   r   rQ   rK   rS   r   r   r   r   <module>   s*    
X
