
    gh7                     v    S SK r S SKrS SKJrJr  S SKrS SKJr  S SKJ	r	  \	(       a  S SKJ
r
  Sr " S S5      rg)	    N)ThreadLock)logger)TYPE_CHECKING)Optional
   c                   Z    \ rS rSrSrSrSS jrS rS rS r	S r
S	 r\S
 5       rS rSrg)Monitor   z
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.
zsentry.monitorc                     Xl         X l        SU l        SU l        S U l        [        5       U l        S U l        SU l        g )NTr   )		transportinterval_healthy_downsample_factor_threadr   _thread_lock_thread_for_pid_running)selfr   r   s      U/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sentry_sdk/monitor.py__init__Monitor.__init__   s;    " "# F#    c                   ^  T R                   [        R                  " 5       :X  a  T R                  b  gT R                     T R                   [        R                  " 5       :X  a  T R                  b
   SSS5        gU 4S jn[        T R                  US9nSUl         UR                  5         UT l        [        R                  " 5       T l         SSS5        g! [         a    ST l
         SSS5        gf = f! , (       d  f       g= f)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                     > T R                   (       aU  [        R                  " T R                  5        T R                   (       a  T R	                  5         T R                   (       a  MT  g g N)r   timesleepr   runr   s   r   r   (Monitor._ensure_running.<locals>._thread7   s5    mmJJt}}-}}
 mmmr   )nametargetTF)r   osgetpidr   r   r   r"   daemonstartRuntimeErrorr   )r   r   threads   `  r   _ensure_runningMonitor._ensure_running'   s     299;.4<<3K##ryy{2t||7O # 7;F FM "DL#%99;D - 0     !&'  0 s5   2C5:!C5C,!C5C2'C51C22C55
Dc                 D    U R                  5         U R                  5         g r   )check_healthset_downsample_factorr    s    r   r   Monitor.runM   s    ""$r   c                    U R                   (       a.  U R                  S:  a  [        R                  " S5        SU l        g U R                  [
        :  a  U =R                  S-  sl        [        R                  " SU R                  5        g )Nr   z=[Monitor] health check positive, reverting to normal sampling   zA[Monitor] health check negative, downsampling with a factor of %d)r   r   r   debugdownsample_factorMAX_DOWNSAMPLE_FACTORr    s    r   r.   Monitor.set_downsample_factorR   sh    ==&&*S '(D#%%(==''1,'LLS''r   c                 B    U R                   R                  5       U l        g)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   r    s    r   r-   Monitor.check_healthb   s     113r   c                 :    U R                  5         U R                  $ r   )r*   r   r    s    r   r7   Monitor.is_healthyk   s    }}r   c                 :    U R                  5         U R                  $ r   )r*   r   r    s    r   r3   Monitor.downsample_factorp   s     	&&&r   c                     SU l         g )NF)r   r    s    r   killMonitor.killv   s	    r   )r   r   r   r   r   r   r   r   N)r   )__name__
__module____qualname____firstlineno____doc__r"   r   r*   r   r.   r-   r7   propertyr3   r>   __static_attributes__ r   r   r
   r
      sF     D$L%
 4
 ' '
r   r
   )r$   r   	threadingr   r   
sentry_sdksentry_sdk.utilsr   typingr   r   r4   r
   rG   r   r   <module>rL      s1    	  "  #    g gr   