0i7lddlZddlZddlmZmZddlZddlmZddlm Z e rddlm Z dZ GddZ y) N)ThreadLock)logger) TYPE_CHECKING)Optional cPeZdZdZdZd dZdZdZdZdZ dZ e d 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) transportinterval_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# cjtjk(r jyj5jtjk(rj dddyfd}t j |}d|_ |j|_tj_dddy#t$rd_ YdddywxYw#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. NcjrItjjjrj jrHyyN)rtimesleepr runrsrrz(Monitor._ensure_running.._thread7s3mmJJt}}-}} mmr)nametargetTF) rosgetpidrrrrdaemonstart RuntimeErrorr)rrthreads` r_ensure_runningzMonitor._ensure_running's   299; .4<<3K   ##ryy{2t||7O  #7;F FM  "DL#%99;D -0  !& '  0s5/C/4#C/C( C/C,!C/+C,,C//C8cD|j|jyr) check_healthset_downsample_factorrs rrz Monitor.runMs  ""$rc|jr,|jdkDrtjdd|_y|jt kr|xjdz c_tjd|jy)Nrz=[Monitor] health check positive, reverting to normal samplingzA[Monitor] health check negative, downsampling with a factor of %d)rrrdebugdownsample_factorMAX_DOWNSAMPLE_FACTORrs rr*zMonitor.set_downsample_factorRsh ==&&* S'(D #%%(==''1,' LLS'' rcB|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_healthbs113 rc:|j|jSr)r'rrs rr1zMonitor.is_healthyks }}rc:|j|jSr)r'rrs rr.zMonitor.downsample_factorps &&&rcd|_y)NF)rrs rkillz Monitor.killvs  rN)r)__name__ __module__ __qualname____doc__rrr'rr*r)r1propertyr.r5rrr r sF D $L%  4 '' rr ) r!r threadingrr sentry_sdksentry_sdk.utilsrtypingrrr/r r;rrr@s1 "# ggr