|
7 | 7 | import datadog.trace.agent.tooling.InstrumenterModule; |
8 | 8 | import datadog.trace.api.Config; |
9 | 9 | import net.bytebuddy.asm.Advice; |
| 10 | +import de.thetaphi.forbiddenapis.SuppressForbidden; |
10 | 11 | import org.apache.spark.SparkContext; |
11 | 12 | import org.apache.spark.sql.execution.SparkPlan; |
12 | 13 | import org.apache.spark.sql.execution.SparkPlanInfo; |
@@ -95,20 +96,37 @@ public static void enter(@Advice.This SparkContext sparkContext) { |
95 | 96 |
|
96 | 97 | public static class SparkPlanInfoAdvice { |
97 | 98 | @Advice.OnMethodExit(suppress = Throwable.class, onThrowable = Throwable.class) |
| 99 | + @SuppressForbidden |
98 | 100 | public static void exit( |
99 | 101 | @Advice.Return(readOnly = false) SparkPlanInfo planInfo, |
100 | 102 | @Advice.Argument(0) SparkPlan plan) { |
101 | 103 | if (planInfo.metadata().size() == 0 |
102 | 104 | && (Config.get().isDataJobsParseSparkPlanEnabled() |
103 | 105 | || Config.get().isDataJobsExperimentalFeaturesEnabled())) { |
104 | 106 | Spark213PlanSerializer planUtils = new Spark213PlanSerializer(); |
105 | | - planInfo = |
106 | | - new SparkPlanInfo( |
107 | | - planInfo.nodeName(), |
108 | | - planInfo.simpleString(), |
109 | | - planInfo.children(), |
110 | | - HashMap.from(JavaConverters.asScala(planUtils.extractFormattedProduct(plan))), |
111 | | - planInfo.metrics()); |
| 107 | + scala.collection.immutable.Map<String, String> meta = |
| 108 | + HashMap.from(JavaConverters.asScala(planUtils.extractFormattedProduct(plan))); |
| 109 | + try { |
| 110 | + Class<?> spiClass = Class.forName("org.apache.spark.sql.execution.SparkPlanInfo"); |
| 111 | + java.lang.reflect.Constructor<?> targetCtor = null; |
| 112 | + for (java.lang.reflect.Constructor<?> c : spiClass.getConstructors()) { |
| 113 | + if (c.getParameterCount() == 5) { |
| 114 | + targetCtor = c; |
| 115 | + break; |
| 116 | + } |
| 117 | + } |
| 118 | + if (targetCtor != null) { |
| 119 | + Object newInst = |
| 120 | + targetCtor.newInstance( |
| 121 | + planInfo.nodeName(), |
| 122 | + planInfo.simpleString(), |
| 123 | + planInfo.children(), |
| 124 | + meta, |
| 125 | + planInfo.metrics()); |
| 126 | + planInfo = (SparkPlanInfo) newInst; |
| 127 | + } |
| 128 | + } catch (Throwable ignored) { |
| 129 | + } |
112 | 130 | } |
113 | 131 | } |
114 | 132 | } |
|
0 commit comments