
    jKj3                     d    d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ erd dl	m
Z
  G d d      Zy)    N)TYPE_CHECKING)BucketedRateLimiter)walk_exception_chain)Clientc                       e Zd Z ej                  d      ZdZdZdZdeeef	 ddZ	d Z
d Zd Zd	 ZddZed        Zy
)ExceptionCaptureposthog2   
   Fc                     || _         t        j                  | _        | j                  t        _        | j
                  t        _        d | _        |rt        |||      | _        y y )N)bucket_sizerefill_raterefill_interval_seconds)	clientsys
excepthookoriginal_excepthookexception_handlerthread_exception_handler	threading_rate_limiterr   )selfr   rate_limiting_enabledr   r   r   s         j/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/posthog/exception_capture.py__init__zExceptionCapture.__init__   sZ     #&>> //#<<	 " !4''(?"D !    c                 |    | j                   t        _        | j                  | j                  j	                          y y N)r   r   r   r   stop)r   s    r   closezExceptionCapture.close2   s2    11)##% *r   c                 R    | j                  |||f       | j                  |||       y r   )capture_exceptionr   )r   exc_type	exc_valueexc_tracebacks       r   r   z"ExceptionCapture.exception_handler7   s)    )]CD  9mDr   c                 h    | j                  |j                  |j                  |j                  f       y r   )r"   r#   r$   r%   )r   argss     r   r   z)ExceptionCapture.thread_exception_handler<   s%    t~~t?Q?QRSr   c                 \    d|v rd|d   i}nd }| j                  |d   |d   |d   f|       y )Ndistinct_idr         )r"   )r   exc_infoextra_propertiesmetadatas       r   exception_receiverz#ExceptionCapture.exception_receiver?   sC    ,,%'7'FGHHXa[(1+FQr   Nc                    	 | j                   K| j                  |      }| j                   j                  |      r| j                  j	                  d|        y |r|j                  d      nd }| j                  j                  ||       y # t        $ r(}| j                  j                  d|        Y d }~y d }~ww xY w)NzFSkipping exception capture because of client rate limiting. exception=r)   )r)   zFailed to capture exception: )
r   _exception_typeconsume_rate_limitloginfogetr   r"   	Exception	exception)r   r7   r.   exception_typer)   es         r   r"   z"ExceptionCapture.capture_exceptionF   s    	D!!-!%!5!5i!@%%88HHHMM`ao`pq 9A(,,}5tKKK))))M 	DHH!>qcBCC	Ds   AB 2B 	B=B88B=c                     t        | t              r| }nt        |       | t        | dd       f}|d   }t	        |      D ]  \  }}}|}
 t        |dd       xs dS )N__traceback__r   __name__r6   )
isinstancetupletypegetattrr   )r7   r,   r#   chained_type_s        r   r1   z ExceptionCapture._exception_typeU   sm    i' H Y	?D9H A;"6x"@L!Q#H #A xT2AkAr   )r   r   r   )r<   
__module____qualname__logging	getLoggerr3   DEFAULT_BUCKET_SIZEDEFAULT_REFILL_RATEDEFAULT_REFILL_INTERVAL_SECONDSr   r    r   r   r/   r"   staticmethodr1    r   r   r   r      sv    
'

I
&C &(#
 $'' ?,&
E
TRD B Br   r   )rE   r   r   typingr   posthog.bucketed_rate_limiterr   posthog.exception_utilsr   posthog.clientr   r   rK   r   r   <module>rP      s-     
    = 8%WB WBr   