o
    ni                      @  s   d dl mZ dZd dlZd dlZ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mZ d dlmZ d dlZd dlZd dlZd dlZd dlZd dlZerRd dlZdZed ZdddZG dd dZdS )    )annotations)SentryN)TracebackType)TYPE_CHECKINGAnyCallableLiteralquotezRhttps://2592b1968ea94cca9b5ef5e348e094a7@o151352.ingest.sentry.io/4504800232407040)okexitedcrashedabnormalfuncr   returnc                   s   t  d
 fdd}|S )zODecorator to ensure that Sentry methods do nothing if disabled and don't raise.selftype[Sentry]argsr   kwargsr   c              
     sl   | j rd S z | g|R i |W S  ty5 } z jdkr*| d j d|  W Y d }~d S d }~ww )N	exceptionz	Error in z: )	_disabled	Exception__name__r   )r   r   r   er    T/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/wandb/analytics/sentry.pywrapper$   s   
z_safe_noop.<locals>.wrapperN)r   r   r   r   r   r   r   r   )	functoolswraps)r   r   r   r   r   
_safe_noop!   s   r    c                   @  s   e Zd ZU ded< d)ddZed*dd	Zed)d
dZed+d,ddZ	e		d-d.ddZ
d/ddZed)ddZed)d d!Zed0d1d"d#Ze		d2d3d'd(ZdS )4r   boolr   r   Nonec                 C  s@   t j  | _t | _tjt jj	t
| _d | _t| j d S N)wandbenverror_reporting_enabledr   set_sent_messagesosenvironget
SENTRY_DSNSENTRY_DEFAULT_DSNdsnscopeatexitregisterend_session)r   r   r   r   __init__6   s
   zSentry.__init__strc                 C  s&   t tjjjd }|rdS dS )z(Return the environment we're running in.z.gitdevelopment
production)pathlibPath__file__parentjoinpathexists)r   is_gitr   r   r   environmentA   s   zSentry.environmentc                 C  s@   t j| jd| jtjd}t   | _| j	  | j
| dS )zSetup Sentry SDK.

        We use lower-level APIs (i.e., not sentry_sdk.init) here
        to avoid the possibility of interfering with the user's
        own Sentry SDK setup.
        F)r.   default_integrationsr>   releaseN)
sentry_sdkClientr.   r>   r$   __version__get_global_scopeforkr/   clear
set_client)r   clientr   r   r   setupJ   s   
zSentry.setupTmessagerepeat
str | Nonec                 C  sZ   |s	|| j v r	dS | j | tj| j t|W  d   S 1 s&w   Y  dS )zSend a message to Sentry.N)r(   addrA   r/   use_isolation_scopecapture_message)r   rJ   rK   r   r   r   rJ   \   s   $zSentry.messageFNexcjstr | BaseException | tuple[type[BaseException] | None, BaseException | None, TracebackType | None] | NonehandledstatusSessionStatus | Nonec           	      C  s   t |trtjt|}nt |trtj|}nt }tjj	|| j
 jd|dd\}}d}ztj
| j
 t|}W d   n1 sJw   Y  W n	 tyY   Y nw |pa|s`dnd}| j|d | j
 }|duru|  |S )zLog an exception to Sentry.generic)typerR   )client_options	mechanismNr   erroredrS   )
isinstancer4   rA   utilsexc_info_from_errorr   BaseExceptionsysexc_infoevent_from_exceptionr/   
get_clientoptionsrN   capture_eventmark_sessionflush)	r   rP   rR   rS   r`   event_event_idrH   r   r   r   r   e   s2   




zSentry.exceptionr   c                 C  s   |  | |t d )zRe-raise an exception after logging it to Sentry.

        Use this for top-level exceptions when you want the user to see the traceback.

        Must be called from within an exception handler.
           )r   with_tracebackr_   r`   )r   rP   r   r   r   reraise   s   
zSentry.reraisec                 C  s0   | j dusJ | j j}|du r| j   dS dS )zStart a new session.N)r/   _sessionstart_session)r   sessionr   r   r   rn      s
   zSentry.start_sessionc                 C  sN   | j dusJ | j  }| j j}|dur#|dur%| j   |  dS dS dS )zEnd the current session.N)r/   rb   rm   r2   rf   )r   rH   ro   r   r   r   r2      s   

zSentry.end_sessionc                 C  s2   | j dusJ | j j}|dur|j|d dS dS )z'Mark the current session with a status.NrZ   )r/   rm   update)r   rS   ro   r   r   r   re      s
   zSentry.mark_sessiontagsdict[str, Any] | Noneprocess_contextc                   sb  | j dusJ d}|r| j d|  du rdS |D ]} |d}|dvr-| j || q ddr7d}n ddr@d}n d	drId
}nd}| j d| dD ]I}| d| d}}	 |	drhqTz,tj d }
 fdddD \}}| j |	|
 d| d| d| d |  	 W qT ty   Y qTw  d}|rd|i| j _|   dS )aW  Configure the Sentry scope for the current thread.

        This function should be called at the beginning of every thread that
        will send events to Sentry. It sets the tags that will be applied to
        all events sent from this thread. It also tries to start a session
        if one doesn't already exist for this thread.
        N)entityprojectrun_idrun_url	sweep_urlsweep_id
deploymentx_disable_servicex_require_legacy_servicelaunch	_platformrs   )N _colabcolab_jupyterjupyter_ipythonipythonpythonpython_runtime)runsweep_id_urlbase_urlc                 3  s    | ]	}t  | V  qd S r#   r	   ).0krq   r   r   	<genexpr>   s    z)Sentry.configure_scope.<locals>.<genexpr>)rt   ru   /zs/email)	r/   set_tagr+   r$   utilapp_urlr   userrn   )r   rq   rs   settings_tagstagvalr   objobj_idobj_urlr   rt   ru   r   r   r   r   configure_scope   sJ   "
zSentry.configure_scope)r   r"   )r   r4   )T)rJ   r4   rK   r!   r   rL   )FN)rP   rQ   rR   r!   rS   rT   r   rL   )rP   r   r   r"   r#   )rS   rT   r   r"   )NN)rq   rr   rs   rL   r   r"   )r   
__module____qualname____annotations__r3   propertyr>   r    rI   rJ   r   rl   rn   r2   re   r   r   r   r   r   r   3   s0   
 

,
r   )r   r   r   r   )
__future__r   __all__r0   r   r)   r7   r_   typesr   typingr   r   r   r   urllib.parser
   rA   sentry_sdk.scopesentry_sdk.utilsr$   	wandb.env
wandb.util"wandb.sdk.internal.settings_staticr-   SessionStatusr    r   r   r   r   r   <module>   s.    
