관리-도구
편집 파일: starlette.cpython-311.pyc
� �܋f�Z � �` � d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm Z d dl mZ d dlm Z mZ d dlmZmZ d d lmZmZ d d lmZ d dlmZmZ d dlmZmZmZmZmZ e rd d l m!Z!m"Z"m#Z#m$Z$m%Z% d dl&m'Z( d dl)Z)d dl)m*Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9m:Z:m'Z;m<Z< n# e=$ r ed� � �w xY w d dl>m?Z? n# e=$ r d dl@m?Z? Y nw xY w d dlAZAn # e=$ r dZAY nw xY wdZBdZC G d� de� � ZDd� ZEd+d�ZFd � ZGd!� ZHd"� ZId#� ZJd$� ZKd%� ZLd&� ZMd'� ZN G d(� d)� � ZOd*� ZPdS ),� )�absolute_importN)�deepcopy)� iteritems)� TYPE_CHECKING)�OP)�Hub�_should_send_default_pii)�DidNotEnable�Integration)�_is_json_content_type�request_body_within_bounds)�SentryAsgiMiddleware)�SOURCE_FOR_STYLE�TRANSACTION_SOURCE_ROUTE)�AnnotatedValue�capture_internal_exceptions�event_from_exception� parse_version�transaction_from_function)�Any� Awaitable�Callable�Dict�Optional)�Scope)�__version__)� Starlette)� UploadFile)� Middleware)�AuthenticationMiddleware)�Request)�Match)�ASGIApp�Receiver �SendzStarlette is not installed)�ExceptionMiddlewarezgeneric Starlette request)�endpoint�urlc �4 � e Zd ZdZdZdd�Zed� � � ZdS )�StarletteIntegration� starlette� r( c �\ � |t vrt d|�dt �d�� � �|| _ d S )Nz%Invalid value for transaction_style: z (must be in �))�TRANSACTION_STYLE_VALUES� ValueError�transaction_style)�selfr1 s �X/opt/cloudlinux/venv/lib64/python3.11/site-packages/sentry_sdk/integrations/starlette.py�__init__zStarletteIntegration.__init__F sJ � ��$<�<�<��*�$�$�$�&>�&>�&>�@�� � � "3����� c � � t t � � } | �'t d� t � � � � �t � � t � � t � � | dk rt � � d S d S )Nz Unparsable Starlette version: {})r � )r �STARLETTE_VERSIONr �format�patch_middlewares�patch_asgi_app�patch_request_response�patch_templates)�versions r3 � setup_oncezStarletteIntegration.setup_onceO s� � � � 1�2�2���?��2�9�9�:K�L�L�� � � ��������� � � ��g��������� �r5 N)r( )�__name__� __module__�__qualname__� identifierr1 r4 �staticmethodr? � r5 r3 r* r* A sN � � � � � ��J���3� 3� 3� 3� �� � �\�� � r5 r* c �D �� | j ��fd�}�j dv}|r|| _ | S )Nc � � ����K � t j }|� t � � }|��| j j �|� t j ��� � 5 }|� d�� � ��fd�}t �dt �� � � � } | dk } | s|n�}��fd�}t �dt �� � � � } | dk }|s|n�} �| |||fi |��� d {V ��cd d d � � S # 1 swxY w Y d S �| |��fi |��� d {V ��S )N��op�description�starlette.middleware_namec � � �K � t j }|� t j t �dt �� � � � �� � 5 }|� d�� � �| i |��� d {V ��cd d d � � S # 1 swxY w Y d S �NrB rH rK )r �current� start_spanr �MIDDLEWARE_STARLETTE_RECEIVE�getattr�str�set_tag)�args�kwargs�hub�span�middleware_name�receives ��r3 �_sentry_receivezO_enable_span_for_middleware.<locals>._create_span_call.<locals>._sentry_receiver s� �� � � ��+�C�����:�$+�G�^�S��\�\�$R�$R� (� � � >� ����%@�/�R�R�R�%,�W�d�%=�f�%=�%=�=�=�=�=�=�=�>� >� >� >� >� >� >� >� >� >� >� >���� >� >� >� >� >� >� � $A>�>B�Br@ rZ c � � �K � t j }|� t j t �dt �� � � � �� � 5 }|� d�� � �| i |��� d {V ��cd d d � � S # 1 swxY w Y d S rM )r rN rO r �MIDDLEWARE_STARLETTE_SENDrQ rR rS )rT rU rV rW rX �sends ��r3 �_sentry_sendzL_enable_span_for_middleware.<locals>._create_span_call.<locals>._sentry_send� s� �� � � ��+�C�����7�$+�D�.�#�d�)�)�$L�$L� (� � � ;� ����%@�/�R�R�R�%)�T�4�%:�6�%:�%:�:�:�:�:�:�:�;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;� ;���� ;� ;� ;� ;� ;� ;r[ r_ )r rN �get_integrationr* � __class__r@ rO r �MIDDLEWARE_STARLETTErS rQ rR )�app�scoperY r^ rU rV �integration�middleware_spanrZ �receive_name�receive_patched�new_receiver_ � send_name�send_patched�new_sendrX �old_calls `` @�r3 �_create_span_callz6_enable_span_for_middleware.<locals>._create_span_calle s� ����� � � ��k���)�)�*>�?�?���"�!�m�4�O�����*�� � � � # S� ��'�'�(C�_�U�U�U�>� >� >� >� >� >� '�w� �C��L�L�I�I��".�2C�"C��5D�Q�o�o�'��;� ;� ;� ;� ;� ;� $�D�*�c�$�i�i�@�@� �(�N�:��/;�E�<�<���%�X�c�5�+�x�R�R�6�R�R�R�R�R�R�R�R�G# S� # S� # S� # S� # S� # S� # S� # S� # S� # S� # S� # S���� # S� # S� # S� # S� # S� # S�L "��#�u�g�t�F�F�v�F�F�F�F�F�F�F�F�Fs �BC1�1C5�8C5)rn �%_sentry_authenticationmiddleware_call� _sentry_exceptionmiddleware_call)�__call__r@ )�middleware_classrn �not_yet_patchedrm s @r3 �_enable_span_for_middlewarert a sW �� ��(�H�-G� -G� -G� -G� -G�^ �'� 0� �O� � 6�$5��!��r5 Fc �� � t j }|� t � � �d S t | |j r|j j nd t j |d��� � \ }}|� ||�� � d S )N)�type�handled)�client_options� mechanism)�hint) r rN r` r* r �client�optionsrC � capture_event)� exceptionrw rV �eventrz s r3 �_capture_exceptionr� � s� � � �+�C� ���/�0�0�8���&��-0�Z�A�s�z�)�)�T�/�:�w�O�O�� � �K�E�4� ���e�$��'�'�'�'�'r5 c � ��� | j �dt �� � v}|r!�fd�}|| _ | j ��fd�}|| _ dS dS )zX Capture all exceptions in Starlette app and also extract user information. �_sentry_middleware_initc � ��� �| g|�R i |�� | j � � � ��fd�}| j � � � D ]}|| j |<