o
    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   Z/home/ubuntu/veenaModal/venv/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sanitize%s %sopnamer#   urlE[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spanr1   r2   rv	real_sendr   r   send2   sT   
$

z#_install_httpx_client.<locals>.send)r%   r   r&   r   r'   r   r   r   )r   rM   r   r   rM   r   rK   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}|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r|jtr|j|  d| 7  < 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 )
NFr(   r*   r+   r.   r/   r0   ,r3   )"r=   r>   get_integrationr   r   r   r4   r.   r   r   r5   r6   r   r#   r7   r   r8   r9   r:   r;   r<   r   r?   r@   r   rA   rB   r   rC   getrD   rE   rF   r	   rG   rK   r   r   rM   g   s^   
&

z)_install_httpx_async_client.<locals>.send)r%   r   r&   r   r'   r   r   r   )r   rM   rN   r   rK   r   r   d   s   
5r   r   )!r=   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