o
    h                     @   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   `/var/www/html/aiguide_backend/venv/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   currentget_integrationr   r
   r   strr$   
start_spanr   HTTP_CLIENTmethodr	   set_datar   HTTP_METHOD
HTTP_QUERYqueryHTTP_FRAGMENTfragmentr   iter_trace_propagation_headersr   debugformatr   headersgetset_http_statusstatus_codereason_phrase	selfrequestkwargshub
parsed_urlspanr%   r&   rv	real_sendr   r   send-   sL   $z#_install_httpx_client.<locals>.send)r   rH   rH   r   rF   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)   r>   rF   r   r   rH   b   sN   $z)_install_httpx_async_client.<locals>.send)r   rH   rI   r   rF   r   r   ^   rJ   r   N)
sentry_sdkr   sentry_sdk.constsr   r   sentry_sdk.integrationsr   r   sentry_sdk.tracingr   sentry_sdk.tracing_utilsr   sentry_sdk.utilsr	   r
   r   r   sentry_sdk._typesr   typingr   r   r   r   r   r   ImportError__all__r   r   r   r   r   r   r   <module>   s$    5