HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/sentry_sdk/__pycache__/hub.cpython-37.pyc
B

Ta|V�@sddlZddlZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
ddlmZdd	lmZmZmZmZdd
lmZe�r`ddlmZdd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!d�Z-ndd�Z"ed�Z.dd�Z/d d!�Z0Gd"d#�d#e1�Z2d$d%�Z3dd
lmZe�r�Gd&d'�d'e,e#e�Z4n
d(d)��Z4Gd*d+�d+e5�Z6Gd,d-�d-e1�Z7Gd.d/�d/ee6��Z8e8�Z9e.�:e9�dS)0�N)�datetime)�contextmanager)�with_metaclass)�Scope)�Client)�Span�Transaction)�Session)�exc_info_from_error�event_from_exception�logger�
ContextVar)�MYPY)�Union)�Any)�Optional)�Tuple)�Dict)�List)�Callable)�	Generator)�Type)�TypeVar)�overload)�ContextManager)�Integration)�Event�Hint�
Breadcrumb�BreadcrumbHint�ExcInfo)�ClientConstructor�TcCs|S)N�)�xr#r#�?/opt/alt/python37/lib/python3.7/site-packages/sentry_sdk/hub.pyr1srZsentry_current_hubcCsd|r|rtd��|dk	r@t�|�}t|�r4||�q`|�|�n |r\t�|�}|jf|�n|}|S)Nzcannot provide scope and kwargs)�	TypeError�copy�callableZupdate_from_scopeZupdate_from_kwargs)�baseZscope_changeZscope_kwargsZfinal_scoper#r#r%�
_update_scope9s


r*cCstjj}|sdS|jdS)NFZsend_default_pii)�Hub�current�client�options)r-r#r#r%�_should_send_default_piiKsr/c@s$eZdZdd�Zdd�Zdd�ZdS)�
_InitGuardcCs
||_dS)N)�_client)�selfr-r#r#r%�__init__Tsz_InitGuard.__init__cCs|S)Nr#)r2r#r#r%�	__enter__Xsz_InitGuard.__enter__cCs|j}|dk	r|��dS)N)r1�close)r2�exc_type�	exc_value�tb�cr#r#r%�__exit__\sz_InitGuard.__exit__N)�__name__�
__module__�__qualname__r3r4r:r#r#r#r%r0Ssr0cOs"t||�}tj�|�t|�}|S)zsInitializes the SDK and optionally integrations.

    This takes the same arguments as the client constructor.
    )rr+r,�bind_clientr0)�args�kwargsr-�rvr#r#r%�_initcs
rBc@seZdZdS)�initN)r;r<r=r#r#r#r%rCxsrCcCstS)N)rBr#r#r#r%�<lambda>��rDc@s$eZdZedd��Zedd��ZdS)�HubMetacCs(t�d�}|dkr$tt�}t�|�|S)z(Returns the current instance of the hub.N)�_local�getr+�
GLOBAL_HUB�set)�clsrAr#r#r%r,�s


zHubMeta.currentcCstS)z%Returns the main instance of the hub.)rI)rKr#r#r%�main�szHubMeta.mainN)r;r<r=�propertyr,rLr#r#r#r%rF�s
rFc@s$eZdZdd�Zdd�Zdd�ZdS)�
_ScopeManagercCs"||_t|j�|_|jd|_dS)N���)�_hub�len�_stack�
_original_len�_layer)r2�hubr#r#r%r3�sz_ScopeManager.__init__cCs|jd}|dk	st�|S)N�)rT�AssertionError)r2�scoper#r#r%r4�s
z_ScopeManager.__enter__cCs�t|jj�}||jkr,t�d|j|�dS||jkrXt�d||j|jj|jd��|jj|jd}|jj|jdd�=|d|jdkr�t�d|d|jd�n |d|jdkr�d}t�|�dS)Nz1Scope popped too soon. Popped %s scopes too many.zLeaked %s scopes: %srVz2Wrong scope found. Meant to pop %s, but popped %s.rz�init() 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.)rQrPrRrSr�error�warningrT)r2r6r7r8Zcurrent_lenZlayerrZr#r#r%r:�s*

z_ScopeManager.__exit__N)r;r<r=r3r4r:r#r#r#r%rN�srNc@s<eZdZdZdZerdZdZd:dd�Zdd�Z	dd�Z
d	d
�Zdd�Ze
d
d��Ze
dd��Zdd�Zdd�Zd;dd�Zd<dd�Zd=dd�Zdd�Zd>dd�Zd?dd �Zd@d!d"�ZedAd#d$��Zed%d$��ZdBd&d$�Zd'd(�ZedCd)d*��Zed+d*��ZdDd,d*�ZdEd.d/�Zd0d1�Zd2d3�Zd4d5�Z dFd6d7�Z!dGd8d9�Z"dS)Hr+z�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.
    NcCs^t|t�r0|}|jd\}}|dkr4t�|�}n|}|dkrBt�}||fg|_d|_g|_dS)NrO)�
isinstancer+rRr'r�_last_event_id�	_old_hubs)r2Z
client_or_hubrXrUr-Zother_scoper#r#r%r3�s
zHub.__init__cCs|j�tj�t�|�|S)N)r]�appendr+r,rGrJ)r2r#r#r%r4�s
z
Hub.__enter__cCs|j��}t�|�dS)N)r]�poprGrJ)r2r6r7r8�oldr#r#r%r:�s
zHub.__exit__c	Cs|�|�SQRXdS)z~Runs a callback in the context of the hub.  Alternatively the
        with statement can be used on the hub directly.
        Nr#)r2�callbackr#r#r%�run�szHub.runcCsTt|t�r|}n|jdk	r"|j}ntd��|j}|dk	rP|j�|�}|dk	rP|SdS)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-ZintegrationsrH)r2Z
name_or_classZintegration_namer-rAr#r#r%�get_integrations

zHub.get_integrationcCs|jddS)z&Returns the current client on the hub.rOr)rR)r2r#r#r%r-sz
Hub.clientcCs|jddS)z%Returns the current scope on the hub.rOrV)rR)r2r#r#r%rX"sz	Hub.scopecCs|jS)zReturns the last event ID.)r\)r2r#r#r%�
last_event_id(szHub.last_event_idcCs |jd}||df|jd<dS)zBinds a new client to the hub.rOrVN)rR)r2�new�topr#r#r%r>-s
zHub.bind_clientcKsF|jd\}}t|||�}|dk	rB|�|||�}|dk	r>||_|SdS)zGCaptures an event. Alias of :py:meth:`sentry_sdk.Client.capture_event`.rON)rRr*�
capture_eventr\)r2�event�hintrX�
scope_argsr-Z	top_scoperAr#r#r%rj5s	zHub.capture_eventcKs6|jdkrdS|dkrd}|j||d�fd|i|��S)z�Captures 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`).
        N�info)�message�levelrX)r-rj)r2rorprXrmr#r#r%�capture_messageGs
zHub.capture_messagecKs~|j}|dkrdS|dk	r$t|�}nt��}t||jd�\}}y|j|f||d�|��Stk
rx|�t���YnXdS)z�Captures 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)Zclient_options)rlrX)	r-r
�sys�exc_inforr.rj�	Exception�_capture_internal_exception)r2rYrXrmr-rsrkrlr#r#r%�capture_exception\s

zHub.capture_exceptioncCstjd|d�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)rsN)rrY)r2rsr#r#r%ruys
zHub._capture_internal_exceptioncKs�|jd\}}|dkr$t�d�dSt|p,d�}|�|�|sBdSt|pJd�}|�d�dkrht��|d<|�d�dkr~d|d<|jddk	r�|jd||�}n|}|dk	r�|j	�
|�nt�d	|�|jd
}xt|j	�|kr�|j	��q�WdS)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.
        rONz*Dropped breadcrumb because no client boundr#�	timestamp�type�defaultZbefore_breadcrumbz)before breadcrumb dropped breadcrumb (%s)�max_breadcrumbs)
rRrrn�dict�updaterHr�utcnowr.Z_breadcrumbsr^rQ�popleft)r2Zcrumbrlr@r-rXZ	new_crumbrzr#r#r%�add_breadcrumb�s,


zHub.add_breadcrumbcKs�t|t�sd|krdd}t|t�r4t�|�|�|�Sd|krdt�|�|�d�}|jfd|i|��S|dk	rp|S|�d|�|jj}|dk	r�|j	f|�St
f|�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.�nameNrU)r[rrrZ�start_transactionr_�
setdefaultrX�spanZstart_childr)r2r�r@Zdeprecation_msgr�r#r#r%�
start_span�s 




zHub.start_spancKs�|�di�}|dkr*|�d|�tf|�}|��|jd�}|�|�|j|d�|jr~|jrn|jj	d�
d�ppd}|j|d	�|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_contextNrU)Ztransaction_context�parent_sampled)�sampling_contextZ_experiments�	max_spansi�)�maxlen)r_r�rZto_jsonr�r|Z_set_initial_sampling_decisionZsampledr-r.rHZinit_span_recorder)r2r�r@r�r�r�r#r#r%r��s


zHub.start_transactioncCsdS)Nr#)r2rar#r#r%�
push_scopeszHub.push_scopecCsdS)Nr#)r2rar#r#r%r�sc	CsX|dk	r(|���}||�WdQRXdS|jd\}}|t�|�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.
        NrO)r�rRr'r^rN)r2rarXr-Z	new_layerr#r#r%r�#s

cCs|j��}|jstd��|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)rRr_rW)r2rAr#r#r%�pop_scope_unsafe;s
zHub.pop_scope_unsafecCsdS)Nr#)r2rar#r#r%�configure_scopeFszHub.configure_scopecCsdS)Nr#)r2rar#r#r%r�MscsB|jd\��|dk	r*�dk	r&|��dSt��fdd��}|�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.
        rONc3s�dk	r�Vnt�VdS)N)rr#)r-rXr#r%�innerhsz"Hub.configure_scope.<locals>.inner)rRr)r2rar�r#)r-rXr%r�Ts
�applicationcCsJ|��|jd\}}t|r&|jdnd|r6|jdnd|j|d�|_dS)zStarts a new session.rO�releaseN�environment)r�r��user�session_mode)�end_sessionrRr	r.�_user�_session)r2r�r-rXr#r#r%�
start_sessionrszHub.start_sessioncCsB|jd\}}|j}d|j_|dk	r>|��|dk	r>|�|�dS)z)Ends the current session if there is one.rON)rRr�rXr5Zcapture_session)r2r-rXZsessionr#r#r%r��szHub.end_sessioncCs |��|jd\}}d|_dS)z�Stops automatic session tracking.

        This temporarily session tracking for the current scope when called.
        To resume session tracking call `resume_auto_session_tracking`.
        rOFN)r�rR�_force_auto_session_tracking)r2r-rXr#r#r%�stop_auto_session_tracking�szHub.stop_auto_session_trackingcCs|jd\}}d|_dS)z�Resumes automatic session tracking for the current scope if
        disabled earlier.  This requires that generally automatic session
        tracking is enabled.
        rON)rRr�)r2r-rXr#r#r%�resume_auto_session_tracking�sz Hub.resume_auto_session_trackingcCs(|jd\}}|dk	r$|j||d�SdS)z>
        Alias for :py:meth:`sentry_sdk.Client.flush`
        rON)�timeoutra)rR�flush)r2r�rar-rXr#r#r%r��s	z	Hub.flushccsJ|p
|jj}|sdS|jdd}|o.|jd}|s8dSd|��fVdS)z�
        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.
        NrOr�propagate_traceszsentry-trace)rXr�rRr.Zto_traceparent)r2r�r-r�r#r#r%�iter_trace_propagation_headers�sz"Hub.iter_trace_propagation_headers)NN)NN)NN)NN)NN)N)N)N)N)N)N)r�)NN)N)#r;r<r=�__doc__rRrr,rLr3r4r:rbrfrMr-rXrgr>rjrqrvrurr�r�rr�r�r�r�r�r�r�r�r�r#r#r#r%r+�sT






-
,
4





r+);r'rrr�
contextlibrZsentry_sdk._compatrZsentry_sdk.scoperZsentry_sdk.clientrZsentry_sdk.tracingrrZsentry_sdk.sessionr	Zsentry_sdk.utilsr
rrr
Zsentry_sdk._typesr�typingrrrrrrrrrrrrZsentry_sdk.integrationsrrrrrr Zsentry_sdk.constsr!r"rGr*r/�objectr0rBrCrxrFrNr+rIrJr#r#r#r%�<module>sZ
	
0~