Viewing File: /opt/alt/python38/lib/python3.8/site-packages/sentry_sdk/__pycache__/hub.cpython-38.pyc

U

\2@sddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZd	d
ZedZdadd
ZGddde Z!ddZ"Gddde#Z$Gddde Z%Gddde Z&Gddde	e$Z'e'Z(e)e(dS)N)datetime)contextmanager)warn)with_metaclassScope)Client)exc_info_from_errorevent_from_exceptionlogger
ContextVarcCs|SN)xrr/hub.pyoverload srZsentry_current_hubcCstjj}|sdS|jdS)NFZsend_default_pii)Hubcurrentclientoptions)rrrr_should_send_default_pii(src@s$eZdZddZddZddZdS)
_InitGuardcCs
||_dSr
)_client)selfrrrr__init__1sz_InitGuard.__init__cCs|Sr
rrrrr	__enter__4sz_InitGuard.__enter__cCs|j}|dk	r|dSr
)rclose)rexc_type	exc_valuetbcrrr__exit__7sz_InitGuard.__exit__N__name__
__module____qualname__rrr"rrrrr0srcOs4t||}tj|t|}|dk	r0t|a|S)zsInitializes the SDK and optionally integrations.

    This takes the same arguments as the client constructor.
    N)rrrbind_clientrweakrefref_initial_client)argskwargsrrvrrrinit=s

r.c@s$eZdZeddZeddZdS)HubMetacCs(td}|dkr$tt}t||S)z(Returns the current instance of the hub.N)_localgetr
GLOBAL_HUBsetrr-rrrrLs


zHubMeta.currentcCstS)z%Returns the main instance of the hub.)r2rrrrmainVszHubMeta.mainN)r$r%r&propertyrr5rrrrr/Ks
	r/c@seZdZddZddZdS)_HubManagercCstj|_t|dSr
)rr_oldr0r3rhubrrrr]sz_HubManager.__init__cCst|jdSr
)r0r3r8)rrrr rrrr"asz_HubManager.__exit__N)r$r%r&rr"rrrrr7\sr7c@s$eZdZddZddZddZdS)
_ScopeManagercCs"||_t|j|_|jd|_dSN)_hublen_stack
_original_len_layerr9rrrrfsz_ScopeManager.__init__cCs|jd}|dk	st|S)N)rBAssertionError)rscoperrrrks
z_ScopeManager.__enter__cCst|jj}||jkr,td|j|dS||jkrXtd||j|jj|jd|jj|jd}|jj|jdd=|d|jdkrtd|d|jdn |d|jdkrd}t|dS)Nz1Scope popped too soon. Popped %s scopes too many.zLeaked %s scopes: %srCz2Wrong 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.)r?r>r@rArerrorwarningrB)rrrr Zcurrent_lenZlayerrGrrrr"qs2

z_ScopeManager.__exit__Nr#rrrrr;esr;c@seZdZdZdZd)ddZddZddZd	d
ZddZ	e
d
dZddZddZ
d*ddZd+ddZd,ddZddZd-ddZeddZeddZd.d dZeZd!d"Zed#d$Zed%d$Zd/d&d$Zd0d'd(ZdS)1rzThe 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|tr0|}|jd\}}|dkr4t|}n|}|dkrBt}||fg|_d|_g|_dSr<)
isinstancerr@copyr_last_event_id	_old_hubs)rZ
client_or_hubrEr:rZother_scoperrrrs
zHub.__init__cCs|jtjt||Sr
)rKappendrrr0r3rrrrrs
z
Hub.__enter__cCs|j}t|dSr
)rKpopr0r3)rrrr oldrrrr"s
zHub.__exit__c
Cs"||W5QRSQRXdS)z~Runs a callback in the context of the hub.  Alternatively the
        with statement can be used on the hub directly.
        NrrcallbackrrrrunszHub.runcCst|tr|}n|jdk	r"|j}ntd|jdd}|dk	rX|j|}|dk	rX|St}|dk	rj|}|dk	r||k	r|j|dk	rd|f}tt	|ddt
|dS)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 namer=rzIntegration %r attempted to run but it was only enabled on init() but not the client that was bound to the current flow.  Earlier versions of the SDK would consider these integrations enabled but this is no longer the case.)
stacklevel)rHstrZ
identifier
ValueErrorr@Zintegrationsr1r*rWarningrrG)rZ
name_or_classZintegration_namerr-Zinitial_clientrGrrrget_integrations2	

zHub.get_integrationcCs|jddS)z&Returns the current client on the hub.r=rr@rrrrrsz
Hub.clientcCs|jS)zReturns the last event ID.)rJrrrr
last_event_idszHub.last_event_idcCs |jd}||df|jd<dS)zBinds a new client to the hub.r=rCNrX)rnewtoprrrr's
zHub.bind_clientcCs:|jd\}}|dk	r6||||}|dk	r2||_|SdS)akCaptures an event.  The return value is the ID of the event.

        The event is a dictionary following the Sentry v7/v8 protocol
        specification.  Optionally an event hint dict can be passed that
        is used by processors to extract additional information from it.
        Typically the event hint object would contain exception information.
        r=N)r@
capture_eventrJ)reventhintrrEr-rrrr\s	zHub.capture_eventcCs*|jdkrdS|dkrd}|||dS)zyCaptures a message.  The message is just a string.  If no level
        is provided the default level is `info`.
        Ninfo)messagelevel)rr\)rr`rarrrcapture_messages

zHub.capture_messagecCsv|j}|dkrdS|dkr$t}nt|}t||jd\}}z|j||dWStk
rp|tYnXdS)zCaptures an exception.

        The argument passed can be `None` in which case the last exception
        will be reported, otherwise an exception object or an `exc_info`
        tuple.
        N)Zclient_options)r^)	rsysexc_infor	r
rr\	Exception_capture_internal_exception)rrFrrdr]r^rrrcapture_exceptions
zHub.capture_exceptioncCstjd|ddS)zNCapture an exception that is likely caused by a bug in the SDK
        itself.zInternal error in sentry_sdk)rdN)rrF)rrdrrrrf1szHub._capture_internal_exceptioncKs|jd\}}|dkr$tddSt|p,d}|||sBdSt|pJd}|ddkrht|d<|ddkr~d|d<|}|jddk	r|jd||}|dk	r|j	
|ntd	||jd
}t|j	|kr|j	qdS)zAdds a breadcrumb.  The breadcrumbs are a dictionary with the
        data as the sentry v7/v8 protocol expects.  `hint` is an optional
        value that can be used by `before_breadcrumb` to customize the
        breadcrumbs that are emitted.
        r=Nz*Dropped breadcrumb because no client boundrZ	timestamptypedefaultZbefore_breadcrumbz)before breadcrumb dropped breadcrumb (%s)max_breadcrumbs)
r@rr_dictupdater1rZutcnowrZ_breadcrumbsrLr?popleft)rZcrumbr^r,rrEZoriginal_crumbrjrrradd_breadcrumb6s,


zHub.add_breadcrumbcCsdSr
rrrrr
push_scope[szHub.push_scopecCsdSr
rrOrrrro`sc	CsX|dk	r(|}||W5QRXdS|jd\}}|t|f}|j|t|S)zPushes a new layer on the scope stack. Returns a context manager
        that should be used to pop the scope again.  Alternatively a callback
        can be provided that is executed in the context of the scope.
        Nr=)ror@rIrLr;)rrPrErZ	new_layerrrrroes
cCs|j}|jstd|S)zaPops a scope layer from the stack. Try to use the context manager
        `push_scope()` instead.z"stack must have at least one layer)r@rMrDr4rrrpop_scope_unsafexs
zHub.pop_scope_unsafecCsdSr
rrrrrconfigure_scopeszHub.configure_scopecCsdSr
rrOrrrrqscsB|jd\|dk	r*dk	r&|dStfdd}|S)zReconfigures the scope.r=Nc3sdk	rVntVdSr
rrrrErrinnersz"Hub.configure_scope.<locals>.inner)r@r)rrPrsrrrrrqscCs(|jd\}}|dk	r$|j||dSdS)zAlias for self.client.flushr=N)timeoutrP)r@flush)rrtrPrrErrrrusz	Hub.flush)NN)N)N)N)NN)N)N)NN)r$r%r&__doc__r@rrr"rQrWr6rrYr'r\rbrgrfrnrrorErprqrurrrrrs:

)




%





r)*rcrIr(r
contextlibrwarningsrZsentry_sdk._compatrZsentry_sdk.scoperZsentry_sdk.clientrZsentry_sdk.utilsr	r
rrZUnionZAnyZOptionalZDictZTupleZListCallablerZContextManagerZIntegrationr0r*robjectrr.rhr/r7r;rr2r3rrrr<module>s.
	.
Back to Directory File Manager