o
    BDiz                     @   s   d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	 d dl
mZ er:d dl
mZ d dl
mZ d dlmZmZmZ G dd	 d	eZd
d Zdd Zdd ZdS )    N)Integration)capture_internal_exceptionsexc_info_from_error!single_exception_from_error_tuplewalk_exception_chainevent_hint_with_exc_info)TYPE_CHECKING)Any)Optional)ExcInfoEventHintc                   @   s   e Zd ZdZedd ZdS )SparkWorkerIntegrationspark_workerc                  C   s   dd l m}  t| _d S Nr   )pyspark.daemondaemon_sentry_worker_mainworker_main)original_daemon r   c/var/www/Datamplify/venv/lib/python3.10/site-packages/sentry_sdk/integrations/spark/spark_worker.py
setup_once   s   
z!SparkWorkerIntegration.setup_onceN)__name__
__module____qualname__
identifierstaticmethodr   r   r   r   r   r      s    r   c           	   	   C   s   t  }ddd}t| } | \}}}g }t| D ]\}}}|tttfvr0|t||||j	| q|rN|
  t| }dd|id}t  t j||d d S d S )NsparkF)typehandlederrorvalues)level	exception)hint)
sentry_sdk
get_clientr   r   
SystemExitEOFErrorConnectionResetErrorappendr   optionsreverser   _tag_task_contextcapture_event)	exc_infoclient	mechanismexc_type	exc_valuetbrvr%   eventr   r   r   _capture_exception!   s(   

r8   c                     s*   ddl m  t } | j fdd}d S )Nr   TaskContextc                    sH  t   t t}  }|d u s|d u r | W  d    S | di dt|  | d dt|	  | d dt|
  | d dt|  |jrd|jv rp| d d|jd  | d d|jd	  d
|jv r| di d|jd
  W d    | S W d    | S W d    | S 1 sw   Y  | S )NtagsstageIdpartitionIdattemptNumbertaskAttemptIdsentry_app_nameapp_nameapplication_idsentry_application_idzcallSite.shortextracallSite)r   r&   r'   get_integrationr   get
setdefaultstrr<   r=   r>   r?   _localProperties)r7   r%   integrationtask_contextr9   r   r   process_eventE   sJ   	






z(_tag_task_context.<locals>.process_event)pyspark.taskcontextr:   r&   get_isolation_scopeadd_event_processor)scoperM   r   r9   r   r.   ?   s   r.   c                  O   s   dd l m} z|j| i | W d S  tyD   t td urAt	 }t
  t| W d    Y d S 1 s9w   Y  Y d S Y d S w r   )pyspark.workerworkermainr(   r&   r'   rF   r   sysr0   r   r8   )argskwargsoriginal_workerr0   r   r   r   r   j   s   
&r   )rU   r&   sentry_sdk.integrationsr   sentry_sdk.utilsr   r   r   r   r   typingr   r	   r
   sentry_sdk._typesr   r   r   r   r8   r.   r   r   r   r   r   <module>   s    +