mfw>pddlmZddlmZddlmZddlmZddlmZddl m Z m Z ddl m Z ddlmZerhdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZmZmZmZmZmZmZddl mZddl m!Z!ededefZ"edZ#gZ$dZ%dZ&dZ'Gdde(Z)dS))copy)deque)chainwraps)MYPY)loggercapture_internal_exceptions) Transaction) Attachment)Any)Dict)Optional)Deque)List)Callable)TypeVar) BreadcrumbEventEventProcessorErrorProcessorExcInfoHintType)Span)SessionF.)boundTc:t|dSN)global_event_processorsappend) processors G/opt/imunify360/venv/lib64/python3.11/site-packages/sentry_sdk/scope.pyadd_global_event_processorr&(s""9-----c.t||jS)N)fsetdoc)property__doc__)fns r% _attr_setterr.-s  , , ,,r'c<tfd}|S)Ncd|jsdS d|_|g|Ri|d|_S#d|_wxYw)NFT)_should_capture)selfargskwargsr-s r%wrapperz!_disable_capture..wrapper4s^#  F (#(D 2d,T,,,V,,#'D 4D ' ' ' 's& /r)r-r5s` r%_disable_capturer62s3 2YY((((Y( Nr'cdeZdZdZdZdZdZedZdZ edZ e dZ e j d Z ed Zd Ze d Zej d ZdZdZdZdZdZdZdZ ddZdZ d dZedZdZ d!dZdZdZ dS)"ScopezaThe scope holds extra information that should be sent with all events that belong to it. )_level_name _fingerprint _transaction_user_tags _contexts_extras _breadcrumbs_event_processors_error_processorsr1_span_session _attachments_force_auto_session_trackingcXg|_g|_d|_|dSr!)rBrCr:clearr2s r%__init__zScope.__init__bs*!#!#  r'cd|_d|_d|_d|_i|_i|_i|_g|_|d|_ d|_ d|_ d|_ dS)zClears the entire scope.NT) r9r;r<r=r>r?r@rFclear_breadcrumbsr1rDrErGrJs r%rIz Scope.clearjsu          #  ,0)))r'c||_dS)zDWhen set this overrides the level. Deprecated in favor of set_level.Nr9r2values r%levelz Scope.level~s r'c||_dS)zSets the level for the scope.NrOrPs r% set_levelzScope.set_levels r'c||_dS)z0When set this overrides the default fingerprint.N)r;rPs r% fingerprintzScope.fingerprints"r'c|jdSt|jtr|jS|jjr |jjSdS)z8Return the transaction (root span) in the scope, if any.N)rD isinstancer _containing_transactionrJs r% transactionzScope.transactionsP : 4 dj+ . . :  : - 6:5 5 tr'cf||_|j}|rt|tr ||_dSdSdS)z;When set this forces a specific transaction name to be set.N)r<rDrXr name)r2rQspans r%rZzScope.transactionsK"z  Jt[11 DIII    r'c0||dS)zPWhen set a specific user is bound to the scope. Deprecated in favor of set_user.N)set_userrPs r%userz Scope.users er'c\||_|j|j|dSdS)zSets a user for the scope.N)r`)r=rEupdaterPs r%r_zScope.set_users: = $ M e , , , , , % $r'c|jS)z,Get/set current tracing span or transaction.)rDrJs r%r]z Scope.spans zr'cp||_t|tr|}|jr|j|_dSdSdSr!)rDrXr r\r<)r2r]rZs r%r]z Scope.spansT  dK ( ( 5K 5$/$4!!! 5 5 5 5r'c||j|<dS)z)Sets a tag for a key to a specific value.N)r>r2keyrQs r%set_tagz Scope.set_tags  3r'c<|j|ddS)zRemoves a specific tag.N)r>popr2rgs r% remove_tagzScope.remove_tags sD!!!!!r'c||j|<dS)z5Binds a context at a certain key to a specific value.N)r?rfs r% set_contextzScope.set_contexts$sr'c<|j|ddS)zRemoves a context.N)r?rjrks r%remove_contextzScope.remove_contexts" 3%%%%%r'c||j|<dS)z&Sets an extra key to a specific value.N)r@rfs r% set_extrazScope.set_extras" Sr'c<|j|ddS)zRemoves a specific extra key.N)r@rjrks r% remove_extrazScope.remove_extras" d#####r'c,t|_dS)zClears breadcrumb buffer.N)rrArJs r%rMzScope.clear_breadcrumbss"GGr'NFc ^|jt|||||dS)z)Adds an attachment to future events sent.)bytespathfilename content_typeadd_to_transactionsN)rFr#r )r2rwryrxrzr{s r%add_attachmentzScope.add_attachment sJ   !)$7         r'ct|jdkr$tjd|j|jdd=|j|dS)z}Register a scope local event processor on the scope. :param func: This function behaves like `before_send.` zLToo many event processors on scope! Clearing list to free up some memory: %rN)lenrBr warningr#)r2funcs r%add_event_processorzScope.add_event_processor!se t% & & + + N^&   &qqq) %%d+++++r'cV| ||fd}|j|dS)aRegister a scope local error processor on the scope. :param func: A callback that works similar to an event processor but is invoked with the original exception info triple as second argument. :param cls: Optionally, only process exceptions of this type. Ncx t|d}n#t$rd}YnwxYw|r ||S|S)NF)rX Exception)eventexc_infois_instcls_ real_funcs r%rz'Scope.add_error_processor..funcBs`$(!d;;GG $$$#GGG$6$9UH555 s  )))rCr#)r2rclsrrs @@r%add_error_processorzScope.add_error_processor2sR ?DI       %%d+++++r'cvd}|ddk}|dpg}|jD] }|r|jr||!||d<|j |j|d<|sB|didg|j|d |j |j|d <|d|j |j |d<|d |j |j |d <|j r.|d i |j |j r.|d i |j |jr.|d i |j|jG|d i}|ds|j|d<|d}|)|jD]!} | ||} | ||| dcS| }"t%t&|jD]I} |} t+5| ||} dddn #1swxYwY| ||| dcS| }J|S)zBApplies the information contained on the scope to the given event.c4tjd|||dS)Nz%s (%s) dropped event (%s))r info)rcausetys r%_dropz#Scope.apply_to_event.._dropWs K4b% G G G4r'typerZ attachmentsNrR breadcrumbsvaluesr`rVextratagscontextstracerzerror processorzevent processor)getrFr{r#r9 setdefaultextendrAr=r<r;r@rbr>r?rDget_trace_contextrCrr"rBr ) r2rhintris_transactionattachments_to_send attachmentrrerror_processor new_eventevent_processors r%apply_to_eventzScope.apply_to_eventNsP    6**m; #hh}55;+ 7 7J! 7Z%C 7#**:6661] ; "![E'N    ]B / / : :8R H H O O!    99V   $)? JE&M 99] # # +0A0M#'#4E- 99] # # +0A0M#'#4E- < ?   Wb ) ) 0 0 > > > : <   VR ( ( / / ; ; ; > D   Z , , 3 3DN C C C : !'' B77H<<(( C$(J$@$@$B$B!88J''  #'#9 " "+OE8<< $ 59JKKKKK!$%TUU  OI,.. 9 9+OE488  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 uUO5FGGGGGEE s JJ !J cD|j |j|_|j |j|_|j |j|_|j |j|_|jr|j|j|jr|j|j|jr|j|j|jr|j |j|j r |j |_ |j r!|j |j dSdSr!) r9r;r<r=r>rbr?r@rArrDrF)r2scopes r%update_from_scopezScope.update_from_scopes < #,DK   ) % 2D    ) % 2D  ; "DJ ; + J  ek * * * ? 3 N ! !%/ 2 2 2 = / L   . . .   9   $ $U%7 8 8 8 ; %DJ   9   $ $U%7 8 8 8 8 8 9 9r'c|||_|||_||j|||j|||j|| ||_dSdSr!)r9r=r@rbr?r>r;)r2r`rRextrasrrrVs r%update_from_kwargszScope.update_from_kwargss  DK  DJ   L   ' ' '   N ! !( + + +   J  d # # #  " +D    # "r'czt|j}|j|_|j|_|j|_|j|_|j|_t|j |_ t|j |_ t|j |_ t|j |_ t|j|_t|j|_|j|_|j|_|j|_|j|_t|j|_|Sr!)object__new__ __class__r9r:r;r<r=dictr>r?r@rrAlistrBrCr1rDrErGrF)r2rvs r%__copy__zScope.__copy__s ^^DN + +K :++: ##DN++ $,'' t011#D$:;;#D$:;;!1:m *.*K't011 r'cld|jjdtt|d|jdS)N)r__name__hexidr:rJs r%__repr__zScope.__repr__s: N # # # 4MMMM JJJ  r')NNNNFr!)NNNNNN)!r __module__ __qualname__r, __slots__rKrIr.rRrTrVr+rZsetterr`r_r]rhrlrnrprrrtrMr|rrr6rrrrrr'r%r8r8BsOI*111(\  ""\" X.$\ ---X  [55[5   """$$$&&&"""$$$$$$ !     (,,,( ,,,,8GGGR9992 ,,,,.4     r'r8N)*r collectionsr itertoolsrsentry_sdk._functoolsrsentry_sdk._typesrsentry_sdk.utilsr r sentry_sdk.tracingr sentry_sdk.attachmentsr typingr rrrrrrrrrrrrrrsentry_sdk.sessionsrrrr"r&r.r6rr8rr'r%rs>''''''""""""@@@@@@@@******------('''''++++++8CH-...A A... ---    d d d d d Fd d d d d r'