OwlCyberSecurity - MANAGER
Edit File: asgi.cpython-312.pyc
� ����;0h�1�����������������������V����d�Z�ddlZddlZddlmZ�ddlmZ�ddlZddlm Z �ddl mZ�ddlm Z mZmZ�ddlmZmZ�dd lmZ�dd lmZmZ�ddlmZmZmZmZmZmZmZ�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,dZ-dd�Z.d��Z/�G�d��d�������Z0y)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�TransactionSource)� 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�Hint�sentry_asgi_middleware_appliedzgeneric ASGI request)�endpoint�urlc�����������������������t��������|�t��������j��������������������������j������������������|dd���������\��}}t��������j������������������||���������y�)NF)�type�handled)�client_options� mechanism)�hint)r���� sentry_sdk� get_client�options� capture_event)�exc�mechanism_type�eventr'���s��� �K/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/integrations/asgi.py�_capture_exceptionr0���<���sA�������'��!�,�,�.�6�6�)�e�<��K�E�4� ����U��.�����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_asgi3r>���G���s[����������s���s�K�(�(� � � �C� ��*�*�3�/�/��s�J��-���*�*�4�0�0r1���c��������������������@�����e�Zd�ZdZddddefd�Zd��Zd��Zd ��Zd ��Z d��Z y) �SentryAsgiMiddleware)r<���r4����transaction_styler-����span_origin�http_methods_to_captureFr ����asgi�manualc������������������j����|st���������st��������dt��������z�����������|t��������vrt ��������d|�dt���������d���������|dk(��xr�dt����������������v�}|rt ��������j������������������d��������||�_��������||�_ ��������||�_ ��������||�_��������||�_��������t��������|�������r|�j������������������|�_��������y|�j ������������������|�_��������y) 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.z%Invalid value for transaction_style: z (must be in �)rD���� 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����warningrA���r-���rB���r<���rC���r>���� _run_asgi3r4���� _run_asgi2)�selfr<����unsafe_context_datarA���r-���rB���rC����0asgi_middleware_while_using_starlette_or_fastapis��� r/����__init__zSentryAsgiMiddleware.__init__a���s�������"�#�+?���1�3L�M��� ���$<�<��$�&>�@��� �� �f�$�P��8N�8P�)P�� 9��<��N�N�a� ��"3���,���&������'>��$��S�!� �O�O�D�M� �O�O�D�Mr1���c�����������������������������fd�}|S�)Nc�������������������J����K�����j�������������������|�|d����������d�{������S�7���w)N������asgi_version��_run_app)�receive�send�scoperO���s��� ��r/����innerz.SentryAsgiMiddleware._run_asgi2.<locals>.inner����s$�������������u�g�t�!��L�L�L�L�s����#�!�#��)rO���r\���r]���s���`` r/���rN���zSentryAsgiMiddleware._run_asgi2����s������� M���r1���c�������������������H���K����|�j������������������|||d����������d�{������S�7���w)N����rV���rX���)rO���r\���rZ���r[���s��� r/���rM���zSentryAsgiMiddleware._run_asgi3����s#����������]�]�5�'�4�a�]�H�H�H�H�s����"� �"c����������� ��������Z����K����t���������j������������������d�������}|d���dk(��}|s|rA �|dk(��r �|�j������������������|�������|����������d�{������S�|�j������������������||����������d�{������S�t���������j ������������������d�������� �t��������j��������������������������5�}t��������|d��������5��|j���������������������������d |_��������t��������|�j������������������|� �������} |j������������������| ��������|d���} |�j������������������|�j ������������������|�������\��}}|j������������������dd�������j#��������������������������} d��| d v�r\| dk(��s| |�j$������������������v�r�t'��������t)��������|�������dj+������������������| �������|||�j,���������������������������t/��������j0������������������d���������n=t3��������t4��������j6������������������|||�j,���������������������������t/��������j0������������������d����������r=�j9������������������d| ��������t/��������j0������������������d�j:�������������������j<����������������������������t��������j>�������������������d|i��������n tA����������������5��t/��������j0������������������d��������� ���fd�}|dk(��rP�|�j������������������|�������||���������d�{������cd�d�d���������cd�d�d���������cd�d�d���������t���������j ������������������d��������S�|�j������������������|||���������d�{������cd�d�d���������cd�d�d���������cd�d�d���������t���������j ������������������d��������S�7����7����#�t��������$�r}t ��������||�j ���������������������������|d��d�}~ww�xY�w7���7��g#�t��������$�r}t ��������||�j ���������������������������|d��d�}~ww�xY�w#�1�sw�Y���nxY�w �d�d�d���������n#�1�sw�Y���nxY�wd�d�d���������n#�1�sw�Y���nxY�wt���������j ������������������d��������y�#�t���������j ������������������d��������w�xY�w�w)NFr#����lifespanrU���)r-���T�request)�session_moderD���)� asgi_scope�method��)�http� websocketri���z {}.server)�op�name�source�originz1[ASGI] Created transaction (continuing trace): %sz$[ASGI] Created transaction (new): %sz asgi.typezB[ASGI] Set transaction name and source on transaction: '%s' / '%s're���)�custom_sampling_contextz[ASGI] Started transaction: %sc�����������������������K������0|�j������������������d�������dk(��xr�d|�v�}|r�j������������������|�d�������������|����������d�{������S�7���w)Nr#���zhttp.response.start�status)�get�set_http_status)r.����is_http_responser[����transactions��� ��r/����_sentry_wrapped_sendz;SentryAsgiMiddleware._run_app.<locals>._sentry_wrapped_send����sX����������#.�#:�(-� � �&�(9�=R�(R��)>�,4��,=��%5��(8�(3�(C�(C�E�(�O�(T�-1�%�[�'8� 8�'8�s����>A�A�A)!�_asgi_middleware_appliedrq���r<���� Exceptionr0���r-����setr(����isolation_scoper����clear_breadcrumbs�_namer����event_processor�add_event_processor� _get_transaction_name_and_sourcerA����upperrC���r���r����formatrB���r����debugr���r����HTTP_SERVER�set_tagrk���rl����start_transactionr���)rO���r\���rZ���r[���rW����is_recursive_asgi_middleware�is_lifespanr,����sentry_scope� processor�ty�transaction_name�transaction_sourcerf���ru���rt���s��� ` @r/���rY���zSentryAsgiMiddleware._run_app����s���������'?�'C�'C�E�'J�$��F�m�z�1��'�;� $��1�$�!0����%���$�!?�?�?�!%���%��$�!?�?�?�� !�$�$�T�*�V 0��+�+�-��"�<�i�H� �2�2�4�)/�L�&� '��(<�(<�� O�I� �4�4�Y�?��v��B���=�=��.�.����(�*��#�Y�Y�x��4�:�:�<�F�"&�K��2�2���,��$�:V�:V�0V�*8� ,�U� 3�#.�#5�#5�b�#9�%5�'9�'+�'7�'7�+�K��#�L�L� S� +�� �'2�!�~�~�!1�#5�#'�#3�#3� '������B�K���#�#�+�+�K��<����`�'�,�,�'�.�.���'�2� �#�4�4�'�5A�5�4I�� �)�]�+�����%E�{�S�0� 9�� ,�q�0�-<�T�X�X�e�_�$+�-A�."��("�/+��+�e�I�H��.�-�j� %�(�(��/��.2�X�X�$)�7�4H�."��("�7+��+�e�I�H��.�-�j� %�(�(��/��@��?���� $�"�3�t�7J�7J�K��t�#�� $��`("��("��� )��0�.�s�4�CV�CV�W�"%�4�/��0��=+��+���+�e�I�H�H���.�-�-��j� %�(�(��/��$�(�(��/�s+���"N+� K*��K$�K*��N+�K*��"K'�#K*��&N+�=N��M/�FM�&M�>&L�$L �%L�( M�1 M/�: N��N+�L�/L �0L�3 M�< M/� N��N+�$K*��'K*��* L�3L � L�N+�L�L� M �"L< �<M �M�M � M� M/�M# �M/�& N��/M8�4N��;N+�N(�(N+c����������������������|j������������������di��������}|j������������������t��������|���������������t��������|�������|d<���|j������������������d�������}|j������������������d�������xs�i�j������������������d�������}|d�uxr<�|t��������k7��xr1�|t ��������j������������������t ��������j������������������t ��������j������������������fv�}|sK|�j������������������|�j������������������|�������\��}} ||d<���d| i|d<���t��������j������������������d|d���|d���d�����������|S�)Nrc���rt����transaction_inforl���zF[ASGI] Set transaction name and source in event_processor: '%s' / '%s') rq����updater���r����_DEFAULT_TRANSACTION_NAMEr���� COMPONENT�ROUTE�CUSTOMr~���rA���r���r����) rO���r.���r'���re����request_datart���r�����already_setrk���rl���s ��� r/���r|���z$SentryAsgiMiddleware.event_processor��s������y�y��B�/�����-�j�9�:�#�L�1��i����i�i� �.��#�i�i�(:�;�A�r�F�F�x�P���t�#�� ��8�8� �"�!�+�+�!�'�'�!�(�(���� ����@�@��&�&� ��L�D�&��$(�E�-� �)1�6�(:�E�$�%��L�L�X��m�$��(�)�(�3� ���r1���c����������������������d�}t���������|���}|j������������������d�������}|dk(��rI|j������������������d�������}|rt��������|�������xs�d}nut��������||dk(��rdndd���������}t��������j ������������������}nO|dk(��rJ|j������������������d�������}|rt ��������|d d��������}|�(|}n%t��������||dk(��rdndd���������}t��������j ������������������}|�t��������}t��������j������������������}||fS�||fS�) Nr#���r ���rg���rh����ws)�hostr!����route�path) r ���rq���r���r ���r����URLr;���r����r����) rO���rA���re���rk���rl���r����r ���r����r����s ��� r/���r~���z5SentryAsgiMiddleware._get_transaction_name_and_source0��s���������!�"3�4�� �^�^�F� #��� �*�!�~�~�j�1�H���0��:�@�b��� �b�F�l�F��SW�X��*�.�.�� �%� '���N�N�7�+�E���u�f�d�3���#��D�� �b�F�l�F��SW�X��*�.�.���<�,�D�&�,�,�F���<���V�|�r1���N)�__name__� __module__�__qualname__� __slots__r ���rR���rN���rM���rY���r|���r~���r^���r1���r/���r@���r@���W���s=�������I��"�$��� ?�1,�f�I�f0�P �P"r1���r@���)rD���)1�__doc__r9���r5����copyr���� functoolsr���r(����sentry_sdk.apir����sentry_sdk.constsr����$sentry_sdk.integrations._asgi_commonr���r���r ����$sentry_sdk.integrations._wsgi_commonr ���r����sentry_sdk.sessionsr����sentry_sdk.tracingr ���r����sentry_sdk.utilsr���r���r���r���r���r���r���r����typingr���r���r���r���r���r����sentry_sdk._typesr���r���rv���r����rJ���r0���r>���r@���r^���r1���r/����<module>r�������s������������������)�� ���� ��.��������+�� �������-��&�&F�G���2���.���/� 1� {��{r1���