Skip to content

Commit e677d95

Browse files
dont attach parent run context when openlineage not enabled
1 parent fb31324 commit e677d95

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

dd-java-agent/instrumentation/spark/src/main/java/datadog/trace/instrumentation/spark/OpenlineageParentContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.instrumentation.spark;
22

3+
import datadog.trace.api.Config;
34
import datadog.trace.api.DDSpanId;
45
import datadog.trace.api.DDTraceId;
56
import datadog.trace.api.datastreams.PathwayContext;
@@ -43,6 +44,11 @@ public class OpenlineageParentContext implements AgentSpanContext {
4344
public static final String OPENLINEAGE_ROOT_PARENT_RUN_ID = "spark.openlineage.rootParentRunId";
4445

4546
public static Optional<OpenlineageParentContext> from(SparkConf sparkConf) {
47+
if (!Config.get().isDataJobsOpenLineageEnabled()) {
48+
log.debug(
49+
"OpenLineage - Data Jobs integration disabled. Not returning OpenlineageParentContext");
50+
return Optional.empty();
51+
}
4652
if (!sparkConf.contains(OPENLINEAGE_PARENT_JOB_NAMESPACE)
4753
|| !sparkConf.contains(OPENLINEAGE_PARENT_JOB_NAME)
4854
|| !sparkConf.contains(OPENLINEAGE_PARENT_RUN_ID)) {

dd-java-agent/instrumentation/spark/src/testFixtures/groovy/datadog/trace/instrumentation/spark/OpenlineageParentContextTest.groovy

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package datadog.trace.instrumentation.spark
22

3+
import datadog.trace.test.util.DDSpecification
34
import org.apache.spark.SparkConf
4-
import spock.lang.Specification
55

6-
class OpenlineageParentContextTest extends Specification {
6+
class OpenlineageParentContextTest extends DDSpecification {
77
def "should create OpenLineageParentContext with particular trace id based on root parent id" () {
88
given:
9+
injectSysConfig("data.jobs.openlineage.enabled", "true")
910
SparkConf mockSparkConf = Mock(SparkConf)
1011

1112
when:
@@ -38,6 +39,7 @@ class OpenlineageParentContextTest extends Specification {
3839

3940
def "should create empty OpenLineageParentContext if any required field is missing" () {
4041
given:
42+
injectSysConfig("data.jobs.openlineage.enabled", "true")
4143
SparkConf mockSparkConf = Mock(SparkConf)
4244

4345
when:
@@ -66,6 +68,7 @@ class OpenlineageParentContextTest extends Specification {
6668

6769
def "should only generate a non-empty OpenlineageParentContext if parentRunId is a valid UUID" () {
6870
given:
71+
injectSysConfig("data.jobs.openlineage.enabled", "true")
6972
SparkConf mockSparkConf = Mock(SparkConf)
7073

7174
when:
@@ -94,6 +97,7 @@ class OpenlineageParentContextTest extends Specification {
9497

9598
def "should only generate a non-empty OpenlineageParentContext if rootParentRunId is a valid UUID" () {
9699
given:
100+
injectSysConfig("data.jobs.openlineage.enabled", "true")
97101
SparkConf mockSparkConf = Mock(SparkConf)
98102

99103
when:
@@ -119,5 +123,21 @@ class OpenlineageParentContextTest extends Specification {
119123
"6afeb6ee-729d-37f7-b8e6f47ca694" | false
120124
"6AFEB6EE-729D-37F7-AD73-B8E6F47CA694" | true
121125
}
126+
127+
def "should create empty OpenLineageParentContext if data jobs openlineage not enabled" () {
128+
given:
129+
injectSysConfig("data.jobs.openlineage.enabled", "falsebrn")
130+
SparkConf mockSparkConf = Mock(SparkConf)
131+
132+
when:
133+
mockSparkConf.contains(OpenlineageParentContext.OPENLINEAGE_PARENT_JOB_NAMESPACE) >> true
134+
mockSparkConf.contains(OpenlineageParentContext.OPENLINEAGE_PARENT_JOB_NAME) >> true
135+
mockSparkConf.contains(OpenlineageParentContext.OPENLINEAGE_PARENT_RUN_ID) >> true
136+
mockSparkConf.contains(OpenlineageParentContext.OPENLINEAGE_ROOT_PARENT_RUN_ID) >> true
137+
138+
then:
139+
Optional<OpenlineageParentContext> parentContext = OpenlineageParentContext.from(mockSparkConf)
140+
!parentContext.isPresent()
141+
}
122142
}
123143

0 commit comments

Comments
 (0)