diff --git a/dd-java-agent/instrumentation/spark/spark-common/src/main/java/datadog/trace/instrumentation/spark/AbstractDatadogSparkListener.java b/dd-java-agent/instrumentation/spark/spark-common/src/main/java/datadog/trace/instrumentation/spark/AbstractDatadogSparkListener.java index 5b4e1501826..9da49156dd1 100644 --- a/dd-java-agent/instrumentation/spark/spark-common/src/main/java/datadog/trace/instrumentation/spark/AbstractDatadogSparkListener.java +++ b/dd-java-agent/instrumentation/spark/spark-common/src/main/java/datadog/trace/instrumentation/spark/AbstractDatadogSparkListener.java @@ -254,41 +254,42 @@ private void initApplicationSpanIfNotInitialized() { } log.debug("Starting tracer application span."); + if (!isRunningOnDatabricks) { + AgentTracer.SpanBuilder builder = buildSparkSpan("spark.application", null); + + if (applicationStart != null) { + String ddTags = + Config.get().getGlobalTags().entrySet().stream() + .sorted(Map.Entry.comparingByKey()) + .map(e -> e.getKey() + ":" + e.getValue()) + .collect(Collectors.joining(",")); + + builder + .withStartTimestamp(applicationStart.time() * 1000) + .withTag("application_name", applicationStart.appName()) + .withTag("djm.tags", ddTags) + .withTag("spark_user", applicationStart.sparkUser()); + + if (applicationStart.appAttemptId().isDefined()) { + builder.withTag("app_attempt_id", applicationStart.appAttemptId().get()); + } + } - AgentTracer.SpanBuilder builder = buildSparkSpan("spark.application", null); - - if (applicationStart != null) { - String ddTags = - Config.get().getGlobalTags().entrySet().stream() - .sorted(Map.Entry.comparingByKey()) - .map(e -> e.getKey() + ":" + e.getValue()) - .collect(Collectors.joining(",")); - - builder - .withStartTimestamp(applicationStart.time() * 1000) - .withTag("application_name", applicationStart.appName()) - .withTag("djm.tags", ddTags) - .withTag("spark_user", applicationStart.sparkUser()); + captureApplicationParameters(builder); - if (applicationStart.appAttemptId().isDefined()) { - builder.withTag("app_attempt_id", applicationStart.appAttemptId().get()); + Optional openlineageParentContext = + OpenlineageParentContext.from(sparkConf); + // We know we're not in Databricks context + if (openlineageParentContext.isPresent()) { + captureOpenlineageContextIfPresent(builder, openlineageParentContext.get()); + } else { + builder.asChildOf(predeterminedTraceIdContext); } - } - - captureApplicationParameters(builder); - Optional openlineageParentContext = - OpenlineageParentContext.from(sparkConf); - // We know we're not in Databricks context - if (openlineageParentContext.isPresent()) { - captureOpenlineageContextIfPresent(builder, openlineageParentContext.get()); - } else { - builder.asChildOf(predeterminedTraceIdContext); + applicationSpan = builder.start(); + setDataJobsSamplingPriority(applicationSpan); + applicationSpan.setMeasured(true); } - - applicationSpan = builder.start(); - setDataJobsSamplingPriority(applicationSpan); - applicationSpan.setMeasured(true); } private void captureOpenlineageContextIfPresent(