bgiddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZmZmZmZmZdd lmZdd lmZmZdd lmZmZmZmZdd lm Z e rnddl!m"Z"ddl!m#Z#ddl!m$Z$ddl!m%Z%ddl!m&Z&ddl!m'Z'ddl!m(Z(ddl!m)Z)ddl!m*Z*ddl!m+Z+ddl!m,Z,ddl!m-Z-ddl.m/Z/ddlm0Z0m1Z1m2Z2m3Z3m4Z4ddlm5Z5e+dZ6ndZ,edZ7d Z8d!Z9Gd"d#e:Z;d$Zn d(Z>Gd)d*e?Z@Gd+d,e:ZAGd-d.ee@ZBeBZCe7DeCdS)/N)datetime)contextmanager)with_metaclass) INSTRUMENTERScope)Client)Profile)NoOpSpanSpan TransactionBAGGAGE_HEADER_NAMESENTRY_TRACE_HEADER_NAME)Session)has_tracing_enablednormalize_incoming_data)exc_info_from_errorevent_from_exceptionlogger ContextVar) TYPE_CHECKING)Union)Any)Optional)Tuple)Dict)List)Callable) Generator)Type)TypeVar)overload)ContextManager) Integration)EventHint BreadcrumbBreadcrumbHintExcInfo)ClientConstructorTc|SN)xs E/opt/cloudlinux/venv/lib64/python3.11/site-packages/sentry_sdk/hub.pyr"r">ssentry_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 r0 _update_scoper=Fs; ;9:::ioo L ! ! 8 L % % % %  ) ), 7 7 7 7 ioo & &666666 r1cFtjj}|sdS|jdS)NFsend_default_pii)Hubcurrentclientoptions)rBs r0_should_send_default_piirDXs' [ F u >, --r1c eZdZdZdZdZdS) _InitGuardc||_dSr-)_client)selfrBs r0__init__z_InitGuard.__init__as  r1c|Sr-r.rIs r0 __enter__z_InitGuard.__enter__es r1cD|j}||dSdSr-)rHclose)rIexc_type exc_valuetbcs r0__exit__z_InitGuard.__exit__is& L = GGIIIII =r1N__name__ __module__ __qualname__rJrMrTr.r1r0rFrF`sAr1rFctjdd}|dks|dkr3tjddj|tjddSdS)N))r[z1sentry-sdk 2.0.0 will drop support for Python %s.z{}.{}zQPlease upgrade to the latest version to continue receiving upgrades and bugfixes.)sys version_inforwarningformat)versions r0_check_python_deprecationsrcpsvrr"G&Gv-- ? GNG $     _     .-r1ct|i|}tj|t t |}|S)zsInitializes the SDK and optionally integrations. This takes the same arguments as the client constructor. )r r@rA bind_clientrcrF)argskwargsrBrvs r0_initri~sJ T $V $ $FKF###   F  B Ir1ceZdZdS)initN)rVrWrXr.r1r0rkrks r1rkctSr-)rir.r1r0rmsEr1c:eZdZedZedZdS)HubMetactd}|.tt}t||S)z(Returns the current instance of the hub.N)_localgetr@ GLOBAL_HUBset)clsrhs r0rAzHubMeta.currents9ZZ   :ZB JJrNNN r1ctS)z%Returns the main instance of the hub.)rs)rus r0mainz HubMeta.mains r1N)rVrWrXpropertyrArwr.r1r0rorosH XXr1roc eZdZdZdZdZdS) _ScopeManagercj||_t|j|_|jd|_dSN)_hublen_stack _original_len_layer)rIhubs r0rJz_ScopeManager.__init__s*  __jn r1c(|jd}|J|S)N)r)rIscopes r0rMz_ScopeManager.__enter__s A    r1cLt|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: %srz2Wrong 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.)rr~rrrerrorr`r)rIrPrQrR current_lenlayerr`s r0rTz_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 # # # # #( 'r1NrUr.r1r0rzrzsA%%%  $ $ $ $ $r1rzceZdZdZdZerdZdZ d&dZdZ dZ dZ dZ e dZe d Zd Zd Zd&d Zd&d Zd&dZdZd&dZdejfdZdejfdZd'dZe d(dZedZ d)dZdZe d(dZedZ d)dZ d*dZ dZ!dZ"d Z# d&d!Z$d"Z%d#Z&d(d$Z'd(d%Z(dS)+r@zThe 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|_dSr|) isinstancer@rr5r_last_event_id _old_hubs)rI client_or_hubrrrB other_scopes r0rJz Hub.__init__st mS ) ) #C"%*R. FK} +.."F =GGE' "r1c|jtjt||Sr-)rappendr@rArqrtrLs r0rMz Hub.__enter__s1 ck*** 4 r1cl|j}t|dSr-)rpoprqrt)rIrPrQrRolds r0rTz Hub.__exit__ s*n  "" 3r1cN|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.rIcallbacks r0runzHub.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)rstr identifier ValueErrorrB integrationsrr)rI name_or_classintegration_namerBrhs r0get_integrationzHub.get_integrations~ mS ) ) 8,    % 1,7  677 7  $(()9::B~   ~r1c(|jddS)z&Returns the current client on the hub.r}rrrLs r0rBz Hub.client7{2q!!r1c(|jddS)z%Returns the current scope on the hub.r}rrrLs r0rz Hub.scope=rr1c|jS)zReturns the last event ID.)rrLs r0 last_event_idzHub.last_event_idCs ""r1cD|jd}||df|jd<dS)zBinds a new client to the hub.r}rNr)rInewtops r0rezHub.bind_clientHs& k"oA- Br1c |jd\}}t|||}|=|ddk}||||}| |s||_|SdS)z Captures an event. Alias of :py:meth:`sentry_sdk.Client.capture_event`. :param scope_args: For supported `**scope_args` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`. r}Ntype transaction)rr=rr capture_eventr) rIeventhintr scope_argsrB top_scopeis_transactionrhs r0rzHub.capture_eventPss!KO i ;;  "YYv..-?N%%eT599B~n~&(#Itr1c B|jdS|d}|j||dfd|i|S)a Captures a message. :param message: The string to send as the message. :param level: If no level is provided, the default level is `info`. :param scope: An optional :py:class:`sentry_sdk.Scope` to use. :param scope_args: For supported `**scope_args` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.Client.capture_event`). Ninfo)messagelevelr)rBr)rIrrrrs r0capture_messagezHub.capture_messagedsR ; 4 =E!t!% 0 0  8= AK   r1c (|j}|dS|t|}ntj}t ||j\}} |j|f||d|S#t$r)|tjYnwxYwdS)ahCaptures an exception. :param error: An exception to catch. If `None`, `sys.exc_info()` will be used. :param scope_args: For supported `**scope_args` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.Client.capture_event`). N)client_options)rr) rBrr^exc_inforrCr Exception_capture_internal_exception)rIrrrrBrrrs r0capture_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)rr)rIrs r0rzHub._capture_internal_exceptions   3hGGGGGGr1c |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. r}Nz*Dropped breadcrumb because no client boundr. timestamprdefaultbefore_breadcrumbz)before breadcrumb dropped breadcrumb (%s)max_breadcrumbs) rrrdictupdaterrrutcnowrC _breadcrumbsrrpopleft)rIcrumbrrgrBr new_crumbrs r0add_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   & & ( ( (%$%%777777r1c |jo|jjd}||krtSt|tsd|vr|d}t|tr)t j|||Sd|vr8t j||d}|jd d|i|S||S| d||j j }| |j d i|Sd|vr:| }|r|dd nd}|||d<td i|S) a Start a span whose parent is the currently active span or transaction, if any. The return value is a :py:class:`sentry_sdk.tracing.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 :py:meth:`sentry_sdk.start_transaction` to start a new transaction when one is not already in progress. For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Span`. instrumenterrzcDeprecated: use start_transaction to start transactions and Transaction.start_child to start spans.nameNrtrace_id-rr.)rBrCr rr rr`start_transactionr setdefaultrspan start_childget_traceparentsplitr ) rIrrrgconfiguration_instrumenterdeprecation_msgr traceparentrs r0 start_spanzHub.start_spans"&*[%XT[5H5X" 5 5 5::  dK ( ( CMV,C,C: $ ,, 4///--d333&&///zz-00-t-BB4B6BBB  K%&&&z  #4#--f-- - V # #..00K4?I{((--a00TH#%-z"~~f~~r1c F|jo|jjd}||krtS|di}|"|d|t d i|}||jd}||| |t||}| ||j rD|jo$|jjd d pd }| | |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. For supported `**kwargs` see :py:class:`sentry_sdk.tracing.Transaction`. rcustom_sampling_contextNr)transaction_contextparent_sampled)sampling_context)r _experiments max_spansi)maxlenr.)rBrCr rrr to_jsonrr_set_initial_sampling_decisionr sampledrrinit_span_recorder) rIrrrgrrrprofilers r0rzHub.start_transactionsO8&*[%XT[5H5X" 5 5 5:: "(**-F"K"K     eT * * *%////K $/#6#6#8#8)8    788822DT2UUU+4000..@P.QQQ   = T 3N C G G T T   * *) * < < <r1c|5}||dddn #1swxYwYtjt ||||}|S)ze Sets the propagation context from environment or headers and returns a transaction. N)oprsource)configure_scopegenerate_propagation_contextr continue_from_headersr)rIenviron_or_headersrrrrrs r0continue_tracezHub.continue_traceBs  ! ! # # Cu  . ./A B B B C C C C C C C C C C C C C C C"7 #$6 7 7    s 7;;cdSr-r.rs r0 push_scopezHub.push_scopeR r1cdSr-r.rs r0rzHub.push_scopeYrr1TcF|9|5}||dddn #1swxYwYdS|jd\}}tj|}|r|||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. Nr})rrr5rrrz)rIrrrrB new_scope new_layers r0rzHub.push_scope`s  "" e               4 B Ie$$  5  2 2 4 4 4Y'  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)rr)rIrhs r0pop_scope_unsafezHub.pop_scope_unsafes0[__  {@@@@@{ r1cdSr-r.rs r0rzHub.configure_scoperr1cdSr-r.rs r0rzHub.configure_scoperr1c|jd\|r| |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. r}Nc3<KVdStVdSr-r)rBrsr0innerz"Hub.configure_scope..inners-! gg r1)rrr)rIrrrrBrs @@r0rzHub.configure_scopes B   1  . . 0 0 0  !4        uwwr1 applicationc||jd\}}t|r |jdnd|r |jdnd|j||_dS)zStarts a new session.r}releaseN environment)rruser session_mode) end_sessionrrrC_user_session)rIrrBrs r0 start_sessionzHub.start_sessionso  B  17AFN9--T9?I}55T%    r1c|jd\}}|j}d|j_|-||||dSdSdS)z)Ends the current session if there is one.r}N)rrrrOcapture_session)rIrBrsessions r0rzHub.end_sessionse B ."    MMOOO!&&w/////  !!r1c\||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`. r}FN)rr_force_auto_session_trackingrIrBrs r0stop_auto_session_trackingzHub.stop_auto_session_trackings3  B -2***r1c4|jd\}}d|_dS)zResumes automatic session tracking for the current scope if disabled earlier. This requires that generally automatic session tracking is enabled. r}N)rrrs r0resume_auto_session_trackingz Hub.resume_auto_session_trackings!  B -1***r1cX|jd\}}||||SdS)z> Alias for :py:meth:`sentry_sdk.Client.flush` r}N)timeoutr)rflush)rIrrrBrs r0rz Hub.flushs7 B   <<(<CC C  r1c|jCt|jjr*|jj|jjS|jS)zX Returns the traceparent either from the active span or from the scope. )rBrrCrrto_traceparentrrLs r0rzHub.get_traceparentsT ; ""4;#677 8DJON++--     *1133     r1c|tjdd}|}||dtd|dz }|}||dt d|dz }|S)z Return meta tags which should be injected into HTML templates to allow propagation of trace information. NzaThe parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future.z )rr`rrrr)rIrmeta sentry_tracers r0trace_propagation_metazHub.trace_propagation_meta+s   Ns   ++--  # D(((  D ""$$   D### D  r1)NN)NNNr-)NT)r))rVrWrX__doc__rrrArwrJrMrTrrrxrBrrrerrrrrrSENTRYrrrr"rrrr rrrrrrr!r&r.r1r0r@r@s F( 0""X" ""X" ### ((((    06 H H H')')')')R#1D6666r\-@<<<<|    X   X ####@      X   X """"J)      0 0 0 3 3 3222 D D D D , , ,&*r1r@)Er5r^r contextlibrsentry_sdk._compatrsentry_sdk.constsrsentry_sdk.scopersentry_sdk.clientr sentry_sdk.profilerr sentry_sdk.tracingr r r rrsentry_sdk.sessionrsentry_sdk.tracing_utilsrrsentry_sdk.utilsrrrrsentry_sdk._typesrtypingrrrrrrrrr r!r"r#sentry_sdk.integrationsr$r%r&r'r(r)r*r+rqr=rDobjectrFrcrirkrrorzr@rsrtr.r1r0r7s_ %%%%%%------******""""""$$$$$$'''''''&&&&& ,+++++      %%%%%%333333433333 AA ( ) )$...               ,+++++      *     MM  Dd$-$-$-$-$-$F-$-$-$`e e e e e .. ! !e e e PSUU  :r1