Viewing File: /opt/alt/python35/lib/python3.5/site-packages/sentry_sdk/__pycache__/hub.cpython-35.pyc



\2@sjddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZmZmZmZd	d
ZedZdadd
ZGdddeZddZGdddeZGdddeZGdddeZGddde	eZeZej edS)N)datetime)contextmanager)warn)with_metaclass)Scope)Client)exc_info_from_errorevent_from_exceptionlogger
ContextVarcCs|S)N)xrr/hub.pyoverload srZsentry_current_hubcCs!tjj}|sdS|jdS)NFZsend_default_pii)Hubcurrentclientoptions)rrrr_should_send_default_pii(src@s4eZdZddZddZddZdS)
_InitGuardcCs
||_dS)N)_client)selfrrrr__init__1sz_InitGuard.__init__cCs|S)Nr)rrrr	__enter__4sz_InitGuard.__enter__cCs#|j}|dk	r|jdS)N)rclose)rexc_type	exc_valuetbcrrr__exit__7s	z_InitGuard.__exit__N)__name__
__module____qualname__rrrrrrrr0srcOsJt||}tjj|t|}|dk	rFtj|a|S)zsInitializes the SDK and optionally integrations.

    This takes the same arguments as the client constructor.
    N)rrrbind_clientrweakrefref_initial_client)argskwargsrrvrrrinit=sr*c@s4eZdZeddZeddZdS)HubMetacCs8tjd}|dkr4tt}tj||S)z(Returns the current instance of the hub.N)_localgetr
GLOBAL_HUBset)rr)rrrrLs

zHubMeta.currentcCstS)z%Returns the main instance of the hub.)r.)rrrrmainVszHubMeta.mainN)r r!r"propertyrr0rrrrr+Ks
r+c@s(eZdZddZddZdS)_HubManagercCstj|_tj|dS)N)rr_oldr,r/)rhubrrrr]sz_HubManager.__init__cCstj|jdS)N)r,r/r3)rrrrrrrrasz_HubManager.__exit__N)r r!r"rrrrrrr2\sr2c@s4eZdZddZddZddZdS)
_ScopeManagercCs/||_t|j|_|jd|_dS)N)_hublen_stack
_original_len_layer)rr4rrrrfs	z_ScopeManager.__init__cCs#|jd}|dk	st|S)Nr6)r<AssertionError)rscoperrrrks
z_ScopeManager.__enter__cCst|jj}||jkr<tjd|j|dS||jkrxtjd||j|jj|jd|jj|jd}|jj|jdd=|d|jdkrtjd|d|jdn*|d|jdkrd}tj|dS)Nz1Scope popped too soon. Popped %s scopes too many.zLeaked %s scopes: %sr6z2Wrong 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.)r9r8r:r;r
errorwarningr<)rrrrZcurrent_lenZlayerr@rrrrqs*
z_ScopeManager.__exit__N)r r!r"rrrrrrrr5esr5c@s]eZdZdZdZddddZddZddZd	d
ZddZ	e
d
dZddZddZ
dddZdddZdddZddZddddZeddZeddZdd dZeZd!d"Zed#d$Zed%d$Zdd&d$Zddd'd(ZdS))rzThe 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.
    NcCst|trF|}|jd\}}|dkrLtj|}n|}|dkrat}||fg|_d|_g|_dS)Nr6r7)
isinstancerr:copyr_last_event_id	_old_hubs)rZ
client_or_hubr>r4rZother_scoperrrrs		zHub.__init__cCs$|jjtjtj||S)N)rDappendrrr,r/)rrrrrs
z
Hub.__enter__cCs |jj}tj|dS)N)rDpopr,r/)rrrroldrrrrszHub.__exit__c	Cs||SWdQRXdS)z~Runs a callback in the context of the hub.  Alternatively the
        with statement can be used on the hub directly.
        Nr)rcallbackrrrrunszHub.runcCst|tr|}n'|jdk	r3|j}ntd|jdd}|dk	r~|jj|}|dk	r~|St}|dk	r|}|dk	r||k	r|jj|dk	rd|f}tt	|ddt
j|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 namer6rzIntegration %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.
stacklevelr7)rAstrZ
identifier
ValueErrorr:Zintegrationsr-r&rWarningr
r@)rZ
name_or_classZintegration_namerr)Zinitial_clientr@rrrget_integrations(			
zHub.get_integrationcCs|jddS)z&Returns the current client on the hub.r6rr7)r:)rrrrrsz
Hub.clientcCs|jS)zReturns the last event ID.)rC)rrrr
last_event_idszHub.last_event_idcCs(|jd}||df|jd<dS)zBinds a new client to the hub.r6Nr7r7)r:)rnewtoprrrr#s
zHub.bind_clientcCsQ|jd\}}|dk	rM|j|||}|dk	rI||_|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.
        r6Nr7)r:
capture_eventrC)reventhintrr>r)rrrrSs		zHub.capture_eventcCs>|jdkrdS|dkr%d}|jd|d|iS)zyCaptures a message.  The message is just a string.  If no level
        is provided the default level is `info`.
        Ninfomessagelevel)rrS)rrWrXrrrcapture_messages
zHub.capture_messagecCs|j}|dkrdS|dkr4tj}nt|}t|d|j\}}y|j|d|SWn%tk
r|jtjYnXdS)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.
        NZclient_optionsrU)	rsysexc_inforr	rrS	Exception_capture_internal_exception)rr?rr[rTrUrrrcapture_exceptions	
zHub.capture_exceptioncCstjdd|dS)zNCapture an exception that is likely caused by a bug in the SDK
        itself.zInternal error in sentry_sdkr[N)r
r?)rr[rrrr]1szHub._capture_internal_exceptioncKsG|jd
\}}|dkr0tjddSt|p<f}|j||sYdSt|pef}|jddkrtj|d<|jddkrd|d<|}|jddk	r|jd||}|dk	r|j	j
|ntjd||jd	}x&t|j	|krB|j	jqWdS)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.
        r6Nz*Dropped breadcrumb because no client boundZ	timestamptypedefaultZbefore_breadcrumbz)before breadcrumb dropped breadcrumb (%s)max_breadcrumbsr7)
r:r
rVdictupdater-rZutcnowrZ_breadcrumbsrEr9popleft)rZcrumbrUr(rr>Zoriginal_crumbrarrradd_breadcrumb6s,



zHub.add_breadcrumbcCsdS)Nr)rrrr
push_scope[szHub.push_scopecCsdS)Nr)rrHrrrrf`sc
Csr|dk	r0|j}||WdQRXdS|jd\}}|tj|f}|jj|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.
        Nr6r7)rfr:rBrEr5)rrHr>rZ	new_layerrrrrfescCs(|jj}|js$td|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:rFr=)rr)rrrpop_scope_unsafexszHub.pop_scope_unsafecCsdS)Nr)rrrrconfigure_scopeszHub.configure_scopecCsdS)Nr)rrHrrrrhscs[|jd\|dk	r9dk	r5|dStfdd}|S)zReconfigures the scope.r6Nc3s dk	rVntVdS)N)rr)rr>rrinnersz"Hub.configure_scope.<locals>.innerr7)r:r)rrHrir)rr>rrhs
cCs9|jd\}}|dk	r5|jd|d|SdS)zAlias for self.client.flushr6NtimeoutrHr7)r:flush)rrjrHrr>rrrrksz	Hub.flush)r r!r"__doc__r:rrrrIrOr1rrPr#rSrYr^r]rerrfr>rgrhrkrrrrrs0
)%r)!rZrBr$r
contextlibrwarningsrZsentry_sdk._compatrZsentry_sdk.scoperZsentry_sdk.clientrZsentry_sdk.utilsrr	r
rrr,r&robjectrr*r_r+r2r5rr.r/rrrr<module>s,"
	.	
Back to Directory File Manager