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

�

h0i7��l�ddlZddlZddlmZmZddlZddlmZddlm	Z	e	rddlm
Z
dZGd�d�Zy)	�N)�Thread�Lock)�logger)�
TYPE_CHECKING)�Optional�
c�P�eZdZdZdZdd�Zd�Zd�Zd�Zd�Z	d�Z
ed	��Zd
�Z
y)
�Monitorz�
    Performs health checks in a separate thread once every interval seconds
    and updates the internal state. Other parts of the SDK only read this state
    and act accordingly.
    zsentry.monitorc��||_||_d|_d|_d|_t�|_d|_d|_y)NTr)	�	transport�interval�_healthy�_downsample_factor�_threadr�_thread_lock�_thread_for_pid�_running)�selfrr
s   �A/opt/hc_python/lib/python3.12/site-packages/sentry_sdk/monitor.py�__init__zMonitor.__init__s?��"��� ��
���
�"#������ �F���#�����
�c����jtj�k(r
�j�y�j5�jtj�k(r�j�
	ddd�y�fd�}t�j|��}d|_	|j�|�_tj��_ddd�y#t$rd�_
Yddd�ywxYw#1swYyxYw)a-
        Check that the monitor has an active thread to run in, or create one if not.

        Note that this might fail (e.g. in Python 3.12 it's not possible to
        spawn new threads at interpreter shutdown). In that case self._running
        will be False after running this function.
        Nc����jrItj�j��jr�j	��jr�Hyy�N)r�time�sleepr
�run�rs�rrz(Monitor._ensure_running.<locals>._thread7s3����m�m��J�J�t�}�}�-��}�}����
��m�mr)�name�targetTF)r�os�getpidrrrr�daemon�start�RuntimeErrorr)rr�threads`  r�_ensure_runningzMonitor._ensure_running's�������2�9�9�;�.�4�<�<�3K��
�
�
��#�#�r�y�y�{�2�t�|�|�7O���
�
#�����7�;�F� �F�M�
�����"�D�L�#%�9�9�;�D� �-�0�� �
�!&��
��'�
�
���0�s5�/C/�4#C/�C�( C/�C,�!C/�+C,�,C/�/C8c�D�|j�|j�yr)�check_health�set_downsample_factorrs rrzMonitor.runMs�������"�"�$rc��|jr,|jdkDrtjd�d|_y|jt
kr|xjdz
c_tjd|j�y)Nrz=[Monitor] health check positive, reverting to normal sampling�zA[Monitor] health check negative, downsampling with a factor of %d)rrr�debug�downsample_factor�MAX_DOWNSAMPLE_FACTORrs rr*zMonitor.set_downsample_factorRsh���=�=��&�&��*����S��'(�D�#��%�%�(=�=��'�'�1�,�'��L�L�S��'�'�
rc�B�|jj�|_y)z�
        Perform the actual health checks,
        currently only checks if the transport is rate-limited.
        TODO: augment in the future with more checks.
        N)r�
is_healthyrrs rr)zMonitor.check_healthbs�����1�1�3��
rc�:�|j�|jSr)r'rrs rr1zMonitor.is_healthyks�������}�}�rc�:�|j�|jSr)r'rrs rr.zMonitor.downsample_factorps��	
�����&�&�&rc��d|_y)NF)rrs r�killzMonitor.killvs	����
rN)r)�__name__�
__module__�__qualname__�__doc__rrr'rr*r)r1�propertyr.r5�rrr
r
sF����D��$�L%�
� 4��
�'��'�
rr
)
r!r�	threadingrr�
sentry_sdk�sentry_sdk.utilsr�typingrrr/r
r;rr�<module>r@s1��	��"��#� �����g�gr
Back to Directory File Manager