+]Z d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z m
Z
ddlmZ ddl
mZmZmZmZmZ ddlmZ er&dd lmZ dd
lmZ ddlmZ ddlmZ dd
lmZ ddlmZmZ ed ZdZd Z d Z! G d d Z"dS )zf
An ASGI middleware.
Based on Tom Christie's `sentry-asgi `_.
N)partial)MYPY)Hub_should_send_default_pii)_filter_headers)
ContextVarevent_from_exceptiontransaction_from_functionHAS_REAL_CONTEXTVARSCONTEXTVARS_ERROR_MESSAGE)Transaction)Dict)Any)Optional)Callable)Literal)EventHintsentry_asgi_middleware_appliedzgeneric ASGI requestc | j ;t || j j ddd \ }}| || d S d S )NasgiF)typehandled)client_options mechanism)hint)clientr options
capture_event)hubexceventr s |/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py_capture_exceptionr$ ( sc z*:-%%88
t
%d+++++
c t j | rt | d S t j | rt j | S t
| dd }t j | S )z
Try to figure out if an application object supports ASGI3.
This is how uvicorn figures out the application version as well.
__await____call__N)inspectisclasshasattr
isfunctionasyncioiscoroutinefunctiongetattr)appcalls r# _looks_like_asgi3r2 5 sl s 1sK((( C 1*3///sJ--*4000r% c D e Zd ZdZddZd Zd Zd Zd Zd Z d Z
d
ZdS )
SentryAsgiMiddleware)r0 r( Fc |st st dt z || _ t | r| j | _ dS | j | _ dS )ab
Instrument an ASGI application with Sentry. Provides HTTP/websocket
data to sent events and basic handling for exceptions bubbling up
through the middleware.
:param unsafe_context_data: Disable errors when a proper contextvars installation could not be found. We do not recommend changing this from the default.
zRThe ASGI middleware for Sentry requires Python 3.7+ or the aiocontextvars package.N)r RuntimeErrorr r0 r2
_run_asgi3r(
_run_asgi2)selfr0 unsafe_context_datas r# __init__zSentryAsgiMiddleware.__init__H si # +? 13LM
S!! , ODMMM ODMMMr% c fd}|S )Nc P K fd d {V S )Nc B S Nr0 receivescoper9 sends r# z@SentryAsgiMiddleware._run_asgi2..inner..d s odhhuoogt6T6T r% _run_app)rB rD rC r9 s ``r# innerz.SentryAsgiMiddleware._run_asgi2..innerb sB u.T.T.T.T.T.T.TUUUUUUUUUr% )r9 rC rH s `` r# r8 zSentryAsgiMiddleware._run_asgi2` s/ V V V V V V r% c R K fd d {V S )Nc 2 S r? r@ rA s r# rE z1SentryAsgiMiddleware._run_asgi3..j s $((5'42P2P r% rF )r9 rC rB rD s ````r# r7 zSentryAsgiMiddleware._run_asgi3h sC ]]5*P*P*P*P*P*P*PQQQQQQQQQr% c K t d }|r@ | d {V S # t $ r"}t t j | |d d }~ww xY wt d t t j }|5 | 5 }| d|_ t | j | }| | d d d n# 1 swxY w Y |d }|dv r=t j t |d d | } nt d
} t" | _ | d| | | 5 | d {V cd d d cd d d t d S # t $ r}t || |d d }~ww xY w# 1 swxY w Y d d d n# 1 swxY w Y t d d S # t d w xY w)NFTr )
asgi_scoper http websocketheadersz {}.server)opzasgi.serverz asgi.type)_asgi_middleware_appliedget Exceptionr$ r currentsetconfigure_scopeclear_breadcrumbs_namer event_processoradd_event_processorr
continue_from_headersdictformat_DEFAULT_TRANSACTION_NAMEnameset_tagstart_transaction)
r9 rC callbackis_recursive_asgi_middlewarer! r sentry_scope processortytransactions
r# rG zSentryAsgiMiddleware._run_appl sx '?'C'CE'J'J$' $
$%XZZ'''''''
$
$
$"3;444t#
$ !$$T*** 0ck""C
,
,((** @l 22444)/L& '(< O O OI 44Y??? @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 6]..."-"CU9-..&--b11# # #KK
#."?"?"?K#< ##K444**;77 , ,,%-XZZ///////, , , , , , ,)
,
,
,
,
,
,
,<