o
    i                     @   sf   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
 G dd	 d	eZG d
d dZdS )    N)Optional)AttrDict)DDTraceDeprecationWarning)	deprecate   )
HttpConfigc                       s   e Zd ZdZ fddZdZdd Zedd Zed	e	fd
dZ
ded	e	fddZded	ee fddZ fddZ fddZdddZdd Zdd Z  ZS )IntegrationConfiga}  
    Integration specific configuration object.

    This is what you will get when you do::

        from ddtrace import config

        # This is an `IntegrationConfig`
        config.flask

        # `IntegrationConfig` supports both attribute and item accessors
        config.flask['service_name'] = 'my-service-name'
        config.flask.service_name = 'my-service-name'
    c              
      s   t t| j|i | t| d| t| d| t| dt  t| dt  | dd | dd tj	d	|
  tj	d
|
  ddd}| d| | d| t| d| t| dd dS )zw
        :param global_config:
        :type global_config: Config
        :param args:
        :param kwargs:
        global_configintegration_namehttphooksanalytics_enabledFanalytics_sample_rateg      ?zDD_%s_SERVICEzDD_%s_SERVICE_NAMEN)defaultserviceservice_namehttp_tag_query_stringdefault_http_tag_query_string)superr   __init__object__setattr__r   Hooks
setdefaultosgetenvupperget_http_tag_query_stringgetattr)selfr	   nameargskwargsr   	__class__ Y/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/settings/integration.pyr      s*   

zIntegrationConfig.__init__)r   r   c                 C   s,   | j jr|r|ntdd}| dvS dS )NDD_HTTP_SERVER_TAG_QUERY_STRINGtrue)false0F)r	   _http_tag_query_stringr   r   lower)r   valuedd_http_server_tag_query_stringr%   r%   r&   r   E   s   z+IntegrationConfig.get_http_tag_query_stringc                 C   s   | j jd ur
| j jS | jjjS N)r   trace_query_stringr	   _httpr   r%   r%   r&   r0   L   s   
z$IntegrationConfig.trace_query_stringreturnc                 C   s   | j jp| jjjS )zReturns whether header tracing is enabled for this integration.

        Will return true if traced headers are configured for this integration
        or if they are configured globally.
        )r   is_header_tracing_configuredr	   r1   r2   r%   r%   r&   r4   R   s   z.IntegrationConfig.is_header_tracing_configuredheader_namec                 C   s   |  |duS )z;Returns whether or not the current header should be traced.N)_header_tag_name)r   r5   r%   r%   r&   header_is_traced[   s   z"IntegrationConfig.header_is_tracedc                 C   s$   | j |}|d u r| j|S |S r/   )r   r6   r	   )r   r5   tag_namer%   r%   r&   r6   _   s   z"IntegrationConfig._header_tag_namec                    s   t  |S r/   )r   __getattr__)r   keyr#   r%   r&   r9   e      zIntegrationConfig.__getattr__c                    s   t  ||S r/   )r   r   )r   r:   r-   r#   r%   r&   r   h   s   zIntegrationConfig.__setattr__Fc                 C   s   dS )Nr   r%   )r   use_global_configr%   r%   r&   get_analytics_sample_ratek      z+IntegrationConfig.get_analytics_sample_ratec                 C   s.   | j }d|  }|j d|j d| dS )Nz, .())r$   joinkeys
__module____name__)r   clsrC   r%   r%   r&   __repr__n   s   zIntegrationConfig.__repr__c                 C   s   |  | j| j}||  |S r/   )r$   r	   r
   update)r   new_instancer%   r%   r&   copys   s   
zIntegrationConfig.copy)F)rE   rD   __qualname____doc__r   APP_ANALYTICS_CONFIG_NAMESr   propertyr0   boolr4   strr7   r   r6   r9   r   r=   rG   rJ   __classcell__r%   r%   r#   r&   r      s     (

r   c                   @   s4   e Zd ZdZdddZdddZdd Zd	d
 ZdS )r   z9Deprecated no-op Hooks class for backwards compatibility.Nc                 C   s$   t dddtd |sdd }|S d S )Nz8Hooks.register() is deprecated and is currently a no-op.zJTo interact with spans, use get_current_span() or get_current_root_span().5.0.0messageremoval_versioncategoryc                 S   s   | S r/   r%   )funcr%   r%   r&   wrapper   r>   zHooks.register.<locals>.wrapperr   r   )r   hookrW   rX   r%   r%   r&   register|   s   zHooks.registerc                 C   s   |  ||S r/   )r[   r   rZ   rW   r%   r%   r&   on   r;   zHooks.onc                 C   s   t ddtd d S )Nz:Hooks.deregister() is deprecated and is currently a no-op.rR   )rU   rV   rY   r\   r%   r%   r&   
deregister   s   zHooks.deregisterc                 O   s   t dddtd d S )NzHooks.emit() is deprecatedzIUse tracer.current_span() or TraceFilters to retrieve and/or modify spansrR   rS   rY   )r   rZ   r!   r"   r%   r%   r&   emit   s   z
Hooks.emitr/   )rE   rD   rK   rL   r[   r]   r^   r_   r%   r%   r%   r&   r   y   s    

r   )r   typingr   ddtrace.internal.utils.attrdictr   #ddtrace.internal.utils.deprecationsr   ddtrace.vendor.debtcollectorr   r   r   r   r   r%   r%   r%   r&   <module>   s    n