U 췀gKd @sddlZddlmZddlmZmZmZmZddlm Z ddl m Z ddl m Z ddlmZddlmZmZmZdd lmZmZdd lmZerdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddl%m&Z&ddl m'Z'ddlm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddlm3Z3e#dZ4nddZ Gd d!d!e5Z6ed"d#Z7ed$Z8Gd%d&d&e9Z:Gd'd(d(e e:Z;e7 e;ZZ>dS)*N)contextmanager) get_clientget_global_scopeget_isolation_scopeget_current_scope)with_metaclass) INSTRUMENTER) _ScopeManager)Client)NoOpSpanSpan Transaction)logger ContextVar) TYPE_CHECKING)Any)Callable)ContextManager)Dict) Generator)List)Optional)overload)Tuple)Type)TypeVar)Union)Unpack)Scope) BaseClient) Integration)EventHint BreadcrumbBreadcrumbHintExcInfo LogLevelStrSamplingContext)TransactionKwargsTcCs|SN)xr+r+Utility function to suppress deprecation warnings for the Hub.ignore)categoryN)warningscatch_warningsfilterwarningsr.r+r+r+r-!_suppress_hub_deprecation_warningSs r@Zsentry_current_hubc@s$eZdZeddZeddZdS)HubMetac CsJtjtddtd}|dkrFttt}W5QRXt||S)z(Returns the current instance of the hub. stacklevelN) r=warnr._localgetr@Hub GLOBAL_HUBset)clsrvr+r+r-current`s  zHubMeta.currentcCstjtddtS)z%Returns the main instance of the hub.rBrC)r=rEr.rI)rKr+r+r-mainmsz HubMeta.mainN)r6r7r8propertyrMrNr+r+r+r-rA_s rAc@sheZdZdZdZdZer dZdZdAddZ ddZ ddZ d d Z d d Z ed dZeddZddZddZdBddZdCddZdDddZdEddZejfddZdejdfdd ZdFd!d"ZedGd#d$Zed%d$ZdHd'd$Zd(d)ZedId*d+Zed,d+ZdJd-d+ZdKd/d0Z d1d2Z!d3d4Z"d5d6Z#dLd7d8Z$d9d:Z%d;d<Z&dMd=d>Z'dNd?d@Z(dS)OrHa .. deprecated:: 2.0.0 The Hub is deprecated. Its functionality will be merged into :py:class:`sentry_sdk.scope.Scope`. The 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. NcCstjtddd}t|trBt}|dkrRt}t}n|}t ||dkrft}t}|dkrtt}||fg|_ d|_ g|_ g|_g|_||_||_dS)NrBrC)r=rEr. isinstancerHrrforkrr set_client_stack_last_event_id _old_hubs_old_current_scopes_old_isolation_scopes_current_scope_scope)r2Z client_or_hubscope current_scopeclientr+r+r-r0s*     z Hub.__init__cCs\|jtjt|t}|j|tj |j t }|j |tj |j |Sr*)rUappendrHrMrFrJrrVrZrXrrW_isolation_scoperY)r2r[isolation_scoper+r+r- __enter__s   z Hub.__enter__cCsD|j}t||j}tj||j}tj|dSr*) rUpoprFrJrVrZrXrWr^)r2exc_type exc_valuetboldZold_current_scopeZold_isolation_scoper+r+r-__exit__s      z Hub.__exit__c Cs"||W5QRSQRXdS)z .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Runs a callback in the context of the hub. Alternatively the with statement can be used on the hub directly. Nr+r2callbackr+r+r-runs zHub.runcCs t|S)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.client._Client.get_integration` instead. Returns 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. )rget_integration)r2Z name_or_classr+r+r-rjszHub.get_integrationcCst}|sdS|S)z .. deprecated:: 2.0.0 This property is deprecated and will be removed in a future release. Please use :py:func:`sentry_sdk.api.get_client` instead. Returns the current client on the hub. N)rZ is_active)r2r\r+r+r-r\s z Hub.clientcCstS)z .. deprecated:: 2.0.0 This property is deprecated and will be removed in a future release. Returns the current scope on the hub. )rr2r+r+r-rZsz Hub.scopecCstd|jS)a Returns the last event ID. .. deprecated:: 1.40.5 This function is deprecated and will be removed in a future release. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly. zDeprecated: last_event_id is deprecated. This will be removed in the future. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly.)rwarningrTrkr+r+r- last_event_id szHub.last_event_idcCst|dS)z .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.set_client` instead. Binds a new client to the hub. N)rrR)r2newr+r+r- bind_clients zHub.bind_clientcKs>tj||fd|i|}|ddk}|dk r:|s:||_|S)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.capture_event` instead. Captures an event. Alias of :py:meth:`sentry_sdk.Scope.capture_event`. :param event: A ready-made event that can be directly sent to Sentry. :param hint: Contains metadata about the event that can be read from `before_send`, such as the original exception object or a HTTP request object. :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events. The `scope` and `scope_kwargs` parameters are mutually exclusive. :param scope_kwargs: Optional data to apply to event. For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`. The `scope` and `scope_kwargs` parameters are mutually exclusive. rZtype transactionN)r capture_eventrGrT)r2eventhintrZ scope_kwargsrmZis_transactionr+r+r-rr$s zHub.capture_eventcKs,tj|f||d|}|dk r(||_|S)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.capture_message` instead. Captures a message. Alias of :py:meth:`sentry_sdk.Scope.capture_message`. :param message: The string to send as the message to Sentry. :param level: If no level is provided, the default level is `info`. :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events. The `scope` and `scope_kwargs` parameters are mutually exclusive. :param scope_kwargs: Optional data to apply to event. For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`. The `scope` and `scope_kwargs` parameters are mutually exclusive. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`). )levelrZN)rcapture_messagerT)r2messagervrZrurmr+r+r-rwDszHub.capture_messagecKs*tj|fd|i|}|dk r&||_|S)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.capture_exception` instead. Captures an exception. Alias of :py:meth:`sentry_sdk.Scope.capture_exception`. :param error: An exception to capture. If `None`, `sys.exc_info()` will be used. :param scope: An optional :py:class:`sentry_sdk.Scope` to apply to events. The `scope` and `scope_kwargs` parameters are mutually exclusive. :param scope_kwargs: Optional data to apply to event. For supported `**scope_kwargs` see :py:meth:`sentry_sdk.Scope.update_from_kwargs`. The `scope` and `scope_kwargs` parameters are mutually exclusive. :returns: An `event_id` if the SDK decided to send the event (see :py:meth:`sentry_sdk.client._Client.capture_event`). rZN)rcapture_exceptionrT)r2errorrZrurmr+r+r-ryeszHub.capture_exceptioncKstj||f|dS)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.add_breadcrumb` instead. 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. N)radd_breadcrumb)r2Zcrumbrtkwargsr+r+r-r{szHub.add_breadcrumbcKst}|jfd|i|S)aJ .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.start_span` instead. 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`. instrumenter)r start_span)r2r}r|rZr+r+r-r~szHub.start_spancKs t}||d<|j|||f|S)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.start_transaction` instead. 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`. Zhub)rstart_transaction)r2rqr}Zcustom_sampling_contextr|rZr+r+r-rs$zHub.start_transactioncCstj||||dS)a  .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.continue_trace` instead. Sets the propagation context from environment or headers and returns a transaction. )environ_or_headersopnamesource)rcontinue_trace)r2rrrrr+r+r-rs zHub.continue_tracecCsdSr*r+rgr+r+r- push_scopeszHub.push_scopecCsdSr*r+rgr+r+r-rsTc Cs0|dk r(|}||W5QRXdSt|S)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. 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. N)rr )r2rhrrZr+r+r-rs  cCs|j}|jstd|S)z .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. 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)rSraAssertionError)r2rLr+r+r-pop_scope_unsafes zHub.pop_scope_unsafecCsdSr*r+rgr+r+r-configure_scopeszHub.configure_scopecCsdSr*r+rgr+r+r-r$scs<t|r|dk r&|dStfdd}|S)aK .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. 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. Nc3s VdSr*r+r+rZr+r-innerFsz"Hub.configure_scope..inner)rZgenerate_propagation_contextr)r2rhrrr+rr-r+s applicationcCstj|ddS)z .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.start_session` instead. Starts a new session. ) session_modeN)r start_session)r2rr+r+r-rMs zHub.start_sessioncCstdS)z .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.end_session` instead. Ends the current session if there is one. N)r end_sessionrkr+r+r-r\s zHub.end_sessioncCstdS)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.stop_auto_session_tracking` instead. Stops automatic session tracking. This temporarily session tracking for the current scope when called. To resume session tracking call `resume_auto_session_tracking`. N)rstop_auto_session_trackingrkr+r+r-rgs zHub.stop_auto_session_trackingcCstdS)a} .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.resume_auto_session_tracking` instead. Resumes automatic session tracking for the current scope if disabled earlier. This requires that generally automatic session tracking is enabled. N)rresume_auto_session_trackingrkr+r+r-rus z Hub.resume_auto_session_trackingcCstj||dS)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.client._Client.flush` instead. Alias for :py:meth:`sentry_sdk.client._Client.flush` )timeoutrh)rflush)r2rrhr+r+r-rs z Hub.flushcCs(t}|}|dkr$t}|}|S)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.get_traceparent` instead. Returns the traceparent either from the active span or from the scope. N)rget_traceparentr)r2r[Z traceparentr_r+r+r-rs zHub.get_traceparentcCs8t}|}|dkr$t}|}|dk r4|SdS)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.get_baggage` instead. Returns Baggage either from the active span or from the scope. N)r get_baggager serialize)r2r[Zbaggager_r+r+r-rs zHub.get_baggagecCstj|dS)a .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.iter_trace_propagation_headers` instead. Return HTTP headers which allow propagation of trace data. Data taken from the span representing the request, if available, or the current span on the scope if not. span)riter_trace_propagation_headersr2rr+r+r-rs z"Hub.iter_trace_propagation_headerscCs |dk rtdtj|dS)aE .. deprecated:: 2.0.0 This function is deprecated and will be removed in a future release. Please use :py:meth:`sentry_sdk.Scope.trace_propagation_meta` instead. 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.r)rrlrtrace_propagation_metarr+r+r-rs zHub.trace_propagation_meta)NN)NN)NN)NN)NN)NNN)N)NT)N)NT)r)NN)N)N))r6r7r8r9rSrYrrMrNr0r`rfrirjrOr\rZrmrorrrwryr{rZSENTRYr~rrrrrrrrrrrrrrrr+r+r+r-rHust  &    !   /       #    rHr)?r= contextlibrZ sentry_sdkrrrrZsentry_sdk._compatrZsentry_sdk.constsrZsentry_sdk.scoper Zsentry_sdk.clientr Zsentry_sdk.tracingr r r Zsentry_sdk.utilsrrtypingrrrrrrrrrrrrrtyping_extensionsrrrZsentry_sdk.integrationsr Zsentry_sdk._typesr!r"r#r$r%r&r'r(r)DeprecationWarningr.r@rFrprArHrIrJrZr+r+r+r-sX                      $   j