bg addlmZddlmZddlmZddlZddlZddlmZddl m Z ddl m Z m Z mZmZddlmZmZmZdd lmZdd lmZmZdd lmZerzdd lmZdd lmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-ddlm.Z.ddl/m0Z0e$de"defZ1e$dZ2gZ3dZ4dZ5dZ6Gd d!e7Z8dS)")copy)deque)chainN) Attachmentwraps)Baggageextract_sentrytrace_datahas_tracing_enablednormalize_incoming_data)BAGGAGE_HEADER_NAMESENTRY_TRACE_HEADER_NAME Transaction) TYPE_CHECKING)loggercapture_internal_exceptions) FALSE_VALUES)Any)Dict)Iterator)Optional)Deque)List)Callable)Tuple)TypeVar) BreadcrumbEventEventProcessorErrorProcessorExcInfoHintType)Profile)Span)SessionF.)boundTc:t|dSN)global_event_processorsappend) processors G/opt/cloudlinux/venv/lib64/python3.11/site-packages/sentry_sdk/scope.pyadd_global_event_processorr0:s""9-----c.t||jS)N)fsetdoc)property__doc__)fns r/ _attr_setterr8?s  , , ,,r1c<tfd}|S)Ncd|jsdS d|_|g|Ri|d|_S#d|_wxYw)NFT)_should_capture)selfargskwargsr7s r/wrapperz!_disable_capture..wrapperFs^#  F (#(D 2d,T,,,V,,#'D 4D ' ' ' 's& /r)r7r?s` r/_disable_capturer@Ds3 2YY((((Y( Nr1ceZdZdZdZdZdZdZdZdZ d,d Z d Z d Z d Z d ZdZdZedZdZedZedZejdZd,dZedZdZedZejdZedZejdZdZdZdZdZ d Z!d!Z"d"Z# d-d$Z$d%Z% d,d&Z&e' d,d'Z(d(Z) d.d)Z*d*Z+d+Z,dS)/ScopezaThe scope holds extra information that should be sent with all events that belong to it. )_level_name _fingerprint _transaction_transaction_info_user_tags _contexts_extras _breadcrumbs_event_processors_error_processorsr;_span_session _attachments_force_auto_session_tracking_profile_propagation_contextcg|_g|_d|_d|_||}||dS)N) incoming_data)rMrNrDrTclear_load_trace_data_from_envgenerate_propagation_context)r<incoming_trace_informations r/__init__zScope.__init__ws^!#!# $(! %)%C%C%E%E" ))8R)SSSSSr1cd}tjdpd}|tv}|ri}tjdr)tjdpd|t <tjdr)tjdpd|t <|pdS)z Load Sentry trace id and baggage from environment variables. Can be disabled by setting SENTRY_USE_ENVIRONMENT to "false". NSENTRY_USE_ENVIRONMENT SENTRY_TRACESENTRY_BAGGAGE)osenvirongetlowerrrr )r<rZsentry_use_environmentuse_environments r/rXzScope._load_trace_data_from_envs &*" JNN3 4 4 : %'' 1 D  )+ &z~~n-- JNN>228b++CDz~~.// JNN#344:++>?*1T1r1ci}t|}|t}|r)tj||d<|t }|r&t|}|||d|vod|v}|r'|| |r:|ds#tj j dd|d<|SdS)Ndynamic_sampling_contexttrace_idspan_id) r rcr r from_incoming_headerrhrr update_create_new_propagation_contextuuiduuid4hex)r<datacontextnormalized_databaggage_headersentry_trace_headersentrytrace_dataonly_baggage_no_sentry_traces r/_extract_propagation_contextz"Scope._extract_propagation_contexts%1$77(,,-@AA  )292N33&&(( . /.112JKK  178KLL +/000 '' 1 Oj6O % ( C NN4??AA B B B  ;;y)) ;%)Z\\%5bcc%: "Ntr1cxtjjtjjdddddS)Nrkrirjparent_span_idrh)rorprqr<s r/rnz%Scope._create_new_propagation_contexts: (z||',"(,    r1cl||_tjd|jdS)zt Creates a new propagation context and sets it as `_propagation_context`. Overwriting existing one. z,[Tracing] Create new propagation context: %sN)rnrTrdebugr}s r/set_new_propagation_contextz!Scope.set_new_propagation_contexts? %)$H$H$J$J! :  %     r1Nc|r8||}|!||_tjd|j|j|dSdS)z Makes sure `_propagation_context` is set. If there is `incoming_data` overwrite existing `_propagation_context`. if there is no `incoming_data` create new `_propagation_context`, but do NOT overwrite if already existing. Nz>[Tracing] Extracted propagation context from incoming data: %s)ryrTrrr)r<rVrss r/rYz"Scope.generate_propagation_contextsu  77 FFG",3) T-  $ ,  , , . . . . . - ,r1c|jdS|}|||jd<|jdS)z Returns the Dynamic Sampling Context from the Propagation Context. If not existing, creates a new one. Nrh)rT get_baggagerh)r<baggages r/get_dynamic_sampling_contextz"Scope.get_dynamic_sampling_contexts[  $ ,4""$$  0022  %* ()CDDr1cR|jdS|jdd|jd}|S)zn Returns the Sentry "sentry-trace" header (aka the traceparent) from the Propagation Context. Nri-rj)rT)r< traceparents r/get_traceparentzScope.get_traceparentsB  $ ,4  %j 1 1 1  %i 0 0 r1c|jdS|jd}|tj|St|S)Nrh)rTrcr from_options)r<rhs r/rzScope.get_baggagesT  $ ,4#'#<#@#@ &$ $   $ +'-- -344 4r1c|jdS|jd|jd|jd|d}|S)zR Returns the Sentry "trace" context from the Propagation Context. Nrirjr|r{)rTr)r< trace_contexts r/get_trace_contextzScope.get_trace_contextsY  $ ,41*=0;"78HI(,(I(I(K(K   r1c#K|je|}| t|fV|}|0t |}t |fVdSdSdS)zz Creates a generator which returns the `sentry-trace` and `baggage` headers from the Propagation Context. N)rTrrrr serializer )r<rdscrs r/ iter_headerszScope.iter_headers#s  $ 0..00K&. ;;;;3355C!#,,0022)7222222 1 0 r1cd|_d|_d|_i|_d|_i|_i|_i|_g|_| d|_ d|_ d|_ d|_ d|_d|_dS)zClears the entire scope.NT)rCrErFrGrHrIrJrKrQclear_breadcrumbsr;rOrPrRrSrTr}s r/rWz Scope.clear2s   !#       #  ,0) $(!!!r1c||_dS)zDWhen set this overrides the level. Deprecated in favor of set_level.NrCr<values r/levelz Scope.levelKs r1c||_dS)zSets the level for the scope.Nrrs r/ set_levelzScope.set_levelQs r1c||_dS)z0When set this overrides the default fingerprint.N)rErs r/ fingerprintzScope.fingerprintVs"r1cH|jdS|jjdS|jjS)z8Return the transaction (root span) in the scope, if any.N)rOcontaining_transactionr}s r/ transactionzScope.transaction\s0 : 4 : , 44z00r1ctjd||_|jr|jjr||jj_dSdSdS)zrWhen set this forces a specific transaction name to be set. Deprecated: use set_transaction_name instead.z`Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead.N)rwarningrFrOrnamers r/rzScope.transactionnsb$  n   " : ;$*; ;5:DJ - 2 2 2 ; ; ; ;r1c||_|jr0|jjr$||jj_|r||jj_|r ||jd<dSdS)z?Set the transaction name and optionally the transaction source.sourceN)rFrOrrrrG)r<rrs r/set_transaction_namezScope.set_transaction_namesl! : B$*; B59DJ - 2 B;A 18  6/5D "8 , , , 6 6r1c0||dS)zPWhen set a specific user is bound to the scope. Deprecated in favor of set_user.N)set_userrs r/userz Scope.users er1c\||_|j|j|dSdS)zSets a user for the scope.N)r)rHrPrmrs r/rzScope.set_users: = $ M e , , , , , % $r1c|jS)z,Get/set current tracing span or transaction.)rOr}s r/spanz Scope.spans zr1cp||_t|tr|}|jr|j|_dSdSdSr+)rO isinstancerrrF)r<rrs r/rz Scope.spansT  dK ( ( 5K 5$/$4!!! 5 5 5 5r1c|jSr+rSr}s r/profilez Scope.profiles }r1c||_dSr+r)r<rs r/rz Scope.profiles  r1c||j|<dS)z)Sets a tag for a key to a specific value.N)rIr<keyrs r/set_tagz Scope.set_tags  3r1c<|j|ddS)zRemoves a specific tag.N)rIpopr<rs r/ remove_tagzScope.remove_tags sD!!!!!r1c||j|<dS)z5Binds a context at a certain key to a specific value.N)rJrs r/ set_contextzScope.set_contexts$sr1c<|j|ddS)zRemoves a context.N)rJrrs r/remove_contextzScope.remove_contexts" 3%%%%%r1c||j|<dS)z&Sets an extra key to a specific value.N)rKrs r/ set_extrazScope.set_extras" Sr1c<|j|ddS)zRemoves a specific extra key.N)rKrrs r/ remove_extrazScope.remove_extras" d#####r1c,t|_dS)zClears breadcrumb buffer.N)rrLr}s r/rzScope.clear_breadcrumbss"GGr1Fc ^|jt|||||dS)z)Adds an attachment to future events sent.)bytespathfilename content_typeadd_to_transactionsN)rQr-r)r<rrrrrs r/add_attachmentzScope.add_attachmentsJ   !)$7         r1ct|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)lenrMrrr-)r<funcs r/add_event_processorzScope.add_event_processorse t% & & + + N^&   &qqq) %%d+++++r1cV| ||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)r Exception)eventexc_infois_instcls_ real_funcs r/rz'Scope.add_error_processor..func's`$(!d;;GG $$$#GGG$6$9UH555 s  )))rNr-)r<rclsrrs @@r/add_error_processorzScope.add_error_processorsR ?DI       %%d+++++r1c|d}|ddk}|dpg}|jD] }|r|jr||!||d<|j |j|d<|sB|didg|j|d |j |j|d <|d|j |j |d<|d |j |j |d <|d |j |j |d <|j r.|d i |j |jr.|d i |j|jr.|di |j|di}|dJt!|r$|j|j|d<n||d< |ddd} n#t&t(f$rd} YnwxYw| d| i|d<|d} | (|jD] } | || } | || dcS| }!t-t.|jD]H} |} t35| ||} dddn #1swxYwY| || dcS| }I|S)zBApplies the information contained on the scope to the given event.c2tjd||dS)Nz%s (%s) dropped event)rinfo)causetys r/_dropz#Scope.apply_to_event.._drop=s K/U ; ; ;4r1typer attachmentsNr breadcrumbsvaluesrtransaction_inforextratagscontextstracerh replay_idreplayrzerror processorzevent processor)rcrQrr-rC setdefaultextendrLrHrFrGrErKrmrIrJr rOrKeyError TypeErrorrNrr,rMr)r<rhintoptionsris_transactionattachments_to_send attachmentrrrerror_processor new_eventevent_processors r/apply_to_eventzScope.apply_to_event3s    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' ( ( 0T5K5W(,(>E$ % 99] # # +0A0M#'#4E- < ?   Wb ) ) 0 0 > > > : <   VR ( ( / / ; ; ; > D   Z , , 3 3DN C C C##J33 << ("7++ = 0F$(J$@$@$B$B!!$($:$:$<$<!  )*DEkRII)$   III   Y"HX 88J''  #'#9 " "+OE8<< $ 52CDDDDD!$%TUU  OI,.. 9 9+OE488  9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 u_.?@@@@@EE s$#I88J J LL" %L" c|j |j|_|j |j|_|j |j|_|j|j|j|j |j|_|jr|j|j|jr|j|j|jr|j|j|j r|j |j |j r |j |_ |j r|j |j |j r |j |_ |jr|j|_dSdSr+)rCrErFrGrmrHrIrJrKrLrrOrQrSrT)r<scopes r/update_from_scopezScope.update_from_scopesn < #,DK   ) % 2D    ) % 2D   " .  " ) )%*A B B B ; "DJ ; + J  ek * * * ? 3 N ! !%/ 2 2 2 = / L   . . .   9   $ $U%7 8 8 8 ; %DJ   9   $ $U%7 8 8 8 > +!NDM  % C(-(BD % % % C Cr1c|||_|||_||j|||j|||j|| ||_dSdSr+)rCrHrKrmrJrIrE)r<rrextrasrrrs r/update_from_kwargszScope.update_from_kwargss  DK  DJ   L   ' ' '   N ! !( + + +   J  d # # #  " +D    # "r1ct|j}|j|_|j|_|j|_|j|_t|j|_|j |_ t|j |_ t|j |_ t|j |_ t|j|_t|j|_t|j|_|j|_|j|_|j|_|j|_|j|_t|j|_|j|_|Sr+)object__new__ __class__rCrDrErFdictrGrHrIrJrKrrLlistrMrNrTr;rOrPrRrQrS)r<rvs r/__copy__zScope.__copy__s ^^DN + +K :++#D$:;;: ##DN++ $,'' t011#D$:;;#D$:;;"&";!1:m *.*K't011m  r1cld|jjdtt|d|jdS)N)r__name__rqidrDr}s r/__repr__zScope.__repr__s: N # # # 4MMMM JJJ  r1r+)NNNNF)NNNNNN)-r  __module__ __qualname__r6 __slots__r[rXryrnrrYrrrrrrWr8rrrr5rsetterrrrrrrrrrrrrrrrr@rrrrr r1r/rBrBTsJI0 T T T2226>       ////(EEE"    5 5 5" 3 3 3)))2\  ""\" 11X1";;;0 6 6 6 6\ ---X  [55[5X ^  ^    """$$$&&&"""$$$$$$ !     (,,,( ,,,,8  XXXXtCCC> ,,,,.<     r1rB)9r collectionsr itertoolsrrarosentry_sdk.attachmentsrsentry_sdk._functoolsrsentry_sdk.tracing_utilsr r r r sentry_sdk.tracingr rrsentry_sdk._typesrsentry_sdk.utilsrrsentry_sdk.constsrtypingrrrrrrrrrrrrr r!r"r#sentry_sdk.profilerr$r%sentry_sdk.sessionr&r'r)r,r0r8r@rrBrr1r/rs ------''''''  ,+++++@@@@@@@@******,+++++''''''******8CH-...A A... ---    R  R  R  R  R  FR  R  R  R  R  r1