o
    i	                     @   sD  d 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 e	eZdZzeejv rReeeeeZW n eyc   edee Y nw dd ZeZzeejv rzeeeeeZW n ey   edee Y nw dd ZdedefddZdefddZdS )a  
This module contains the logic to configure ddtrace products from a configuration endpoint.
The configuration endpoint is a URL that returns a JSON object with the configuration for the products.
It takes precedence over environment variables and configuration files.
    N)_CONFIG_ENDPOINT_ENV)_CONFIG_ENDPOINT_RETRIES_ENV)_CONFIG_ENDPOINT_TIMEOUT_ENV)DEFAULT_TIMEOUT)
get_logger)Response)get_connection)
verify_url)fibonacci_backoff_with_jitter   z-Invalid value for %s. Using default value: %sc                   C      t S N)RETRIES r   r   ]/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/settings/endpoint_config.py_get_retries      r   c                   C   r   r   )TIMEOUTr   r   r   r   _get_timeout*   r   r   urlreturnc                 C   sT   z$t | }|j}t| t d}|d| | }t|}W |  |S |  w )N)timeoutGET)	r	   pathr   r   requestgetresponser   from_http_responseclose)r   
parsed_urlurl_pathconnresponseresultr   r   r   _do_request.   s   
r#   c                  C   sf   t td} | du ri S ztt ddd dt| }| p i W S  ty2   tj	ddd Y i S w )	zB
    Fetch the configuration from the configuration endpoint.
    Ng?c                 S   s$   t | dod| j  kodk S   S )Nstatus   i,  )hasattrr$   )respr   r   r   <lambda>J   s   $ z,fetch_config_from_endpoint.<locals>.<lambda>)attemptsinitial_waituntilz+Failed to fetch configuration from endpointT)exc_info)
osgetenvr   r
   r   r#   get_json	Exceptionlogerror)config_endpointresr   r   r   fetch_config_from_endpoint;   s$   r5   )__doc__r-   ddtrace.constantsr   r   r   ddtrace.internal.constantsr   ddtrace.internal.loggerr   ddtrace.internal.utils.httpr   r   r	   ddtrace.internal.utils.retryr
   __name__r1   r   environintr.   str
ValueErrorr2   r   r   r   r#   dictr5   r   r   r   r   <module>   s@    

