Skip to content

Commit 8981bb1

Browse files
committed
catch error at the end
1 parent bf99260 commit 8981bb1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ public static void exit(@Advice.Thrown Throwable throwable) {
106106
if (AbstractDatadogSparkListener.listener != null) {
107107
AbstractDatadogSparkListener.listener.finishApplication(
108108
System.currentTimeMillis(), throwable, 0, null);
109+
} else {
110+
try {
111+
Class<?> adviceClass =
112+
Class.forName("datadog.trace.instrumentation.spark.SparkLauncherAdvice");
113+
Object span = adviceClass.getDeclaredField("launcherSpan").get(null);
114+
if (span != null) {
115+
if (throwable != null) {
116+
span.getClass().getMethod("addThrowable", Throwable.class).invoke(span, throwable);
117+
}
118+
span.getClass().getMethod("finish").invoke(span);
119+
adviceClass.getDeclaredField("launcherSpan").set(null, null);
120+
}
121+
} catch (Exception ignored) {
122+
}
109123
}
110124
}
111125
}

0 commit comments

Comments
 (0)