o
    h                     @   s   d dl 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 d dlmZmZmZmZmZ d dlmZ erDd dlmZ d 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 Zdd Z dd Z!dS )    N)OPSPANDATA)IntegrationDidNotEnable)BAGGAGE_HEADER_NAME)Baggageshould_propagate_trace)SENSITIVE_DATA_SUBSTITUTEcapture_internal_exceptionsensure_integration_enabledlogger	parse_url)TYPE_CHECKING)MutableMapping)Any)AsyncClientClientRequestResponsezhttpx is not installedHttpxIntegrationc                   @   s&   e Zd ZdZde Zedd ZdS )r   httpxz
auto.http.c                   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   _/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/sentry_sdk/integrations/httpx.py
setup_once!   s   
zHttpxIntegration.setup_onceN)__name__
__module____qualname__
identifieroriginstaticmethodr   r   r   r   r   r      s
    
c                     s&   t j tt  fdd} | t _d S )Nc              	      s`  d }t   tt|jdd}W d    n1 sw   Y  tjtjd|j|r*|jnt	f t
jdt}|tj|j |d urV|d|j |tj|j |tj|j tt t|jrt  D ] \}}tdj|||jd |tkrt|j| qf||j|< qf | |fi |}||j |d|j |W  d    S 1 sw   Y  d S )	NFsanitize%s %sopnamer    urlE[Tracing] Adding `{key}` header {value} to outgoing request to {url}.keyvaluer(   reason) r
   r   strr(   
sentry_sdk
start_spanr   HTTP_CLIENTmethodr	   r   r    set_datar   HTTP_METHOD
HTTP_QUERYqueryHTTP_FRAGMENTfragmentr   
get_clientget_current_scopeiter_trace_propagation_headersr   debugformatr   _add_sentry_baggage_to_headersheadersset_http_statusstatus_codereason_phraseselfrequestkwargs
parsed_urlspanr+   r,   rv	real_sendr   r   send0   sJ   
$z#_install_httpx_client.<locals>.send)r   rL   r   r   rL   r   rJ   r   r   ,   s   
,r   c                     s   t j  fdd} | t _d S )Nc              	      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 jt	j
d|j|r@|jntf tjd}|tj|j |d url|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    S 1 sw   Y  d S )
NFr"   r$   r%   r(   r)   r*   ,r-   )!r/   r9   get_integrationr   r
   r   r.   r(   r0   r   r1   r2   r	   r    r3   r   r4   r5   r6   r7   r8   r   r:   r;   r   r<   r=   r   r?   getr@   rA   rB   rC   rJ   r   r   rL   d   sT   
$z)_install_httpx_async_client.<locals>.send)r   rL   rM   r   rJ   r   r   `   s   
1r   c                 C   s>   |  td}t|}t|dkrdnd}|| | | t< dS )zAdd the Sentry baggage to the headers.

    This function directly mutates the provided headers. The provided sentry_baggage
    is appended to the existing baggage. If the baggage already contains Sentry items,
    they are stripped out first.
     r   rN   N)rP   r   r   strip_sentry_baggagelen)r?   sentry_baggageexisting_baggagestripped_existing_baggage	separatorr   r   r   r>      s
   


r>   )"r/   sentry_sdk.constsr   r   sentry_sdk.integrationsr   r   sentry_sdk.tracingr   sentry_sdk.tracing_utilsr   r   sentry_sdk.utilsr	   r
   r   r   r   typingr   collections.abcr   r   r   r   r   r   r   ImportError__all__r   r   r   r>   r   r   r   r   <module>   s(    48