
    gh$                         S SK r S SKJr  S SKJrJr  S SKJr  \(       a  S SKJr  S SKJ	r	  S SK
JrJr  S SKJr   " S	 S
\5      rS rS rS rS rS rS r " S S5      r " S S\5      rS rg)    N)Integration)capture_internal_exceptionsensure_integration_enabled)TYPE_CHECKING)Any)Optional)EventHintSparkContextc                   (    \ rS rSrSr\S 5       rSrg)SparkIntegration   sparkc                      [        5         g N)_setup_sentry_tracing     m/home/kali/devsecops-assessor/venv/lib/python3.13/site-packages/sentry_sdk/integrations/spark/spark_driver.py
setup_onceSparkIntegration.setup_once   s
     	r   r   N)__name__
__module____qualname____firstlineno__
identifierstaticmethodr   __static_attributes__r   r   r   r   r      s    J   r   r   c                      SSK Jn   U R                  nU(       a9  UR                  SUR                  5        UR                  SUR
                  5        gg)z
Set properties in driver that propagate to worker processes, allowing for workers to have access to those properties.
This allows worker integration to have access to app_name and application_id.
r   r   sentry_app_namesentry_application_idN)pysparkr   _active_spark_contextsetLocalPropertyappNameapplicationId)r   spark_contexts     r   _set_app_propertiesr)      sP     % 66M&&!!	
 	&&#''	
 r   c                     SSK Jn  U R                  nU" U5        [        5       nU R                  R                  5       R                  U5        g)z9
Start java gateway server to add custom `SparkListener`
r   )ensure_callback_server_startedN)pyspark.java_gatewayr+   _gatewaySentryListener_jscscaddSparkListener)r0   r+   gwlisteners       r   _start_sentry_listenerr4   ,   s9    
 D	B"2&HGGJJL!!(+r   c                 Z   ^  [         R                  " 5       nUR                  U 4S j5       ng )Nc                 b  > [        5          [        R                  " 5       R                  [        5      c  U sS S S 5        $ TR
                  c  U sS S S 5        $ U R                  S0 5      R                  STR                  5       5        U R                  S0 5      R                  STR                  R                  S5      5        U S   R                  STR                  R                  S5      5        U S   R                  STR                  R                  S	5      5        U S   R                  S
TR                  R                  S5      5        U S   R                  STR                  5        U S   R                  STR                  5        U S   R                  STR                  5        U S   R                  STR                  5        U S   R                  STR                  5        U R                  S0 5      R                  STR                  5        S S S 5        U $ ! , (       d  f       U $ = f)Nuseridtagszexecutor.idzspark.executor.idzspark-submit.deployModezspark.submit.deployModezdriver.hostzspark.driver.hostzdriver.portzspark.driver.portspark_versionapp_nameapplication_idmaster
spark_homeextraweb_url)r   
sentry_sdk
get_clientget_integrationr   r$   
setdefault	sparkUser_confgetversionr&   r'   r=   	sparkHomeuiWebUrl)eventhintr0   s     r   process_event+_add_event_processor.<locals>.process_event=   s    )*$$&667GHP +* ''/ +* VR(33D",,.IVR(33rxx||,?@ &M$$)67 &M$$]BHHLLAT4UV&M$$]BHHLLAT4UV&M$$_bjjA&M$$Z<&M$$%5r7G7GH&M$$Xryy9&M$$\2<<@Wb)44YL1 +4 5 +*4 s   +HHF<H
H.)rA   get_isolation_scopeadd_event_processor)r0   scoperM   s   `  r   _add_event_processorrR   9   s)    **,E
 r   c                 D    [        U 5        [        5         [        U 5        g r   )r4   r)   rR   )r0   s    r   _activate_integrationrT   ]   s     2r   c                  h   ^ SSK Jn   U R                  m[        [        T5      U4S j5       nXl        g )Nr   r   c                 6   > T" U /UQ70 UD6n[        U 5        U$ r   )rT   )selfargskwargsrvspark_context_inits       r   "_sentry_patched_spark_context_initE_patch_spark_context_init.<locals>._sentry_patched_spark_context_initk   s&      6t6v6d#	r   )r#   r   _do_initr   r   )r   r\   r[   s     @r   _patch_spark_context_initr_   e   s6    $%.. 02DE F ?r   c                  j    SSK Jn   U R                  b  [        U R                  5        g [	        5         g )Nr   r   )r#   r   r$   rT   r_   r   s    r   r   r   u   s(    $))5l@@Ar   c                       \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r " S S5      rSrg)SparkListener   c                     g r   r   )rW   applicationEnds     r   onApplicationEndSparkListener.onApplicationEnd       r   c                     g r   r   )rW   applicationStarts     r   onApplicationStart SparkListener.onApplicationStart   rh   r   c                     g r   r   )rW   blockManagerAddeds     r   onBlockManagerAdded!SparkListener.onBlockManagerAdded   rh   r   c                     g r   r   )rW   blockManagerRemoveds     r   onBlockManagerRemoved#SparkListener.onBlockManagerRemoved   rh   r   c                     g r   r   )rW   blockUpdateds     r   onBlockUpdatedSparkListener.onBlockUpdated   rh   r   c                     g r   r   )rW   environmentUpdates     r   onEnvironmentUpdate!SparkListener.onEnvironmentUpdate   rh   r   c                     g r   r   )rW   executorAddeds     r   onExecutorAddedSparkListener.onExecutorAdded   rh   r   c                     g r   r   )rW   executorBlacklisteds     r   onExecutorBlacklisted#SparkListener.onExecutorBlacklisted   rh   r   c                     g r   r   )rW   executorBlacklistedForStages     r   onExecutorBlacklistedForStage+SparkListener.onExecutorBlacklistedForStage   s     	r   c                     g r   r   )rW   executorMetricsUpdates     r   onExecutorMetricsUpdate%SparkListener.onExecutorMetricsUpdate   rh   r   c                     g r   r   )rW   executorRemoveds     r   onExecutorRemovedSparkListener.onExecutorRemoved   rh   r   c                     g r   r   )rW   jobEnds     r   onJobEndSparkListener.onJobEnd   rh   r   c                     g r   r   )rW   jobStarts     r   
onJobStartSparkListener.onJobStart   rh   r   c                     g r   r   )rW   nodeBlacklisteds     r   onNodeBlacklistedSparkListener.onNodeBlacklisted   rh   r   c                     g r   r   )rW   nodeBlacklistedForStages     r   onNodeBlacklistedForStage'SparkListener.onNodeBlacklistedForStage   rh   r   c                     g r   r   )rW   nodeUnblacklisteds     r   onNodeUnblacklisted!SparkListener.onNodeUnblacklisted   rh   r   c                     g r   r   )rW   rK   s     r   onOtherEventSparkListener.onOtherEvent   rh   r   c                     g r   r   )rW   speculativeTasks     r   onSpeculativeTaskSubmitted(SparkListener.onSpeculativeTaskSubmitted   rh   r   c                     g r   r   )rW   stageCompleteds     r   onStageCompletedSparkListener.onStageCompleted   rh   r   c                     g r   r   )rW   stageSubmitteds     r   onStageSubmittedSparkListener.onStageSubmitted   rh   r   c                     g r   r   )rW   taskEnds     r   	onTaskEndSparkListener.onTaskEnd   rh   r   c                     g r   r   )rW   taskGettingResults     r   onTaskGettingResult!SparkListener.onTaskGettingResult   rh   r   c                     g r   r   )rW   	taskStarts     r   onTaskStartSparkListener.onTaskStart   rh   r   c                     g r   r   )rW   unpersistRDDs     r   onUnpersistRDDSparkListener.onUnpersistRDD   rh   r   c                       \ rS rSrS/rSrg)SparkListener.Java   z1org.apache.spark.scheduler.SparkListenerInterfacer   N)r   r   r   r   
implementsr   r   r   r   Javar      s
    IJ
r   r   r   N)r   r   r   r   rf   rk   ro   rs   rw   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rb   rb      s    K Kr   rb   c                   8    \ rS rSr S	S jrS rS rS rS rSr	g)
r.      Nc                 J    [         R                  " 5       R                  XUS9  g )Nlevelmessagedata)rA   rO   add_breadcrumb)rW   r   r   r   s       r   _add_breadcrumbSentryListener._add_breadcrumb   s%     	&&(77t 	8 	
r   c                     [         R                  " 5       R                  5         SR                  UR	                  5       5      nU R                  SUS9  [        5         g )NzJob {} Startedinfo)r   r   )rA   rO   clear_breadcrumbsformatjobIdr   r)   )rW   r   r   s      r   r   SentryListener.onJobStart   sG    &&(::<"))(..*:;67;r   c                 6   SnSnSUR                  5       R                  5       0nUR                  5       R                  5       S:X  a"  SnSR                  UR                  5       5      nO!SnSR                  UR                  5       5      nU R	                  X#US9  g )	N resultJobSucceededr   zJob {} EndedwarningzJob {} Failedr   )	jobResulttoStringr   r   r   )rW   r   r   r   r   s        r   r   SentryListener.onJobEnd   s    &**,5578&&(N:E$++FLLN;GE%,,V\\^<G5Er   c                     UR                  5       nSR                  UR                  5       5      nSUR                  5       0n[	        U5      nUb  XTS'   U R                  SX4S9  [        5         g )NzStage {} Submittedname	attemptIdr   r   )	stageInfor   stageIdr   _get_attempt_idr   r)   )rW   r   
stage_infor   r   
attempt_ids         r   r   SentryListener.onStageSubmitted	  sk    #--/
&--j.@.@.BC
)*$Z0
! *67Fr   c                    SSK Jn  UR                  5       nSnSnSUR                  5       0n[	        U5      nUb  XvS'    UR                  5       R                  5       US'   SR                  UR                  5       5      nSnU R                  XTUS9  g ! U a$    S	R                  UR                  5       5      nS
n N:f = f)Nr   )Py4JJavaErrorr   r   r   reasonzStage {} Failedr   zStage {} Completedr   r   )
py4j.protocolr   r   r   r   failureReasonrG   r   r   r   )rW   r   r   r   r   r   r   r   s           r   r   SentryListener.onStageCompleted  s    /#--/

)*$Z0
! *	'557;;=DN'..z/A/A/CDGE
 	5E	  	*11*2D2D2FGGE	s    AB 'B=<B=r   r   )
r   r   r   r   r   r   r   r   r   r   r   r   r   r.   r.      s"    
 		
FFr   r.   c                      U R                  5       $ ! [         a     Of = f U R                  5       $ ! [         a     g f = fr   )r   	ExceptionattemptNumber)r   s    r   r   r   /  sQ    ##%% '')) s    
3 
A A )rA   sentry_sdk.integrationsr   sentry_sdk.utilsr   r   typingr   r   r   sentry_sdk._typesr	   r
   r#   r   r   r)   r4   rR   rT   r_   r   rb   r.   r   r   r   r   <module>r      sp     / T  -$ {  
(
,!H?  dK dKNFF] FFRr   