o
    Zh                     @   s   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 d dlmZmZmZmZ d dlmZ er<d dlmZ zd d	lmZmZmZmZ W n eyU   ed
w dgZG dd deZdd Zdd ZdS )    )Hub)OPSPANDATA)IntegrationDidNotEnable)BAGGAGE_HEADER_NAME)should_propagate_trace)SENSITIVE_DATA_SUBSTITUTEcapture_internal_exceptionslogger	parse_url)TYPE_CHECKING)Any)AsyncClientClientRequestResponsezhttpx is not installedHttpxIntegrationc                   @   s   e Zd ZdZedd ZdS )r   httpxc                   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   T/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/integrations/httpx.py
setup_once   s   
zHttpxIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r      s    c                        t j  fdd} | t _d S )Nc           	   	      s  t j}|td u r | |fi |S d }t  tt|jdd}W d    n1 s,w   Y  |jt	j
d|j|r=|jntf d{}|tj|j |d urg|d|j |tj|j |tj|j t|t|jr| D ]+\}}tdj|||jd |tkr|jtr|j|  d| 7  < qs||j|< qs | |fi |}||j |d	|j |W  d    S 1 sw   Y  d S 
NF)sanitizez%s %s)opdescriptionurlzE[Tracing] Adding `{key}` header {value} to outgoing request to {url}.)keyvaluer$   ,reasonr   currentZget_integrationr   r
   r   strr$   Z
start_spanr   ZHTTP_CLIENTmethodr	   set_datar   ZHTTP_METHODZ
HTTP_QUERYqueryZHTTP_FRAGMENTfragmentr   Ziter_trace_propagation_headersr   debugformatr   headersgetZset_http_statusstatus_codeZreason_phrase	selfrequestkwargsZhub
parsed_urlspanr%   r&   rvZ	real_sendr   r   send-   sL   $z#_install_httpx_client.<locals>.send)r   r=   r=   r   r<   r   r   )      
.r   c                     r   )Nc           	   	      s  t j}|td u r | |fi |I d H S d }t  tt|jdd}W d    n1 s0w   Y  |jt	j
d|j|rA|jntf d~}|tj|j |d urk|d|j |tj|j |tj|j t|t|jr| D ]+\}}tdj|||jd |tkr|jtr|j|  d| 7  < qw||j|< qw | |fi |I d H }||j |d	|j |W  d    S 1 sw   Y  d S r    r)   r5   r<   r   r   r=   b   sN   $z)_install_httpx_async_client.<locals>.send)r   r=   r>   r   r<   r   r   ^   r?   r   N)Z
sentry_sdkr   Zsentry_sdk.constsr   r   Zsentry_sdk.integrationsr   r   Zsentry_sdk.tracingr   Zsentry_sdk.tracing_utilsr   Zsentry_sdk.utilsr	   r
   r   r   Zsentry_sdk._typesr   typingr   r   r   r   r   r   ImportError__all__r   r   r   r   r   r   r   <module>   s$    5