관리-도구
편집 파일: asgi.cpython-38.pyc
U �Mg�1 � @ sZ d Z ddlZddlZddlmZ ddlmZ ddlZddlm Z ddl mZ ddlm Z mZmZ ddlmZmZ dd lmZ dd lmZmZmZmZmZ ddlmZmZmZmZm Z m!Z!m"Z" ddlm#Z# dd l$m%Z% e%�r&ddl$m&Z& ddl$m'Z' ddl$m(Z( ddl$m)Z) ddl$m*Z* ddl+m,Z,m-Z- ed�Z.dZ/dZ0ddd�Z1dd� Z2G dd� d�Z3dS )ze An ASGI middleware. Based on Tom Christie's `sentry-asgi <https://github.com/encode/sentry-asgi>`. � N)�deepcopy)�partial)�continue_trace)�OP)�_get_headers�_get_request_data�_get_url)�DEFAULT_HTTP_METHODS_TO_CAPTURE�nullcontext)� track_session)�SOURCE_FOR_STYLE�TRANSACTION_SOURCE_ROUTE�TRANSACTION_SOURCE_URL�TRANSACTION_SOURCE_COMPONENT�TRANSACTION_SOURCE_CUSTOM)� ContextVar�event_from_exception�HAS_REAL_CONTEXTVARS�CONTEXTVARS_ERROR_MESSAGE�logger�transaction_from_function�_get_installed_modules)�Transaction)� TYPE_CHECKING)�Any)�Callable)�Dict)�Optional)�Tuple)�Event�HintZsentry_asgi_middleware_appliedzgeneric ASGI request)�endpoint�url�asgic C s0 t | t�� j|dd�d�\}}tj||d� d S )NF)�typeZhandled)Zclient_optionsZ mechanism)�hint)r � sentry_sdkZ get_client�optionsZ capture_event)�exc�mechanism_type�eventr% � r+ �J/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/integrations/asgi.py�_capture_exception? s � r- c C sB t �| �rt| d�S t �| �r(t�| �S t| dd�}t�|�S dS )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)�inspect�isclass�hasattr� isfunction�asyncio�iscoroutinefunction�getattr)�app�callr+ r+ r, �_looks_like_asgi3J s r9 c @ sL e Zd ZdZddddefdd�Zdd � Zd d� Zdd � Zdd� Z dd� Z dS )�SentryAsgiMiddleware)r7 r/ �transaction_styler) �span_origin�http_methods_to_captureFr! r# Zmanualc C s� |st stdt ��|tkr,td|tf ��|dko<dt� k}|rLt�d� || _|| _ || _ || _|| _t |�r|| j| _n| 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.z7Invalid value for transaction_style: %s (must be in %s)r# Z starlettez�The Sentry Python SDK can now automatically support ASGI frameworks like Starlette and FastAPI. Please remove 'SentryAsgiMiddleware' from your project. See https://docs.sentry.io/platforms/python/guides/asgi/ for more information.N)r �RuntimeErrorr �TRANSACTION_STYLE_VALUES� ValueErrorr r �warningr; r) r<