
    \j0                         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	e      Zdd
ZddZddZy)    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                   "    e Zd ZdZedd       Zy)SparkWorkerIntegrationspark_workerNc                  &    dd l m}  t        | _        y Nr   )pyspark.daemondaemon_sentry_worker_mainworker_main)original_daemons    T/root/env/lib/python3.12/site-packages/sentry_sdk/integrations/spark/spark_worker.py
setup_oncez!SparkWorkerIntegration.setup_once   s    0&9#    returnN)__name__
__module____qualname__
identifierstaticmethodr    r   r   r   r      s    J: :r   r   c           
         t        j                         }ddd}t        |       } | \  }}}g }t        |       D ]B  \  }}}|t        t
        t        fvs|j                  t        ||||j                  |             D |rD|j                          t        |       }dd|id}t                t        j                  ||       y y )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,   events	            r   _capture_exceptionr?       s    ""$F U3I"8,H&Hi	B $8#A )RJ2FGGII1iV^^Y 



'1#*(BH  T2 
r   c                  d    ddl m t        j                         } | j                  dfd       }y )Nr   )TaskContextc                    t               5  t        j                         j                  t              }j                         }||| cd d d        S | j                  di       j                  dt        |j                                      | d   j                  dt        |j                                      | d   j                  dt        |j                                      | d   j                  dt        |j                                      |j                  rd|j                  v rD| d   j                  d|j                  d          | d   j                  d|j                  d	          d
|j                  v r/| j                  di       j                  d|j                  d
          d d d        | S # 1 sw Y   | S xY w)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strrD   rE   rF   rG   _localProperties)r>   r,   integrationtask_contextrA   s       r   process_eventz(_tag_task_context.<locals>.process_eventB   s   (* 	$//1AA&K '??,L"l&:	 	 VR(333|3356 &M$$]C8P8P8R4ST&M$$_c,:T:T:V6WX&M$$_c,:T:T:V6WX,,$(E(EE&M,,"L$A$ABS$T &M,,($556MN
 $|'D'DD$$Wb1<<"L$A$ABR$S7	> ?	> s   =F5EF55F?)r>   r   r,   r   r   zOptional[Event])pyspark.taskcontextrA   r-   get_isolation_scopeadd_event_processor)scoperU   rA   s     @r   r5   r5   =   s,    /**,E
   r   c                  $   dd l m} 	  |j                  | i | y # t        $ rk t	        j
                         j                  t              At        j                         }t               5  t        |       d d d        Y y # 1 sw Y   Y y xY wY y w xY wr   )pyspark.workerworkermainr/   r-   r.   rN   r   sysr7   r   r?   )argskwargsoriginal_workerr7   s       r   r   r   f   s}    ,-d-f- -  "223IJV||~H,. -"8,- - - W-s.    AB)A?5B?B		B	BB)r7   r   r   Nr   )r_   Optional[Any]r`   rb   r   N)r^   r-   sentry_sdk.integrationsr   sentry_sdk.utilsr   r   r   r   r   typingr	   r
   r   sentry_sdk._typesr   r   r   r   r?   r5   r   r#   r   r   <module>rg      sH    
  /  !66:[ :3:&R	-r   