o
    S۷i'                     @   s   d dl Z d dl mZ d dlmZmZ d dlmZmZ d dlm	Z	 d dl
mZmZmZ d dlmZmZmZmZmZ d dlmZ erFd d	lmZ zd d
lmZmZmZmZ W n ey_   edw dgZG dd deZdddZdddZ dS )    N)
start_span)OPSPANDATA)IntegrationDidNotEnable)BAGGAGE_HEADER_NAME)should_propagate_traceadd_http_request_sourceadd_sentry_baggage_to_headers)SENSITIVE_DATA_SUBSTITUTEcapture_internal_exceptionsensure_integration_enabledlogger	parse_url)TYPE_CHECKING)Any)AsyncClientClientRequestResponsezhttpx is not installedHttpxIntegrationc                   @   s(   e Zd ZdZde ZedddZdS )r   httpxz
auto.http.returnNc                   C   s   t   t  dS )z
        httpx has its own transport layer and can be customized when needed,
        so patch Client.send and AsyncClient.send to support both synchronous and async interfaces.
        N)_install_httpx_client_install_httpx_async_client r   r   S/home/ubuntu/vllm_env/lib/python3.10/site-packages/sentry_sdk/integrations/httpx.py
setup_once%   s   
zHttpxIntegration.setup_oncer   N)__name__
__module____qualname__
identifieroriginstaticmethodr   r   r   r   r   r   !   s
    
r   c                     s(   t j tt d fd	d
} | t _d S )Nselfr   requestr   kwargsr   r   r   c              	      s  d }t   tt|jdd}W d    n1 sw   Y  ttjd|j|r)|jntf t	j
dr}|tj|j |d urU|d|j |tj|j |tj|j tt t|jrt  D ] \}}tdj|||jd |tkrt|j| qe||j|< qe | |fi |}||j |d|j W d    n1 sw   Y  t   t | W d    |S 1 sw   Y  |S 	NF)sanitizez%s %s)opnamer#   urlzE[Tracing] Adding `{key}` header {value} to outgoing request to {url}.)keyvaluer,   reason)!r   r   strr,   r   r   HTTP_CLIENTmethodr   r   r#   set_datar   HTTP_METHOD
HTTP_QUERYqueryHTTP_FRAGMENTfragmentr   
sentry_sdk
get_clientget_current_scopeiter_trace_propagation_headersr   debugformatr   r
   headersset_http_statusstatus_codereason_phraser	   r%   r&   r'   
parsed_urlspanr-   r.   rv	real_sendr   r   send2   sT   
$

z#_install_httpx_client.<locals>.send)r%   r   r&   r   r'   r   r   r   )r   rI   r   r   rI   r   rG   r   r   /   s   
.r   c                     s.   t j 								d fd	d
} | t _d S )Nr%   r   r&   r   r'   r   r   r   c              	      s  t  td u r | |fi |I d H S d }t  tt|jdd}W d    n1 s/w   Y  tt	j
d|j|r?|jntf tjdu}|tj|j |d urk|d|j |tj|j |tj|j tt  t|jrt   D ] \}}tdj|||jd |tkrt|j| q{||j|< q{ | |fi |I d H }||j |d|j  W d    n1 sw   Y  t  t!| W d    |S 1 sw   Y  |S r(   )"r9   r:   get_integrationr   r   r   r0   r,   r   r   r1   r2   r   r#   r3   r   r4   r5   r6   r7   r8   r   r;   r<   r   r=   r>   r   r
   r?   r@   rA   rB   r	   rC   rG   r   r   rI   g   sZ   
#

z)_install_httpx_async_client.<locals>.send)r%   r   r&   r   r'   r   r   r   )r   rI   rJ   r   rG   r   r   d   s   
2r   r   )!r9   r   sentry_sdk.constsr   r   sentry_sdk.integrationsr   r   sentry_sdk.tracingr   sentry_sdk.tracing_utilsr   r	   r
   sentry_sdk.utilsr   r   r   r   r   typingr   r   r   r   r   r   r   ImportError__all__r   r   r   r   r   r   r   <module>   s&    
5