U \1@sddlZddlZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z mZmZddlZddlmZmZGd d d eZd d Zd dZdS)N)reraise)Hub) Integration) ignore_logger)_filter_headers)capture_internal_exceptionsevent_from_exceptionHAS_REAL_CONTEXTVARS) Application HTTPExceptionc@seZdZdZeddZdS)AioHttpIntegrationaiohttpcs0ts tdtdtjfdd}|t_dS)NzRThe aiohttp integration for Sentry requires Python 3.7+ or aiocontextvars packagezaiohttp.servercs*fdd}t|IdHS)Nc stj}|tdkr,fIdHSt}ttj}|}||t |W5QRXzIdH}Wn4t k rYn t k rt t |YnX|W5QRSQRXdS)N)rZcurrentZget_integrationr weakrefrefZconfigure_scopeZclear_breadcrumbsZadd_event_processor_make_request_processorr Exceptionr_capture_exception)hub weak_requestZscopeZresponse)argskwargs old_handlerequestself /aiohttp.pyinner0s   zGAioHttpIntegration.setup_once..sentry_app_handle..inner)asyncioZget_event_loopZ create_task)rrrrrr)rrrrrsentry_app_handle.sz8AioHttpIntegration.setup_once..sentry_app_handle)r RuntimeErrorrr Z_handle)rrrr setup_onces zAioHttpIntegration.setup_onceN)__name__ __module__ __qualname__Z identifier staticmethodr!rrrrr sr csfdd}|S)Nc s}|dkr|St^|di}d|j|j|jf|d<|j|d<|j|d<d|ji|d<tt |j |d<W5QRX|S) Nrz %s://%s%sZurl query_stringmethodZ REMOTE_ADDRenvheaders) r setdefaultZschemeZhostpathr&r'Zremoterdictr))eventhintrZ request_inforrraiohttp_processorPs    z2_make_request_processor..aiohttp_processorr)rr0rr/rrNs rcCs6t}t||jjdddd\}}|j||d|S)Nr F)typeZhandled)Zclient_optionsZ mechanism)r.)sysexc_inforZclientZoptionsZ capture_event)rr3r-r.rrrros r)r2rZsentry_sdk._compatrZsentry_sdk.hubrZsentry_sdk.integrationsrZsentry_sdk.integrations.loggingrZ$sentry_sdk.integrations._wsgi_commonrZsentry_sdk.utilsrrr rZ aiohttp.webr r ZRequestZAnyZDictZTupleCallableZExcInfor rrrrrrs      2!