|
@@ -5,16 +5,18 @@
|
|
|
|
|
|
package io.opentelemetry.javaagent.instrumentation.spring.kafka;
|
|
|
|
|
|
+import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
|
|
|
import static net.bytebuddy.matcher.ElementMatchers.named;
|
|
|
|
|
|
import io.opentelemetry.javaagent.bootstrap.kafka.KafkaClientsConsumerProcessTracing;
|
|
|
+import io.opentelemetry.javaagent.bootstrap.spring.SpringSchedulingTaskTracing;
|
|
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
|
|
|
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
|
|
|
import net.bytebuddy.asm.Advice;
|
|
|
import net.bytebuddy.description.type.TypeDescription;
|
|
|
import net.bytebuddy.matcher.ElementMatcher;
|
|
|
|
|
|
-public class SuppressingKafkaClientsInstrumentation implements TypeInstrumentation {
|
|
|
+public class ListenerConsumerInstrumentation implements TypeInstrumentation {
|
|
|
|
|
|
@Override
|
|
|
public ElementMatcher<TypeDescription> typeMatcher() {
|
|
@@ -25,11 +27,14 @@ public class SuppressingKafkaClientsInstrumentation implements TypeInstrumentati
|
|
|
@Override
|
|
|
public void transform(TypeTransformer transformer) {
|
|
|
transformer.applyAdviceToMethod(named("run"), this.getClass().getName() + "$RunLoopAdvice");
|
|
|
+ transformer.applyAdviceToMethod(
|
|
|
+ isConstructor(), this.getClass().getName() + "$ConstructorAdvice");
|
|
|
}
|
|
|
|
|
|
// this advice suppresses the CONSUMER spans created by the kafka-clients instrumentation
|
|
|
@SuppressWarnings("unused")
|
|
|
public static class RunLoopAdvice {
|
|
|
+
|
|
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
|
|
public static boolean onEnter() {
|
|
|
return KafkaClientsConsumerProcessTracing.setEnabled(false);
|
|
@@ -40,4 +45,19 @@ public class SuppressingKafkaClientsInstrumentation implements TypeInstrumentati
|
|
|
KafkaClientsConsumerProcessTracing.setEnabled(previousValue);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // this advice suppresses the spans generated by spring scheduling instrumentation
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ public static class ConstructorAdvice {
|
|
|
+
|
|
|
+ @Advice.OnMethodEnter(suppress = Throwable.class)
|
|
|
+ public static boolean onEnter() {
|
|
|
+ return SpringSchedulingTaskTracing.setEnabled(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Advice.OnMethodExit(suppress = Throwable.class)
|
|
|
+ public static void onExit(@Advice.Enter boolean previousValue) {
|
|
|
+ SpringSchedulingTaskTracing.setEnabled(previousValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|