˺h dZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZmZmZmZmZddlmZer&dd lmZdd lmZdd lmZdd lmZdd lmZddlmZmZedZdZdZ dZ!GddZ"dS)zf An ASGI middleware. Based on Tom Christie's `sentry-asgi `_. N)partial)MYPY)Hub_should_send_default_pii)_filter_headers) ContextVarevent_from_exceptiontransaction_from_functionHAS_REAL_CONTEXTVARSCONTEXTVARS_ERROR_MESSAGE) Transaction)Dict)Any)Optional)Callable)Literal)EventHintsentry_asgi_middleware_appliedzgeneric ASGI requestc|j;t||jjddd\}}|||dSdS)NasgiF)typehandled)client_options mechanism)hint)clientr options capture_event)hubexceventrs |/builddir/build/BUILD/imunify360-venv-2.5.2/opt/imunify360/venv/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py_capture_exceptionr$(sc z* :-%%88   t %d+++++ ctj|rt|dStj|rt j|St |dd}t j|S)z Try to figure out if an application object supports ASGI3. This is how uvicorn figures out the application version as well. __await____call__N)inspectisclasshasattr isfunctionasyncioiscoroutinefunctiongetattr)appcalls r#_looks_like_asgi3r25sls1sK(((  C 1*3///sJ--*4000r%cDeZdZdZd dZdZdZdZdZdZ d Z d Z d S) SentryAsgiMiddleware)r0r(Fc|ststdtz||_t |r|j|_dS|j|_dS)ab Instrument an ASGI application with Sentry. Provides HTTP/websocket data to sent events and basic handling for exceptions bubbling up through the middleware. :param unsafe_context_data: Disable errors when a proper contextvars installation could not be found. We do not recommend changing this from the default. zRThe ASGI middleware for Sentry requires Python 3.7+ or the aiocontextvars package.N)r RuntimeErrorr r0r2 _run_asgi3r( _run_asgi2)selfr0unsafe_context_datas r#__init__zSentryAsgiMiddleware.__init__Hsi# +? 13LM  S ! ! , ODMMM ODMMMr%cfd}|S)NcPKfdd{VS)NcBSNr0receivescoper9sendsr#z@SentryAsgiMiddleware._run_asgi2..inner..dsodhhuoogt6T6Tr%_run_app)rBrDrCr9s``r#innerz.SentryAsgiMiddleware._run_asgi2..innerbsBu.T.T.T.T.T.T.TUUUUUUUU Ur%)r9rCrHs`` r#r8zSentryAsgiMiddleware._run_asgi2`s/ V V V V V V r%cRKfdd{VS)Nc2Sr?r@rAsr#rEz1SentryAsgiMiddleware._run_asgi3..js$((5'42P2Pr%rF)r9rCrBrDs````r#r7zSentryAsgiMiddleware._run_asgi3hsC]]5*P*P*P*P*P*P*PQQQQQQQQQr%cKtd}|r@ |d{VS#t$r"}ttj||dd}~wwxYwtd t tj}|5|5}|d|_ t|j |}| |dddn #1swxYwY|d}|dvr=tjt|dd| } ntd } t"| _| d ||| 5 |d{V cdddcdddtdS#t$r}t|||dd}~wwxYw#1swxYwY dddn #1swxYwYtddS#tdwxYw) NFTr) asgi_scoperhttp websocketheadersz {}.server)opz asgi.serverz asgi.type)_asgi_middleware_appliedget Exceptionr$rcurrentsetconfigure_scopeclear_breadcrumbs_namerevent_processoradd_event_processorr continue_from_headersdictformat_DEFAULT_TRANSACTION_NAMEnameset_tagstart_transaction) r9rCcallbackis_recursive_asgi_middlewarer!r sentry_scope processorty transactions r#rGzSentryAsgiMiddleware._run_applsx'?'C'CE'J'J$ ' $ $%XZZ''''''' $ $ $"3;444t# $ !$$T*** 0ck""C , ,((**@l 22444)/L& '(< O O OI 44Y??? @@@@@@@@@@@@@@@ 6]..."-"CU9-..&--b11###KK #."?"?"?K#<  ##K444**;77,,,%-XZZ/////// ,,,,,,,) , , , , , , ,< % ( ( / / / / %,,,*3444!t+, ,,,,,,,,,) , , , , , , , , , , , , , , ,< % ( ( / / / / / $ ( ( / / / /s0 AAA:IH*AC=1 H=D HD BHHG* H6 I G?'G::G??HH H H H IHI!H"IIcj|di}|d}|dvr|d|d<t||x|d<}|||d<|||dkrdnd|d |d <|d }|rt r d |d i|d<|dt t kr)|d}|rt||d<||d<|S)NrequestrrNmethodrQ query_stringrOwshosturlr REMOTE_ADDRrenvriendpoint)rTr _get_headers _get_query_get_urlrr`r ) r9r"rrM request_inforhrQrrss r#r[z$SentryAsgiMiddleware.event_processorsXyyB//   & & &%/^^H%=%=L "0?!!*--11 L #g,0??:+F+FL ("&--bFllFFgkk&>Q>Q##L ))  =.00 =#0&)" ? ?( ) )"~~j11H K'@'J'Jm$'i r%c,|d|}|dd}|dd|ddz}|r |d||S|-|\}}dd dd d |}||kr |d|d ||S|d||S|S) zZ Extract URL from the ASGI scope, without also including the querystring. schemeserverN root_pathpathz://Pi)rOhttpsrnwss:)rT) r9rCdefault_schemeroryrzr}port default_ports r#rvzSentryAsgiMiddleware._get_urls 8^448T**yyb))EIIfb,A,AA  6"(&&$$5 5  JD$$&BsKKFSL|##)/ttTTBB"(&&$$5 5 r%c|d}|sdStj|dS)zj Extract querystring from the ASGI scope, in the format that the Sentry protocol expects. rmNlatin-1)rTurllibparseunquotedecode)r9rCqss r#ruzSentryAsgiMiddleware._get_querysD YY~ & & 4|##BIIi$8$8999r%ci}|dD]J\}}|d}|d}||vr||dz|z||<E|||<K|S)zf Extract headers from the ASGI scope, in the format that the Sentry protocol expects. rQrz, )r)r9rCrQraw_key raw_valuekeyvalues r#rtz!SentryAsgiMiddleware._get_headerssx "' "2 % % GY..++C$$Y//Eg~~&s|d2U: $ r%N)F) __name__ __module__ __qualname__ __slots__r;r8r7rGr[rvrurtrIr%r#r4r4Es#I,,,,0RRR,0,0,0\!!!R*:::     r%r4)#__doc__r-r)rsentry_sdk._functoolsrsentry_sdk._typesrsentry_sdk.hubrr$sentry_sdk.integrations._wsgi_commonrsentry_sdk.utilsrr r r r sentry_sdk.tracingr typingrrrrtyping_extensionsrrrrSr`r$r2r4rIr%r#rs  ))))))""""""88888888@@@@@@+*****.))))))--------&:&FGG2 , , , 1 1 1 jjjjjjjjjjr%