mfeUddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z m Z ddlmZdd lmZmZmZmZdd lmZerndd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddl$m%Z%ddlm&Z&m'Z'm(Z(m)Z)m*Z*ddl+m,Z,e!dZ-ndZ"edZ.dZ/dZ0Gdd e1Z2d!Z3dd lmZerGd"d#e,e#eZ4n d$Z4Gd%d&e5Z6Gd'd(e1Z7Gd)d*ee6Z8e8Z9e.:e9dS)+N)datetime)contextmanager)with_metaclassScope)Client)Span Transaction)Session)exc_info_from_errorevent_from_exceptionlogger ContextVar)MYPY)Union)Any)Optional)Tuple)Dict)List)Callable) Generator)Type)TypeVar)overload)ContextManager) Integration)EventHint BreadcrumbBreadcrumbHintExcInfo)ClientConstructorTc|SN)xs E/opt/imunify360/venv/lib64/python3.11/site-packages/sentry_sdk/hub.pyrr1ssentry_current_hubc|r|rtd|Etj|}t|r ||n<||n&|r"tj|}|jdi|n|}|S)Nzcannot provide scope and kwargsr') TypeErrorcopycallableupdate_from_scopeupdate_from_kwargs)base scope_change scope_kwargs final_scopes r) _update_scoper69s; ;9:::ioo L ! ! 8 L % % % %  ) ), 7 7 7 7 ioo & &666666 r*cFtjj}|sdS|jdS)NFsend_default_pii)Hubcurrentclientoptions)r;s r)_should_send_default_piir=Ks' [ F u >, --r*c eZdZdZdZdZdS) _InitGuardc||_dSr&)_client)selfr;s r)__init__z_InitGuard.__init__Ts  r*c|Sr&r'rBs r) __enter__z_InitGuard.__enter__Xs r*cD|j}||dSdSr&)rAclose)rBexc_type exc_valuetbcs r)__exit__z_InitGuard.__exit__\s& L = GGIIIII =r*N__name__ __module__ __qualname__rCrFrMr'r*r)r?r?SsAr*r?czt|i|}tj|t |}|S)zsInitializes the SDK and optionally integrations. This takes the same arguments as the client constructor. )rr9r: bind_clientr?)argskwargsr;rvs r)_initrWcs> T $V $ $FKF### F  B Ir*ceZdZdS)initN)rOrPrQr'r*r)rYrYxs r*rYctSr&)rWr'r*r)r[sEr*c:eZdZedZedZdS)HubMetactd}|.tt}t||S)z(Returns the current instance of the hub.N)_localgetr9 GLOBAL_HUBset)clsrVs r)r:zHubMeta.currents9ZZ   :ZB JJrNNN r*ctS)z%Returns the main instance of the hub.)ra)rcs r)mainz HubMeta.mains r*N)rOrPrQpropertyr:rer'r*r)r]r]sH XXr*r]c eZdZdZdZdZdS) _ScopeManagercj||_t|j|_|jd|_dSN)_hublen_stack _original_len_layer)rBhubs r)rCz_ScopeManager.__init__s*  __jn r*c(|jd}|J|S)N)rp)rBscopes r)rFz_ScopeManager.__enter__s A    r*cLt|jj}||jkrt jd|j|z dS||jkr5t jd||jz |jj|jd|jj|jdz }|jj|jdz d=|d|jdkr)t jd|d|jddS|d|jdkrd}t j|dSdS)Nz1Scope popped too soon. Popped %s scopes too many.zLeaked %s scopes: %srsz2Wrong scope found. Meant to pop %s, but popped %s.rzinit() called inside of pushed scope. This might be entirely legitimate but usually occurs when initializing the SDK inside a request handler or task/job function. Try to initialize the SDK as early as possible instead.)rmrlrnrorerrorwarningrp)rBrIrJrK current_lenlayerrws r)rMz_ScopeManager.__exit__sL$)*++ + + + LC"[0    F 4- - - N&d00  !3!5!56      !3a!78 I T/!355 6 8t{1~ % % LDa A      1XQ ' '4  N7 # # # # #( 'r*NrNr'r*r)rhrhsA%%%  $ $ $ $ $r*rhcleZdZdZdZerdZdZ d dZdZ dZ dZ dZ e dZe d Zd Zd Z d d Z d d Z d dZdZ d dZ d!dZ d!dZe d!dZedZ d!dZdZe d!dZedZ d!dZdZdZdZdZ d dZ!dZ"dS)"r9zThe hub wraps the concurrency management of the SDK. Each thread has its own hub but the hub might transfer with the flow of execution if context vars are available. If the hub is used with a with statement it's temporarily activated. Nct|tr)|}|jd\}}|tj|}n|}|t }||fg|_d|_g|_dSrj) isinstancer9rnr.r_last_event_id _old_hubs)rB client_or_hubrtrqr; other_scopes r)rCz Hub.__init__st mS ) ) #C"%*R. FK} +.."F =GGE' "r*c|jtjt||Sr&)r~appendr9r:r_rbrEs r)rFz Hub.__enter__s1 ck*** 4 r*cl|j}t|dSr&)r~popr_rb)rBrIrJrKolds r)rMz Hub.__exit__s*n  "" 3r*cN|5|cdddS#1swxYwYdS)z~Runs a callback in the context of the hub. Alternatively the with statement can be used on the hub directly. Nr'rBcallbacks r)runzHub.runsw  8::                  s ct|tr|}n|j|j}ntd|j}||j|}||SdSdS)aReturns the integration for this hub by name or class. If there is no client bound or the client does not have that integration then `None` is returned. If the return value is not `None` the hub is guaranteed to have a client attached. NzIntegration has no name)r|str identifier ValueErrorr; integrationsr`)rB name_or_classintegration_namer;rVs r)get_integrationzHub.get_integrations~ mS ) ) 8,    % 1,7  677 7  $(()9::B~   ~r*c(|jddS)z&Returns the current client on the hub.rkrrnrEs r)r;z Hub.client{2q!!r*c(|jddS)z%Returns the current scope on the hub.rkrsrrEs r)rtz Hub.scope"rr*c|jS)zReturns the last event ID.)r}rEs r) last_event_idzHub.last_event_id(s ""r*cD|jd}||df|jd<dS)zBinds a new client to the hub.rkrsNr)rBnewtops r)rSzHub.bind_client-s& k"oA- Br*c |jd\}}t|||}|"||||}|||_|SdS)zGCaptures an event. Alias of :py:meth:`sentry_sdk.Client.capture_event`.rkN)rnr6 capture_eventr})rBeventhintrt scope_argsr; top_scoperVs r)rzHub.capture_event5sY!KO i ;;  %%eT599B~&(#Itr*c B|jdS|d}|j||dfd|i|S)zCaptures a message. The message is just a string. If no level is provided the default level is `info`. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.Client.capture_event`). Ninfo)messagelevelrt)r;r)rBrrrtrs r)capture_messagezHub.capture_messageGsR ; 4 =E!t!% 0 0  8= AK   r*c (|j}|dS|t|}ntj}t ||j\}} |j|f||d|S#t$r)|tjYnwxYwdS)zCaptures an exception. :param error: An exception to catch. If `None`, `sys.exc_info()` will be used. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.Client.capture_event`). N)client_options)rrt) r;r sysexc_infor r<r Exception_capture_internal_exception)rBrvrtrr;rrrs r)capture_exceptionzHub.capture_exception\s >4  *511HH|~~H*8FNSSS t =%4%eR$eRRzRR R = = =  , ,S\^^ < < < < < =ts A0BBc2tjd|dS)z Capture an exception that is likely caused by a bug in the SDK itself. These exceptions do not end up in Sentry and are just logged instead. zInternal error in sentry_sdk)rN)rrv)rBrs r)rzHub._capture_internal_exceptionys   3hGGGGGGr*c |jd\}}|tjddSt|pd}|||sdSt|pd}|dt j|d<|dd|d<|jd|jd||}n|}||j |ntjd ||jd }t|j |kr3|j t|j |k1dSdS) a Adds a breadcrumb. :param crumb: Dictionary with the data as the sentry v7/v8 protocol expects. :param hint: An optional value that can be used by `before_breadcrumb` to customize the breadcrumbs that are emitted. rkNz*Dropped breadcrumb because no client boundr' timestamptypedefaultbefore_breadcrumbz)before breadcrumb dropped breadcrumb (%s)max_breadcrumbs) rnrrdictupdater`rutcnowr< _breadcrumbsrrmpopleft)rBcrumbrrUr;rt new_crumbrs r)add_breadcrumbzHub.add_breadcrumbsk B  > KD E E E FU[b!! V  FDJB 99[ ! ! )!)!2!2E+  99V   $%E&M >- . :;':;E4HHIII    % %i 0 0 0 0 KCU K K K .):;%$%%77   & & ( ( (%$%%777777r*c t|tsd|vr|d}t|tr)tj|||Sd|vr8tj||d}|jdd|i|S||S|d||jj}| |j di|Stdi|S)a" Create and start timing a new span whose parent is the currently active span or transaction, if any. The return value is a span instance, typically used as a context manager to start and stop timing in a `with` block. Only spans contained in a transaction are sent to Sentry. Most integrations start a transaction at the appropriate time, for example for every incoming HTTP request. Use `start_transaction` to start a new transaction when one is not already in progress. transactionzcDeprecated: use start_transaction to start transactions and Transaction.start_child to start spans.nameNrqr') r|r rrwstart_transactionr setdefaultrtspan start_childr )rBrrUdeprecation_msgrs r) start_spanzHub.start_spans( dK ( ( CMV,C,C: $ ,, 4///--d333&&///zz-00-t-BB4B6BBB  K%&&&z  #4#--f-- -~~f~~r*c |di}|"|d|td i|}||jd}|||||jrD|jo$|jj d dpd}| | |S) a Start and return a transaction. Start an existing transaction if given, otherwise create and start a new transaction with kwargs. This is the entry point to manual tracing instrumentation. A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a new child span within the transaction or any span, call the respective `.start_child()` method. Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded. When used as context managers, spans and transactions are automatically finished at the end of the `with` block. If not using context managers, call the `.finish()` method. When the transaction is finished, it will be sent to Sentry with all its finished child spans. custom_sampling_contextNrq)transaction_contextparent_sampled)sampling_context _experiments max_spansi)maxlenr') rrr to_jsonrr_set_initial_sampling_decisionsampledr;r<r`init_span_recorder)rBrrUrrrs r)rzHub.start_transactions8#)**-F"K"K     eT * * *%////K $/#6#6#8#8)8    788822DT2UUU   = T 3N C G G T T   * *) * < < <r*cdSr&r'rs r) push_scopezHub.push_scope r*cdSr&r'rs r)rzHub.push_scoperr*c|9|5}||dddn #1swxYwYdS|jd\}}|tj|f}|j|t |S)a. Pushes a new layer on the scope stack. :param callback: If provided, this method pushes a scope, calls `callback`, and pops the scope again. :returns: If no `callback` is provided, a context manager that should be used to pop the scope again. Nrk)rrnr.rrh)rBrrtr; new_layers r)rzHub.push_scope#s  "" e               4 B TYu--.  9%%%T"""s /33cZ|j}|js Jd|S)z{ Pops a scope layer from the stack. Try to use the context manager :py:meth:`push_scope` instead. z"stack must have at least one layer)rnr)rBrVs r)pop_scope_unsafezHub.pop_scope_unsafe;s0[__  {@@@@@{ r*cdSr&r'rs r)configure_scopezHub.configure_scopeFrr*cdSr&r'rs r)rzHub.configure_scopeMrr*c|jd\| |dStfd}|S)z Reconfigures the scope. :param callback: If provided, call the callback with the current scope. :returns: If no callback is provided, returns a context manager that returns the scope. rkNc3<KVdStVdSr&r)r;rtsr)innerz"Hub.configure_scope..innerhs-! gg r*)rnr)rBrrr;rts @@r)rzHub.configure_scopeTsh B   !4        uwwr*c||jd\}}t|r |jdnd|r |jdnd|j|_dS)zStarts a new session.rkreleaseN environment)rruser) end_sessionrnr r<_user_sessionrBr;rts r) start_sessionzHub.start_sessionrsl  B  17AFN9--T9?I}55T   r*c|jd\}}|j}|+||||d|j_dS)z)Ends the current session if there is one.rkN)rnrrHcapture_sessionrt)rBr;rtsessions r)rzHub.end_session}sW B .   MMOOO!&&w///" r*c\||jd\}}d|_dS)zStops automatic session tracking. This temporarily session tracking for the current scope when called. To resume session tracking call `resume_auto_session_tracking`. rkFN)rrn_force_auto_session_trackingrs r)stop_auto_session_trackingzHub.stop_auto_session_trackings3  B -2***r*c4|jd\}}d|_dS)zResumes automatic session tracking for the current scope if disabled earlier. This requires that generally automatic session tracking is enabled. rkN)rnrrs r)resume_auto_session_trackingz Hub.resume_auto_session_trackings!  B -1***r*cX|jd\}}||||SdS)z> Alias for :py:meth:`sentry_sdk.Client.flush` rkN)timeoutr)rnflush)rBrrr;rts r)rz Hub.flushs7 B   <<(<CC C  r*c#K|jd\}}|j}|dS|o |jd}|sdSd|fVdS)Nrkpropagate_tracesz sentry-trace)rnrr<to_traceparent)rBr;rtrrs r)iter_trace_propagation_headersz"Hub.iter_trace_propagation_headerssk B z < F!Hfn5G&H  Fd1133333333r*)NNr&)#rOrPrQ__doc__rnrr:rerCrFrMrrrfr;rtrrSrrrrrrrrrrrrrrrrrr'r*r)r9r9sF ( 0""X" ""X" ### ((( *     .: H H H ,),),),)`****\4444l   X   X ####0      X   X <     # # # 3 3 3222 D D D D 4 4 4 4 4r*r9);r.rr contextlibrsentry_sdk._compatrsentry_sdk.scopersentry_sdk.clientrsentry_sdk.tracingr r sentry_sdk.sessionsr sentry_sdk.utilsr r rrsentry_sdk._typesrtypingrrrrrrrrrrrrsentry_sdk.integrationsrrrr r!r"sentry_sdk.constsr#r$r_r6r=objectr?rWrYrr]rhr9rarbr'r*r)rs %%%%%%------""""""$$$$$$00000000''''''#"""""      %%%%%%333333433333 AA ( ) )$...           #"""""      ."5     MM  Dd$-$-$-$-$-$F-$-$-$`p4p4p4p4p4.. ! !p4p4p4fSUU  :r*