Skip to content

Commit 67ee5ad

Browse files
put custom tags into a single defined attribute
1 parent cedc49c commit 67ee5ad

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 7 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,15 @@ private void initApplicationSpanIfNotInitialized() {
244245
AgentTracer.SpanBuilder builder = buildSparkSpan("spark.application", null);
245246

246247
if (applicationStart != null) {
248+
String customTags =
249+
Config.get().getGlobalTags().entrySet().stream()
250+
.map(e -> e.getKey() + ":" + e.getValue())
251+
.collect(Collectors.joining(","));
252+
247253
builder
248254
.withStartTimestamp(applicationStart.time() * 1000)
249255
.withTag("application_name", applicationStart.appName())
256+
.withTag("djm.tags", customTags)
250257
.withTag("spark_user", applicationStart.sparkUser());
251258

252259
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 all custom tags get propagated into a single attributes of application span"() {
592+
setup:
593+
def customTags = "tagKey1:tagKeyValue1,tagKey2:tagKeyValue2"
594+
injectSysConfig("dd.tags", customTags)
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"] == customTags
606+
}
607+
}
608+
}
609+
}
610+
591611
def "test setupOpenLineage fills circuit breaker config"(
592612
Boolean configEnabled,
593613
String sparkConfCircuitBreakerType,

0 commit comments

Comments
 (0)