U 췀g~@sfddlZddlZddlmZmZddlZddlmZddlm Z e rPddlm Z dZ GdddZ dS) N)ThreadLock)logger) TYPE_CHECKING)Optional c@sbeZdZdZdZdddZddZdd Zd d Zd d Z ddZ e ddZ ddZ ddZdS)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.monitorrcCs6||_||_d|_d|_d|_t|_d|_d|_dS)NTr) transportinterval_healthy_downsample_factor_threadr _thread_lock_thread_for_pid_running)selfr r r@/opt/hc_python/lib/python3.8/site-packages/sentry_sdk/monitor.py__init__szMonitor.__init__c sjtkrjdk rdSjjtkrJjdk rJW5QRdSfdd}tj|d}d|_z |Wn&t k rd_ YW5QRdSX|_t_W5QRXdS)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. Ncs&jr"tjjrqdSN)rtimesleepr runrrrrr 7s z(Monitor._ensure_running.._thread)nametargetTF) rosgetpidr rrrdaemonstart RuntimeErrorr)rr threadrrr_ensure_running's   zMonitor._ensure_runningcCs||dSr) check_healthset_downsample_factorrrrrrMsz Monitor.runcCsL|jr"|jdkrtdd|_n&|jtkr:|jd7_td|jdS)Nrz=[Monitor] health check positive, reverting to normal samplingzA[Monitor] health check negative, downsampling with a factor of %d)r r rdebugdownsample_factorMAX_DOWNSAMPLE_FACTORrrrrr$Rs  zMonitor.set_downsample_factorcCs|j|_dS)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_healthyr rrrrr#bszMonitor.check_healthcCs||jSr)r"r rrrrr)kszMonitor.is_healthycCs||jSr)r"r rrrrr'pszMonitor.downsample_factorcCs d|_dS)NF)rrrrrkillvsz Monitor.killcCs |dSr)r*rrrr__del__zszMonitor.__del__N)r)__name__ __module__ __qualname____doc__rrr"rr$r#r)propertyr'r*r+rrrrrs &  r) rr threadingrrZ sentry_sdkZsentry_sdk.utilsrtypingrrr(rrrrrs