mf iddlZddlZddlZddlZddlZddlZddlZddlmZddlZddl m Z m Z m Z m Z ddlmZerVddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZm Z edddZ!ej"dZ#dZ$dZ%dZ&dZ'dZ( dSdZ)Gdde*Z+e+Z,dZ-dZ.d Z/d!Z0dSd"Z1Gd#d$e2Z3e Gd%d&e*Z4Gd'd(e*Z5Gd)d*e*Z6erdd+lm7Z7e7d,Z8ee6e8fZ9d-Z:d.Z;d/Zd2Z?d3Z@e rd4ZAnd5ZAd6ZBdUd8ZCdVd9ZDd:ZE dTd;ZFeGeHd<ZIeIrd=ZJnd>ZJ dTd?ZKd@ZLdAZMdBZNdTdCZOdDZPdEZQ dTdFZRdGZSdSdHZTdIZUdJZVdKZWeW\ZXZYdLZZdMZ[eYdNZ\GdOdPeHZ]GdQdRej^Z_dS)WN)datetime)urlparse text_typeimplements_strPY2)MYPY) FrameType) TracebackType)Any)Callable)Dict)ContextManager)Iterator)List)Optional)Set)Tuple)Union)Type)ExcInfo EndpointTypeizsentry_sdk.errorsicVtj|dddS)zCSerialize data into a compact JSON representation encoded as UTF-8.F),:) allow_nan separatorsutf-8)jsondumpsencode)datas G/opt/imunify360/venv/lib64/python3.11/site-packages/sentry_sdk/utils.py json_dumpsr%,s) :de C C C J J7 S SScdSNr)r&r$_get_debug_hubr*2s  Dr&c$tjd}|r|Sttjjd5} t jgdt j|| d d}n#ttf$rYnwxYw|r|cdddS dddn #1swxYwYdD]'}tj|}|r|cS(dS) zTry to guess a default release.SENTRY_RELEASEzw+)gitz rev-parsez--shortHEAD)stdoutstderrstdinrrN)HEROKU_SLUG_COMMITSOURCE_VERSION!CODEBUILD_RESOLVED_SOURCE_VERSION CIRCLE_SHA1GAE_DEPLOYMENT_ID)osenvirongetopenpathdevnull subprocessPopenPIPE communicatestripdecodeOSErrorIOError)releasenullvars r$get_default_releaserH8sjnn-..G bgot $ $  ;;;%?  q " G!    D   #  !&  *..%%  NNN  4s7CA!B'&C'B;8C:B;;CC"CcTtjd}|r|S|dSdS)NSENTRY_ENVIRONMENT production)r7r8r9)rErvs r$get_default_environmentrM_s5 , - -B  | 4r&ceZdZdZdZdZdS)CaptureInternalExceptionr)c|Sr(r)selfs r$ __enter__z"CaptureInternalException.__enter__ns r&c2||t|||fdSNT)capture_internal_exception)rRtyvaluetbs r$__exit__z!CaptureInternalException.__exit__rs% >e/ &E2 7 7 7tr&N)__name__ __module__ __qualname__ __slots__rSrZr)r&r$rOrOks7Ir&rOctSr()_CAPTURE_INTERNAL_EXCEPTIONr)r&r$capture_internal_exceptionsra}s &&r&cTt}|||dSdSr()r*_capture_internal_exception)exc_infohubs r$rVrVs3   C  ''11111r&c:|tz Sr()epoch total_secondsrXs r$ to_timestamprjs EM ( ( * **r&c,|dS)Nz%Y-%m-%dT%H:%M:%S.%fZ)strftimeris r$format_timestamprms >>1 2 22r&ch|tj}nt|}|dd}d|iS)z+Creates a hint with the exc info filled in.Nrrd)sysrdexc_info_from_errorrds r$event_hint_with_exc_inforrs><>>&x00{  !!r&ceZdZdZdS)BadDsnzRaised on invalid DSNs.Nr[r\r]__doc__r)r&r$rtrts!!!!r&rtc<eZdZdZdZedZddZdZdS)DsnzRepresents a DSN.c6t|trt|j|_dSt jt |}|jdvrtd|jz|j|_|j td|j |_ |j |jdkrdpd|_ n |j |_ |j std|j |_ |j|_|jdd } t t%||_n6#t*t,f$r"td |jpd d dzwxYwd|dz|_dS) N)httphttpszUnsupported scheme %rzMissing hostnamer{PzMissing public key/rzInvalid project in DSN (%r)) isinstancerxdict__dict__rurlsplitrschemerthostnamehostportusername public_keypassword secret_keyr;rsplitintpop project_id ValueError TypeErrorjoin)rRrXpartsr;s r$__init__z Dsn.__init__s eS ! !  00DM F!)E"2"233 <2 2 205<?@@ @l > !+,, ,N :  w.63<"DII DI~ /-.. ...z  a(( Q'DHHJJ88DOOI& Q Q Q6%*:JABB9OOPP P QHHTNNS( s 3E3E9cL|j}|j|jfdvr |d|j}|S)zThe netloc part of a DSN.))rzr})r{r|r)rrr)rRrLs r$netlocz Dsn.netlocs7Y K #+I I IBB *B r&Nc jt|j|j|j|j|j|j|S)z*Returns the auth info object for this dsn.)rrr;rrrclient)Authrrr;rrr)rRrs r$to_authz Dsn.to_auths<;    r&cv|jd|j|jr d|jzpdd|j|j|jS)N://@r)rrrrr;rrQs r$__str__z Dsn.__str__sO KKK OO O 5do 5 ; ; ; KK II OO   r&r() r[r\r]rvrpropertyrrrr)r&r$rxrxsh")")")HX           r&rxcJeZdZdZ d dZedZ d dZd d ZdS) rz,Helper object that represents the auth info.Nr~c v||_||_||_||_||_||_||_||_dSr()rrr;rrrversionr) rRrrrrrrrr;s r$rz Auth.__init__s@   $$$  r&c.|dS)z^Returns the API url for storing events. Deprecated: use get_api_url instead. store)type) get_api_urlrQs r$ store_api_urlzAuth.store_api_urlsW---r&rc J|jd|j|jd|jd|d S)z'Returns the API url for storing events.rzapi/r~)rrr;r)rRrs r$rzAuth.get_api_urls7 KKK II III OOO DD   r&c\d|jfd|jfg}|1|dtt |f|j|d|jf|j|d|jfddd |DzS) z!Returns the auth header a string. sentry_keysentry_versionNsentry_timestamp sentry_client sentry_secretzSentry z, c3*K|]\}}|d|VdS)=Nr)).0keyrXs r$ z!Auth.to_header..%s1&S&S*#u###uu'=&S&S&S&S&S&Sr&)rrappendstrrjrrr)rR timestamprLs r$ to_headerzAuth.to_headersT_-0@$,/O P  II)3|I/F/F+G+GH I I I ; " II 4 5 5 5 ? & II8 9 9 9EJJ&S&SPR&S&S&SSSSSr&)NrNr~)rr() r[r\r]rvrrrrrr)r&r$rrs66 *..X.      T T T T T Tr&rceZdZdZdZdS)AnnotatedValuerXmetadatac"||_||_dSr(r)rRrXrs r$rzAnnotatedValue.__init__+s   r&N)r[r\r]r^rr)r&r$rr(s(%I!!!!!r&r)TypeVarTcFt|ddpt|ddS)Nr]r[getattr)clss r$ get_type_namer8s% 3 - - Oj$1O1OOr&c4t|dd}|dvr|SdS)Nr\)Nbuiltins __builtins__r)rmods r$get_type_moduler=s) #|T * *C 444 4r&c |jd}|drdSn#ttf$rYnwxYwdD]#} |j|rdS#t $rY wxYwdS)Nr[z sentry_sdk.T)__traceback_hide____tracebackhide__F) f_globals startswithAttributeErrorKeyErrorf_locals Exception)framer flag_names r$should_hide_framerEs oj) >>- ( ( 4  H %     ?  ~i( tt     D  5s"';; A A! A!c#XK|}|#t|js|V|j}|!dSdSr()rtb_frametb_next)rYtb_s r$ iter_stacksrXsA C / .. IIIk /////r&cxd}d}|Vt|drF ||}n#ttf$rd}YnwxYw||}|2 t j|}n#ttf$rgdgfcYSwxYw|sgdgfStd||z }t|dz|zt|} d|||D} t|| d} d||dz|D} | | | fS#t$rgdgfcYSwxYw)N get_sourcerrcRg|]$}t|d%S  strip_stringrArlines r$ z'get_lines_from_file..s9   15LF++ , ,   r&rcRg|]$}t|d%Srrrs r$rz'get_lines_from_file..s<    F++ , ,   r&)hasattrr ImportErrorrD splitlines linecachegetlinesrCmaxminlenrrA IndexError) filenamelinenoloadermodule context_linessource source_str lower_bound upper_bound pre_context context_line post_contexts r$get_lines_from_filerasM F gfl;; **622JJW%   JJJ   !**,,F ~ '11FF!   tR<     4|a-/00Kfqj=0#f++>>K   9? F@R9S   $F6N$8$8$@$@AA    k9:   L,66 4|s4.AA A55B BAD''D98D9c  |jj}n#t$rd}YnwxYw |jd}n#t$rgdgfcYSwxYw |jd}n#t$rd}YnwxYw|dz }||rt ||||SgdgfS)Nr[ __loader__r)f_code co_filenamerrr)r tb_linenoabs_pathrrrs r$get_source_contextrs <+ , 4|.  ]F h"8VVVDDD tR<s-   0AA A A#"A#c` t|S#t$rt|cYSwxYwr()rr safe_reprris r$safe_strrsD      s --c t|dd} |ddS#t$r|cYSwxYw#t$rYdSwxYw)Nrreplacelatin1zunicode-escape )reprrBr"r)rXrLs r$rrs $e##GY77B yy**112BCCC      $ $ $### $s.#A 'A AA AA A.-A.cD t|S#t$rYdSwxYw)Nr )r rris r$rrs5 #;;  # # #"?? #s  c|r|s|S |dr |dd}|ddd}||krtj|St j|j}||tj dddd tj S#t$r|cYSwxYw)Nz.pyc.rr) endswithsplitr7r;basenameromodules__file__rseplstripr)rr base_modulebase_module_paths r$filename_for_modulers 6    V $ $ %}Hll3**1- & 7##H-- -;{3<~~.55bfa@@CQGGKRR F    sAC(A3C C+*C+Tc vt|dd}|sd}d}n|jj}|jj} |jd}n#t $rd}YnwxYw||j}t||\}}} t||pd|rtj |nd|pd||||| d} |r |j | d<| S)Nrr[z )rrfunctionrrrrrvars) rrrco_namerrf_linenorrr7r;abspathr) rr with_localsrrrrrrrrLs r$serialize_framer"s UHd + +F (<+<', N .@ .R.R+K|(99AT19CBGOOH---t+ "$$  B$^6 Is A AAcd}g}tj}|.7s<   r|UUUr&)rrrX mechanismr$ stacktrace)r- setdefaultrrrr) exc_typer,rYclient_optionsr3r+r$rLr!s @r$!single_exception_from_error_tupler8s)$$ 4&)!4 VR((33GR@@KK e    $]3 b//F "(++h'')$$   B.$f-< Ir&__suppress_context__c#K|\}}}g}t}||t||vr|||fV|||t||jr|j}n|j}|dSt|}|}t|dd}||t||vdSdSdSdSdSdS)N __traceback__) setidraddr9 __cause__ __context__rr)rdr6r,rYseen_exceptionsseen_exception_idscauses r$walk_exception_chainrDMs"*)R UU  %9 %777Ir) ) ) )  " "9 - - -  " "2i== 1 1 1- .!+!-}E{{HI66B)  %9 %77777 ! %%77 ! %%r&c#K|VdSr(r)rqs r$rDrDnsr&c |\}}}g}t|D],\}}}|t|||||-||Sr()rDrr8r')rdr7r3r6r,rYrLs r$exceptions_from_error_tuplerGssz 'Hi B#7#A#A  )R -)R      JJLLL Ir&cp t|S#t$rt|ddcYSwxYw)Nrr)rUnicodeDecodeErrorr ris r$ to_stringrJsK! !!!E{{1R4    !s !55c#Kd|vr |dVd|vr.|ddpdD]}d|vr |dVd|vr.|ddpdD]}d|vr |dVdSdS)Nr4threadsvaluesr) exception)r9)eventthreadrNs r$iter_event_stacktracesrQsuL!!!!EI&**844: + +Fv%%\****e{+//99?R . .Iy(( ---- . .r&c#jKt|D] }|dpdD]}|V!dS)Nr$r))rQr9)rOr4rs r$iter_event_framesrSsW,U33 ^^H--3  EKKKK r&ctt|D]'}t|d||(|S)Nr$)in_app_excludein_app_include)rQhandle_in_app_implr9)rOrUrVr4s r$ handle_in_apprXsQ,U33   NN8 $ $))     Lr&c |sdSd}|D]c}|d}||rd}|d}|s6t||rd|d<d}Nt||rd|d<d|s|D]}|dd|d<|S)NFin_appTr)r9_module_in_set)r$rUrV any_in_apprrZrs r$rWrWs tJ$$8$$   "! 8$$ $  FN 3 3 $"E(OJJ FN 3 3 $#E(O ' ' 'Eyy""*"&h Mr&czt|trt|dkr|\}}}nt|trTt |dd}|t |}|}nNt j\}}}||urd}|}t |}ntdt |z|||fS)Nr;z,Expected Exception object to report, got %s!) rtupler BaseExceptionrrrordr)errorr6r,rYs r$rprps%WCJJ!OO"')RR E= ) ) W UOT 2 2 >E{{HII&)lnn #Hi%%! ;;G$u++UVVV Y ""r&cnt|}t|}ddt|||id|fS)NrarM)levelrN)rprrrG)rdr7r3hints r$event_from_exceptionresX #8,,H #H - -D5ni     r&c^|sdS|pdD]#}||ks||dzrdS$dS)NFr)rT)r)namer<items r$r[r[sP u r 4<<4??4#:66<44  5r&c|s|S|t}t|}||kr*t|d|dz dz|dd|dz |ggdS|S)Nr^z...z!limitx)rremr)MAX_STRING_LENGTHrr)rX max_lengthlengths r$rrs  & ZZF (*q.()F2!3 Q CD     Lr&c ddlm}|ddr|ddrdSdSn#t$rYnwxYw dd lm}|d rdSn#t$rYnwxYwdS) z Returns whether gevent/eventlet have patched the stdlib in a way where thread locals are now more "correct" than contextvars. r)is_object_patched threadinglocal contextvars ContextVarFT)is_monkey_patchedrP) gevent.monkeyrpreventlet.patcherru)rprus r$_is_contextvars_brokenrxs  333333  [' 2 2 !  == u4         666666  X & & 4        5s% 22A AAc2Gfddt}|S)Nc&eZdZfdZdZdZdS)1_make_threadlocal_contextvars..ContextVarc4||_|_dSr()_name_local)rRrgrrs r$rz:_make_threadlocal_contextvars..ContextVar.__init__<sDJ%''DKKKr&c.t|jd|S)NrX)rr~)rRdefaults r$r9z5_make_threadlocal_contextvars..ContextVar.getAs4;99 9r&c||j_dSr()r~rX)rRrXs r$r<z5_make_threadlocal_contextvars..ContextVar.setEs %DK   r&N)r[r\r]rr9r<rrsr$rtr{9sL " " " " "  : : : & & & & &r&rt)object)rrrts` r$_make_threadlocal_contextvarsr7s?&&&&&&&V&&& r&ctsFtjdkr ddlm}d|fS#t $rYnwxYw ddlm}d|fS#t $rYnwxYwddlm}dt|fS)z Figure out the "right" contextvars installation to use. Returns a `contextvars.ContextVar`-like class with a limited API. See https://docs.sentry.io/platforms/python/contextvars/ for more information. )r^rr)rtTrF) rxro version_infoaiocontextvarsrtrrsrqrrr)rtrrs r$_get_contextvarsrLs " # #  f $ $ 555555Z''     222222Z''       /66 66s * 77 A AAz With asyncio/ASGI applications, the Sentry SDK requires a functional installation of `contextvars` to avoid leaking scope/context data across requests. Please refer to https://docs.sentry.io/platforms/python/contextvars/ for more information. c |jjd|jjd|jS#t$rYnwxYwt |ddpt |ddpd}|sdS |jd|S#t$rYnwxYw|S)Nrr]r[)im_classr\r[rr)func func_qualnames r$transaction_from_functionr~s M $ $ $ M " " " MM        nd++VwtZ/N/NVRV t  ///==99       s"% 22 A** A76A7disable_capture_eventceZdZdZdS)ServerlessTimeoutWarningz>Raised when a serverless method is about to reach its timeout.Nrur)r&r$rrsHHDr&rc$eZdZdZdZdZdZdS) TimeoutThreadzCreates a Thread which runs (sleeps) for a time duration equal to waiting_time and raises a custom ServerlessTimeout exception. ctj|||_||_tj|_dSr()rqThreadr waiting_timeconfigured_timeoutEvent _stop_event)rRrrs r$rzTimeoutThread.__init__s?!!$'''("4$?,,r&c8|jdSr()rr<rQs r$stopzTimeoutThread.stops r&c|j|j|jrdSt |j}||jkr|dz}t d|)NrzZWARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.)rwaitris_setrrrformat)rRinteger_configured_timeouts r$runzTimeoutThread.runs d/000   " " $ $  F%()@%A%A" &(? ? ?)Ca)G &' h o o*     r&N)r[r\r]rvrrrr)r&r$rrsK---     r&rr()NNrU)T)`r rloggingr7rorqr=r sentry_sdksentry_sdk._compatrrrrsentry_sdk._typesrtypesr r typingr r r rrrrrrrrrrrg getLoggerloggerrlMAX_FORMAT_PARAM_LENGTHr%r*rHrMrrOr`rarVrjrmrrrrtrxrrrr Annotatedrrrrrrrrrr"r)r-r8rrHAS_CHAINED_EXCEPTIONSrDrGrJrQrSrXrWrprer[rrxrrHAS_REAL_CONTEXTVARSrtCONTEXTVARS_ERROR_MESSAGErrrrrr)r&r$rs  GGGGGGGGGGGG""""""8######%%%%%%77777777 q!  . / /TTT    $$$P          v   7688''' 222+++ 333 " " " """"""Z"""F F F F F &F F F R8T8T8T8T8T68T8T8Tv!!!!!V!!!) Ana'(IPPP &   ))))X.   ##$$$$8###*    F     --- ''''T!,BCC%7777B(!!! . . .    <###0*.:*#7#7#7L$4#3#5#5 j@# #:;;     y   # # # # # I$# # # # # r&