
    g	                     x    d dl Z d dlZd dlZd dlmZ d dlmZmZmZ erd dl	m
Z
  G d dee      Z G d d      Zy)	    N)Enum)TYPE_CHECKINGListOptional)Clientc                       e Zd ZdZy)IntegrationsdjangoN)__name__
__module____qualname__Django     N/var/www/openai/venv/lib/python3.12/site-packages/posthog/exception_capture.pyr	   r	      s    Fr   r	   c                   n    e Zd Z ej                  d      Zddddeee      fdZ	d Z
d Zd	 Zd
 ZddZy)ExceptionCaptureposthogNclientr   integrationsc                    || _         t        j                  | _        | j                  t        _        | j
                  t        _        g | _        |xs g D ]J  }|t        j                  k(  s	 ddl
m}  || j                        }| j                  j                  |       L y # t        $ r(}| j                  j!                  d|        Y d }~zd }~ww xY w)Nr   )DjangoIntegrationz%Failed to enable Django integration: )r   sys
excepthookoriginal_excepthookexception_handlerthread_exception_handler	threadingenabled_integrationsr	   r   %posthog.exception_integrations.djangor   exception_receiverappend	Exceptionlog	exception)selfr   r   integrationr   enabled_integrationes          r   __init__zExceptionCapture.__init__   s    #&>> //#<<	$&!'-2-K l111TW*;D<S<S*T'--445HI . ! THH&&)Nqc'RSSTs   ,3B""	C+CCc                 p    | j                   t        _        | j                  D ]  }|j	                           y N)r   r   r   r   	uninstall)r&   r'   s     r   closezExceptionCapture.close'   s+    1144K!!# 5r   c                 R    | j                  |||f       | j                  |||       y r,   )capture_exceptionr   )r&   exc_type	exc_valueexc_tracebacks       r   r   z"ExceptionCapture.exception_handler,   s)    )]CD  9mDr   c                 h    | j                  |j                  |j                  |j                  f       y r,   )r0   r1   r2   r3   )r&   argss     r   r   z)ExceptionCapture.thread_exception_handler1   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         )r0   )r&   exc_infoextra_propertiesmetadatas       r   r!   z#ExceptionCapture.exception_receiver4   sC    ,,%'7'FGHHXa[(1+FQr   c                     	 |r|j                  d      nd }| j                  j                  ||       y # t        $ r(}| j                  j                  d|        Y d }~y d }~ww xY w)Nr7   zFailed to capture exception: )getr   r0   r#   r$   r%   )r&   r%   r<   r7   r)   s        r   r0   z"ExceptionCapture.capture_exception;   s]    	D9A(,,}5tKKK)))[A 	DHH!>qcBCC	Ds   14 	A%A  A%r,   )r   r   r   logging	getLoggerr$   r   r   r	   r*   r.   r   r   r!   r0   r   r   r   r   r      sS     '

I
&CTx Tx\@R7S T&$
E
TRDr   r   )r?   r   r   enumr   typingr   r   r   posthog.clientr   strr	   r   r   r   r   <module>rE      s7     
   0 0%3 1D 1Dr   