Viewing File: /opt/hc_python/lib/python3.12/site-packages/sentry_sdk/__pycache__/_batcher.cpython-312.pyc

�

_�*j����ddlZddlZddlZddlZddlmZmZddlmZmZm	Z	ddl
mZmZm
Z
ddlmZer
ddlmZmZmZe	d�ZGd�d	ee�Zy)
�N)�datetime�timezone)�
TYPE_CHECKING�Generic�TypeVar)�Envelope�Item�
PayloadRef)�format_timestamp)�Any�Callable�Optional�Tc��eZdZdZdZdZdZdZ						dd�Zdd�Z	de
fd	�Zdd
�Zdd�Z
dd�Zdd
�Zdd�Zdd�Zdd�Zedd��Zy)�Batcher�di�g@��returnNc���g|_||_||_d|_t	j
�|_t	j�|_t	j�|_
d|_d|_ttd�r<tj |j"��d�fd�}tj$|��yy)NT�register_at_forkc�(����}|�|�yy�N�)�method�
weak_resets ��B/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/_batcher.py�_reset_in_childz)Batcher.__init__.<locals>._reset_in_child.s���#����%��H�&�)�after_in_child�rN)�_buffer�
_capture_func�_record_lost_func�_running�	threading�Lock�_lock�local�_active�Event�_flush_event�_flusher�_flusher_pid�hasattr�os�weakref�
WeakMethod�_reset_thread_stater)�self�capture_func�record_lost_funcrrs    @r�__init__zBatcher.__init__s����
#%���)���!1�����
��^�^�%��
�*3�/�/�*;���/8���/@���6:��
�-1����2�)�*� �+�+�D�,D�,D�E�J�
�

����?�+rc���g|_d|_tj�|_tj
�|_tj�|_d|_	d|_
y�NT)r!r$r%r&r'r(r)r*r+r,r-�r3s rr2zBatcher._reset_thread_state5sJ�������
��^�^�%��
� ���(���%�O�O�-�����
� ��rc���|jsytj�}|j|k(ry|j5|j|k(r
	ddd�y||_tj|j��|_d|j_		|jj�	ddd�y#t$rd|_Yddd�ywxYw#1swYyxYw)z�For forking processes we might need to restart this thread.
        This ensures that our process actually has that thread running.
        FTN)�target)r$r/�getpidr-r'r%�Thread�_flush_loopr,�daemon�start�RuntimeError)r3�pids  r�_ensure_threadzBatcher._ensure_thread>s����}�}���i�i�k������#��
�Z�Z�� � �C�'��	�Z�!$�D��%�,�,�D�4D�4D�E�D�M�#'�D�M�M� �
��
�
�#�#�%��&��
 �
�!&��
��#�Z�
���&�s/�C�=C�B:�:C�
C�C�C�C!c�"�d|j_|jrr|jj	|j
t
j�z�|jj�|j�|jr�qyyr8)	r)�flagr$r+�wait�FLUSH_WAIT_TIME�random�clear�_flushr9s rr>zBatcher._flush_loop^s`��
!������m�m����"�"�4�#7�#7�&�-�-�/�#I�J����#�#�%��K�K�M��m�mrc��t|jdd�ryd|j_	|j�r|j�	d|j_y|j
5t
|j�|jk\r,|j|�	ddd�d|j_y|jj|�t
|j�|jk\r|jj�ddd�d|j_y#1swY�xYw#d|j_wxYw�NrEFT)�getattrr)rErCr,r'�lenr!�MAX_BEFORE_DROP�_record_lost�append�MAX_BEFORE_FLUSHr+�set�r3�items  r�addzBatcher.addis����4�<�<���/�� �����
	&��&�&�(�D�M�M�,A��!&�D�L�L������t�|�|�$��(<�(<�<��%�%�d�+���!&�D�L�L��	���#�#�D�)��t�|�|�$��(=�(=�=��%�%�)�)�+��!&�D�L�L�����!&�D�L�L��s6�D2�D2�&5D&�D2�5AD&�D2�&D/�+D2�2Ec�n�|j�yd|_|jj�d|_y)NF)r,r$r+rSr9s r�killzBatcher.kill�s/���=�=� ����
���������
rc���t|jdd�}d|j_	|j�||j_y#||j_wxYwrL)rMr)rErJ)r3�
was_actives  r�flushz
Batcher.flush�sG���T�\�\�6�5�9�
� �����	+��K�K�M� *�D�L�L���
�D�L�L��s�A�Ac��|jt|j|jdt	|j
�it
d|j
D�cgc]}|j|���c}d������ycc}w)N�
item_count�)�version�items)�json)�type�content_type�headers�payload)�add_itemr	�TYPE�CONTENT_TYPErNr!r
�_to_transport_format)r3�enveloperUs   r�_add_to_envelopezBatcher._add_to_envelope�sx�������Y�Y�!�.�.� �#�d�l�l�"3��#�#$�HL���"�HT��D�5�5�d�;��"���

�	
��"s�A=c�t�tdttjtj
��i��}|j5t|j�dk(r
	ddd�y|j|�|jj�ddd�|j|�|S#1swY�xYw)N�sent_at)rdr)rrr�nowr�utcr'rNr!rkrIr")r3rjs  rrJzBatcher._flush�s����� 0����h�l�l�1K� L�M�
���Z�Z��4�<�<� �A�%���Z�
�!�!�(�+��L�L��� ��	
���8�$����Z�s�B.�(+B.�.B7c��yrrrTs  rrPzBatcher._record_lost�s��rc��yrr)rUs rrizBatcher._to_transport_format�s��r)r4zCallable[[Envelope], None]r5zCallable[..., None]rNr )rUrrN)rjrrN)rzOptional[Envelope])rUrrr)�__name__�
__module__�__qualname__rRrOrGrgrhr6r2�boolrCr>rVrXr[rkrJrP�staticmethodrirrrrrs������O��O�
�D��L�@�2�@�0�@�
�	@�8!����@	�&�2�+�
�&�
��
��
rr)r/rHr%r0rr�typingrrr�sentry_sdk.enveloperr	r
�sentry_sdk.utilsrrr
rrrrrr�<module>rzsG��	�
���'�2�2�:�:�-��.�.��C�L��g
�g�a�j�g
r
Back to Directory File Manager