o
    3i                     @   sF   d dl Z d dlZd dlZd dlmZ erd dlmZ G dd dZdS )    N)TYPE_CHECKING)Clientc                   @   sJ   e Zd ZedZdddZdd Zdd	 Zd
d Z	dd Z
dddZdS )ExceptionCaptureposthogclientr   c                 C   s"   || _ tj| _| jt_| jt_d S N)r   sys
excepthookoriginal_excepthookexception_handlerthread_exception_handler	threading)selfr    r   g/lsinfo/ai/hellotax_ai/llm_service/venv_embed/lib/python3.10/site-packages/posthog/exception_capture.py__init__   s   zExceptionCapture.__init__c                 C   s   | j t_d S r   )r
   r   r	   )r   r   r   r   close   s   zExceptionCapture.closec                 C   s"   |  |||f | ||| d S r   )capture_exceptionr
   )r   exc_type	exc_valueexc_tracebackr   r   r   r      s   z"ExceptionCapture.exception_handlerc                 C   s   |  |j|j|jf d S r   )r   r   r   r   )r   argsr   r   r   r   "   s   z)ExceptionCapture.thread_exception_handlerc                 C   s<   d|v rd|d i}nd }|  |d |d |d f| d S )Ndistinct_idr         )r   )r   exc_infoextra_propertiesmetadatar   r   r   exception_receiver%   s   "z#ExceptionCapture.exception_receiverNc              
   C   sb   z|r| dnd }| jj||d W d S  ty0 } z| jd|  W Y d }~d S d }~ww )Nr   )r   zFailed to capture exception: )getr   r   	Exceptionlog	exception)r   r"   r   r   er   r   r   r   ,   s    z"ExceptionCapture.capture_exception)r   r   r   )__name__
__module____qualname__logging	getLoggerr!   r   r   r   r   r   r   r   r   r   r   r      s    

r   )r'   r   r   typingr   posthog.clientr   r   r   r   r   r   <module>   s   