Skip to content

Commit aa411ca

Browse files
add dd_tags into djm.tags spark.application span attribute
1 parent c69c2cd commit aa411ca

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Properties;
3737
import java.util.UUID;
3838
import java.util.function.Consumer;
39+
import java.util.stream.Collectors;
3940
import org.apache.spark.ExceptionFailure;
4041
import org.apache.spark.SparkConf;
4142
import org.apache.spark.TaskFailedReason;
@@ -244,9 +245,16 @@ private void initApplicationSpanIfNotInitialized() {
244245
AgentTracer.SpanBuilder builder = buildSparkSpan("spark.application", null);
245246

246247
if (applicationStart != null) {
248+
String ddTags =
249+
Config.get().getGlobalTags().entrySet().stream()
250+
.sorted(Map.Entry.comparingByKey())
251+
.map(e -> e.getKey() + ":" + e.getValue())
252+
.collect(Collectors.joining(","));
253+
247254
builder
248255
.withStartTimestamp(applicationStart.time() * 1000)
249256
.withTag("application_name", applicationStart.appName())
257+
.withTag("djm.tags", ddTags)
250258
.withTag("spark_user", applicationStart.sparkUser());
251259

252260
if (applicationStart.appAttemptId().isDefined()) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,26 @@ abstract class AbstractSparkListenerTest extends InstrumentationSpecification {
588588
.contains("_dd.ol_intake.process_tags:" + ProcessTags.getTagsForSerialization())
589589
}
590590

591+
def "test DD_TAGS are put into a single attributes of application span"() {
592+
setup:
593+
def ddTags = "tagKey1:tagKeyValue1,tagKey2:tagKeyValue2"
594+
injectSysConfig("dd.tags", ddTags)
595+
def listener = getTestDatadogSparkListener()
596+
listener.onApplicationStart(applicationStartEvent(1000L))
597+
listener.onApplicationEnd(new SparkListenerApplicationEnd(5000L))
598+
599+
expect:
600+
assertTraces(1) {
601+
trace(1) {
602+
span {
603+
operationName "spark.application"
604+
spanType "spark"
605+
assert span.tags["djm.tags"] == ddTags
606+
}
607+
}
608+
}
609+
}
610+
591611
def "test setupOpenLineage fills circuit breaker config"(
592612
Boolean configEnabled,
593613
String sparkConfCircuitBreakerType,

0 commit comments

Comments
 (0)