관리-도구
편집 파일: asgi.cpython-311.pyc
� R�Dg� � � � 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 <https://github.com/encode/sentry-asgi>`_. � N)�partial)�MYPY)�Hub�_should_send_default_pii)�_filter_headers)� ContextVar�event_from_exception�transaction_from_function�HAS_REAL_CONTEXTVARS�CONTEXTVARS_ERROR_MESSAGE)�Transaction)�Dict)�Any)�Optional)�Callable)�Literal)�Event�Hint�sentry_asgi_middleware_appliedzgeneric ASGI requestc � � | j �;t || j j ddd��� � \ }}| � ||�� � d S d S )N�asgiF)�type�handled)�client_options� mechanism)�hint)�clientr �options� capture_event)�hub�exc�eventr s �|/builddir/build/BUILD/imunify360-venv-2.4.0/opt/imunify360/venv/lib/python3.11/site-packages/sentry_sdk/integrations/asgi.py�_capture_exceptionr$ ( sc � � �z��*���:�-�%�%�8�8� � � ���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)�inspect�isclass�hasattr� isfunction�asyncio�iscoroutinefunction�getattr)�app�calls r# �_looks_like_asgi3r2 5 sl � � ��s��� 1��s�K�(�(�(� � �C� � � 1��*�3�/�/�/��s�J��-�-���*�4�0�0�0r% c �D � e Zd ZdZdd�Zd� 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 � � #� �+?� � �1�3L�M�� � � ����S�!�!� ,� �O�D�M�M�M� �O�D�M�M�Mr% c � � �� �� fd�}|S )Nc � �P �� �K � �� �� ���fd�� � � d {V ��S )Nc �B �� �� �� � � �� � S �N�r0 ��receive�scoper9 �sends ����r# �<lambda>z@SentryAsgiMiddleware._run_asgi2.<locals>.inner.<locals>.<lambda>d s �� �o�d�h�h�u�o�o�g�t�6T�6T� r% ��_run_app)rB rD rC r9 s ``��r# �innerz.SentryAsgiMiddleware._run_asgi2.<locals>.innerb sB ���� � � ����u�.T�.T�.T�.T�.T�.T�.T�U�U�U�U�U�U�U�U�Ur% � )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.<locals>.<lambda>j s �� �$�(�(�5�'�4�2P�2P� r% rF )r9 rC rB rD s ````r# r7 zSentryAsgiMiddleware._run_asgi3h sC ����� � � ��]�]�5�*P�*P�*P�*P�*P�*P�*P�Q�Q�Q�Q�Q�Q�Q�Q�Qr% 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"