36
36
import java .util .Optional ;
37
37
import java .util .Properties ;
38
38
import java .util .UUID ;
39
+ import java .util .concurrent .atomic .AtomicReference ;
39
40
import java .util .function .Consumer ;
40
41
import org .apache .spark .ExceptionFailure ;
41
42
import org .apache .spark .SparkConf ;
@@ -69,7 +70,8 @@ public abstract class AbstractDatadogSparkListener extends SparkListener {
69
70
private static final Logger log = LoggerFactory .getLogger (AbstractDatadogSparkListener .class );
70
71
private static final ObjectMapper objectMapper = new ObjectMapper ();
71
72
public static volatile AbstractDatadogSparkListener listener = null ;
72
- public static volatile SparkListenerInterface openLineageSparkListener = null ;
73
+ public static volatile AtomicReference <SparkListenerInterface > openLineageSparkListener =
74
+ new AtomicReference <>(null );
73
75
public static volatile SparkConf openLineageSparkConf = null ;
74
76
75
77
public static volatile boolean finishTraceOnApplicationEnd = true ;
@@ -167,21 +169,45 @@ public AbstractDatadogSparkListener(SparkConf sparkConf, String appId, String sp
167
169
168
170
public void setupOpenLineage (DDTraceId traceId ) {
169
171
log .debug ("Setting up OpenLineage tags" );
170
- if (openLineageSparkListener != null ) {
171
- openLineageSparkConf .set ("spark.openlineage.transport.type" , "composite" );
172
- openLineageSparkConf .set ("spark.openlineage.transport.continueOnFailure" , "true" );
173
- openLineageSparkConf .set ("spark.openlineage.transport.transports.agent.type" , "http" );
174
- openLineageSparkConf .set (
172
+ log .info (
173
+ "Classloader for current variable: ({}) {}" ,
174
+ System .identityHashCode (
175
+ AbstractDatadogSparkListener .openLineageSparkListener
176
+ .get ()
177
+ .getClass ()
178
+ .getClassLoader ()),
179
+ AbstractDatadogSparkListener .openLineageSparkListener .get ().getClass ().getClassLoader ());
180
+ log .info (
181
+ "Current thread class loader: ({}) {}" ,
182
+ System .identityHashCode (Thread .currentThread ().getContextClassLoader ()),
183
+ Thread .currentThread ().getContextClassLoader ());
184
+ if (AbstractDatadogSparkListener .openLineageSparkListener .get () != null ) {
185
+ AbstractDatadogSparkListener .openLineageSparkConf .set (
186
+ "spark.openlineage.transport.type" , "composite" );
187
+ AbstractDatadogSparkListener .openLineageSparkConf .set (
188
+ "spark.openlineage.transport.continueOnFailure" , "true" );
189
+ AbstractDatadogSparkListener .openLineageSparkConf .set (
190
+ "spark.openlineage.transport.transports.agent.type" , "http" );
191
+ AbstractDatadogSparkListener .openLineageSparkConf .set (
175
192
"spark.openlineage.transport.transports.agent.url" , getAgentHttpUrl ());
176
- openLineageSparkConf .set (
193
+ AbstractDatadogSparkListener . openLineageSparkConf .set (
177
194
"spark.openlineage.transport.transports.agent.endpoint" , AGENT_OL_ENDPOINT );
178
- openLineageSparkConf .set ("spark.openlineage.transport.transports.agent.compression" , "gzip" );
179
- openLineageSparkConf .set (
195
+ AbstractDatadogSparkListener .openLineageSparkConf .set (
196
+ "spark.openlineage.transport.transports.agent.compression" , "gzip" );
197
+ AbstractDatadogSparkListener .openLineageSparkConf .set (
180
198
"spark.openlineage.run.tags" ,
181
- "_dd.trace_id:" + traceId .toString () + ";_dd.ol_intake.emit_spans:false" );
199
+ "_dd.trace_id:"
200
+ + traceId .toString ()
201
+ + ";_dd.ol_intake.emit_spans:false;dd.ol_service:"
202
+ + sparkServiceName );
182
203
return ;
183
204
}
184
- log .debug ("No OpenLineageSparkListener!" );
205
+ log .info (
206
+ "There is no OpenLineage Spark Listener in the context. Skipping setting tags. {}" ,
207
+ AbstractDatadogSparkListener .openLineageSparkListener .get ());
208
+ log .info (
209
+ "There is no OpenLineage SparkConf in the context. Skipping setting tags. {}" ,
210
+ AbstractDatadogSparkListener .openLineageSparkConf );
185
211
}
186
212
187
213
/** Resource name of the spark job. Provide an implementation based on a specific scala version */
@@ -212,7 +238,7 @@ public synchronized void onApplicationStart(SparkListenerApplicationStart applic
212
238
.map (context -> context .getTraceId ())
213
239
.orElse (predeterminedTraceIdContext .getTraceId ()));
214
240
}
215
- notifyOl (x -> openLineageSparkListener .onApplicationStart (x ), applicationStart );
241
+ notifyOl (x -> openLineageSparkListener .get (). onApplicationStart (x ), applicationStart );
216
242
}
217
243
218
244
private void initApplicationSpanIfNotInitialized () {
@@ -273,7 +299,7 @@ public void onApplicationEnd(SparkListenerApplicationEnd applicationEnd) {
273
299
log .info (
274
300
"Received spark application end event, finish trace on this event: {}" ,
275
301
finishTraceOnApplicationEnd );
276
- notifyOl (x -> openLineageSparkListener .onApplicationEnd (x ), applicationEnd );
302
+ notifyOl (x -> openLineageSparkListener .get (). onApplicationEnd (x ), applicationEnd );
277
303
278
304
if (finishTraceOnApplicationEnd ) {
279
305
finishApplication (applicationEnd .time (), null , 0 , null );
@@ -468,7 +494,7 @@ public synchronized void onJobStart(SparkListenerJobStart jobStart) {
468
494
stageToJob .put (stageId , jobStart .jobId ());
469
495
}
470
496
jobSpans .put (jobStart .jobId (), jobSpan );
471
- notifyOl (x -> openLineageSparkListener .onJobStart (x ), jobStart );
497
+ notifyOl (x -> openLineageSparkListener .get (). onJobStart (x ), jobStart );
472
498
}
473
499
474
500
@ Override
@@ -499,7 +525,7 @@ public synchronized void onJobEnd(SparkListenerJobEnd jobEnd) {
499
525
if (metrics != null ) {
500
526
metrics .setSpanMetrics (jobSpan );
501
527
}
502
- notifyOl (x -> openLineageSparkListener .onJobEnd (x ), jobEnd );
528
+ notifyOl (x -> openLineageSparkListener .get (). onJobEnd (x ), jobEnd );
503
529
504
530
jobSpan .finish (jobEnd .time () * 1000 );
505
531
}
@@ -669,7 +695,7 @@ public void onTaskEnd(SparkListenerTaskEnd taskEnd) {
669
695
Properties props = stageProperties .get (stageSpanKey );
670
696
sendTaskSpan (stageSpan , taskEnd , props );
671
697
672
- notifyOl (x -> openLineageSparkListener .onTaskEnd (x ), taskEnd );
698
+ notifyOl (x -> openLineageSparkListener .get (). onTaskEnd (x ), taskEnd );
673
699
}
674
700
675
701
private void sendTaskSpan (
@@ -753,20 +779,20 @@ public void onOtherEvent(SparkListenerEvent event) {
753
779
754
780
private <T extends SparkListenerEvent > void notifyOl (Consumer <T > ol , T event ) {
755
781
if (!Config .get ().isDataJobsOpenLineageEnabled ()) {
756
- log .trace ("Ignoring event {} - OpenLineage not enabled" , event );
782
+ log .debug ("Ignoring event {} - OpenLineage not enabled" , event );
757
783
return ;
758
784
}
759
785
760
786
if (isRunningOnDatabricks || isStreamingJob ) {
761
787
log .debug ("Not emitting event when running on databricks or on streaming jobs" );
762
788
return ;
763
789
}
764
- if (openLineageSparkListener != null ) {
790
+ if (AbstractDatadogSparkListener . openLineageSparkListener . get () != null ) {
765
791
log .debug (
766
792
"Passing event `{}` to OpenLineageSparkListener" , event .getClass ().getCanonicalName ());
767
793
ol .accept (event );
768
794
} else {
769
- log .trace ("OpenLineageSparkListener is null" );
795
+ log .debug ("OpenLineageSparkListener is null" );
770
796
}
771
797
}
772
798
@@ -818,7 +844,7 @@ private synchronized void updateAdaptiveSQLPlan(SparkListenerEvent event) {
818
844
private synchronized void onSQLExecutionStart (SparkListenerSQLExecutionStart sqlStart ) {
819
845
sqlPlans .put (sqlStart .executionId (), sqlStart .sparkPlanInfo ());
820
846
sqlQueries .put (sqlStart .executionId (), sqlStart );
821
- notifyOl (x -> openLineageSparkListener .onOtherEvent (x ), sqlStart );
847
+ notifyOl (x -> openLineageSparkListener .get (). onOtherEvent (x ), sqlStart );
822
848
}
823
849
824
850
private synchronized void onSQLExecutionEnd (SparkListenerSQLExecutionEnd sqlEnd ) {
@@ -831,7 +857,7 @@ private synchronized void onSQLExecutionEnd(SparkListenerSQLExecutionEnd sqlEnd)
831
857
if (metrics != null ) {
832
858
metrics .setSpanMetrics (span );
833
859
}
834
- notifyOl (x -> openLineageSparkListener .onOtherEvent (x ), sqlEnd );
860
+ notifyOl (x -> openLineageSparkListener .get (). onOtherEvent (x ), sqlEnd );
835
861
836
862
span .finish (sqlEnd .time () * 1000 );
837
863
}
0 commit comments