o
    i                     @   s   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
lmZ d dlmZ d dlmZ d dlmZ G dd deZdS )    )	HTTPError)HTTPResponse)request)response)config)	SpanTypes)core)schematize_url_operation)SpanDirection)DDTraceDeprecationWarning)asbool)tracer)	deprecatec                   @   s@   e Zd ZdZdZdddZedd Zejd	d Zd
d Z	dS )TracePlugintrace   bottleNc                 C   s>   |d urt ddtdd tj|d| _|d ur|tj_d S d S )Nz"The tracer parameter is deprecatedz'The global tracer will be used instead.z5.0.0)messagecategoryremoval_version)default)r   r   r   _get_serviceservicer   distributed_tracing)selfr   r   r    r   Y/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/contrib/internal/bottle/trace.py__init__   s   zTracePlugin.__init__c                 C   s   t jjS )N)r   r   r   )r   r   r   r   r   !   s   zTracePlugin.distributed_tracingc                 C   s   t |tjd< d S )Nr   )r   r   r   )r   r   r   r   r   r   %   s   c                    s    fdd}|S )Nc                     s.  t rt js | i |S dtjj}tjdtddt	j
dtjj|i tjtjddd
}|j}|d| td|tjf d }d }zuzY | i |}|W W t|trZ|j}n|r_|}ntj}tj}tjjd	d
 }	dtjdjdg}
td|tj||	|tjtjtj|
df
 W  d    W  d    S  t tfy } z|j} d }~w t!y   d} w t|tr|j}n|r|}ntj}tj}tjjd	d
 }	dtjdjdg}
td|tj||	|tjtjtj|
df
 w 1 sw   Y  W d    d S 1 sw   Y  d S )Nz{} {}zbottle.requesthttp)protocol	directionT)		span_name	span_typer   resourcetagsdistributed_headersintegration_configheaders_case_sensitiveactivate_distributed_headersreq_spanzweb.request.start )query/zweb.request.finishFi  )"r   enabledformatr   methodruler   context_with_datar	   r
   INBOUNDr   WEBr   headersr   r   spanset_itemdispatch
isinstancer   status_coder   urlparts_replacegeturljoinscript_namerstriplstripquery_stringr   	Exception)argskwargsr#   ctxr)   coderesultresponse_coder/   url
full_routeecallbackrouter   r   r   wrapped*   s   


6z"TracePlugin.apply.<locals>.wrappedr   )r   rM   rN   rO   r   rL   r   apply)   s   IzTracePlugin.apply)r   NN)
__name__
__module____qualname__nameapir   propertyr   setterrP   r   r   r   r   r      s    


r   N)r   r   r   r   r   ddtracer   ddtrace.extr   ddtrace.internalr   ddtrace.internal.schemar	   -ddtrace.internal.schema.span_attribute_schemar
   #ddtrace.internal.utils.deprecationsr   ddtrace.internal.utils.formatsr   ddtrace.tracer   ddtrace.vendor.debtcollectorr   objectr   r   r   r   r   <module>   s    