From d57ed80d5d820d6b0fec7fd753a6a821b1af6fe1 Mon Sep 17 00:00:00 2001 From: Andrea Marziali Date: Tue, 26 Nov 2024 11:52:10 +0100 Subject: [PATCH] Refactor --- .../instrumentation/mule-4/build.gradle | 2 +- .../mule4/AbstractMuleInstrumentation.java | 36 +++++++++++++++++++ .../ComponentMessageInstrumentation.java | 30 ++-------------- .../mule4/EventContextInstrumentation.java | 25 +------------ .../mule4/EventTracerInstrumentation.java | 32 +---------------- ...ecutionInitialSpanInfoInstrumentation.java | 5 +++ 6 files changed, 47 insertions(+), 83 deletions(-) create mode 100644 dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/AbstractMuleInstrumentation.java diff --git a/dd-java-agent/instrumentation/mule-4/build.gradle b/dd-java-agent/instrumentation/mule-4/build.gradle index 8eb275f9a62d..3d65328e32c8 100644 --- a/dd-java-agent/instrumentation/mule-4/build.gradle +++ b/dd-java-agent/instrumentation/mule-4/build.gradle @@ -33,6 +33,7 @@ muzzle { assertInverse true javaVersion = "17" excludeDependency 'com.google.code.findbugs:jsr305' + additionalDependencies +="org.mule.runtime:mule-tracer-customization-impl:4.5.0" } } @@ -69,7 +70,6 @@ configurations { } configurations.all { - // WHY this is in the CI classpath and not locally? exclude group: 'pull-parser', module: 'pull-parser' resolutionStrategy { diff --git a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/AbstractMuleInstrumentation.java b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/AbstractMuleInstrumentation.java new file mode 100644 index 000000000000..be26ff448b17 --- /dev/null +++ b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/AbstractMuleInstrumentation.java @@ -0,0 +1,36 @@ +package datadog.trace.instrumentation.mule4; + +import datadog.trace.agent.tooling.InstrumenterModule; +import java.util.HashMap; +import java.util.Map; + +public abstract class AbstractMuleInstrumentation extends InstrumenterModule.Tracing { + public AbstractMuleInstrumentation() { + super("mule"); + } + + @Override + protected boolean defaultEnabled() { + return false; + } + + @Override + public Map contextStore() { + final Map contextStore = new HashMap<>(); + contextStore.put("org.mule.runtime.api.event.EventContext", packageName + ".SpanState"); + contextStore.put( + "org.mule.runtime.tracer.api.span.info.InitialSpanInfo", + "org.mule.runtime.api.component.Component"); + return contextStore; + } + + @Override + public String[] helperClassNames() { + return new String[] { + packageName + ".MuleDecorator", + packageName + ".DDEventTracer", + packageName + ".SpanState", + packageName + ".NoopMuleSpan", + }; + } +} diff --git a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/ComponentMessageInstrumentation.java b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/ComponentMessageInstrumentation.java index 34501bda3a76..81af01078394 100644 --- a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/ComponentMessageInstrumentation.java +++ b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/ComponentMessageInstrumentation.java @@ -7,8 +7,6 @@ import datadog.trace.bootstrap.InstrumentationContext; import datadog.trace.bootstrap.instrumentation.api.AgentScope; import datadog.trace.bootstrap.instrumentation.api.AgentTracer; -import java.util.Collections; -import java.util.Map; import net.bytebuddy.asm.Advice; import net.bytebuddy.matcher.ElementMatchers; import org.mule.runtime.api.event.EventContext; @@ -20,29 +18,12 @@ * handler. */ @AutoService(InstrumenterModule.class) -public class ComponentMessageInstrumentation extends InstrumenterModule.Tracing +public class ComponentMessageInstrumentation extends AbstractMuleInstrumentation implements Instrumenter.ForSingleType { - public ComponentMessageInstrumentation() { - super("mule"); - } - - @Override - protected boolean defaultEnabled() { - return false; - } - - @Override - public Map contextStore() { - return Collections.singletonMap( - "org.mule.runtime.api.event.EventContext", packageName + ".SpanState"); - } - @Override - public String[] helperClassNames() { - return new String[] { - packageName + ".SpanState", - }; + public String instrumentedType() { + return "org.mule.runtime.module.extension.internal.runtime.operation.ComponentMessageProcessor"; } @Override @@ -56,11 +37,6 @@ public void methodAdvice(MethodTransformer transformer) { getClass().getName() + "$ProcessAdvice"); } - @Override - public String instrumentedType() { - return "org.mule.runtime.module.extension.internal.runtime.operation.ComponentMessageProcessor"; - } - public static class ProcessAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static AgentScope before(@Advice.Argument(0) final CoreEvent event) { diff --git a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/EventContextInstrumentation.java b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/EventContextInstrumentation.java index d79c16371631..bcc465d19cc1 100644 --- a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/EventContextInstrumentation.java +++ b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/EventContextInstrumentation.java @@ -1,12 +1,10 @@ package datadog.trace.instrumentation.mule4; -import static java.util.Collections.singletonMap; import static net.bytebuddy.matcher.ElementMatchers.isConstructor; import com.google.auto.service.AutoService; import datadog.trace.agent.tooling.Instrumenter; import datadog.trace.agent.tooling.InstrumenterModule; -import java.util.Map; /** * Events in Mule have an {@code EventContext} attached to them, that travels with the event through @@ -14,18 +12,9 @@ * and activate/deactivate the span when mule changes which event it is processing. */ @AutoService(InstrumenterModule.class) -public final class EventContextInstrumentation extends InstrumenterModule.Tracing +public final class EventContextInstrumentation extends AbstractMuleInstrumentation implements Instrumenter.ForKnownTypes { - public EventContextInstrumentation() { - super("mule"); - } - - @Override - protected boolean defaultEnabled() { - return false; - } - @Override public String[] knownMatchingTypes() { return new String[] { @@ -34,18 +23,6 @@ public String[] knownMatchingTypes() { }; } - @Override - public Map contextStore() { - return singletonMap("org.mule.runtime.api.event.EventContext", packageName + ".SpanState"); - } - - @Override - public String[] helperClassNames() { - return new String[] { - packageName + ".SpanState", - }; - } - @Override public void methodAdvice(MethodTransformer transformer) { transformer.applyAdvice(isConstructor(), packageName + ".EventContextCreationAdvice"); diff --git a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/EventTracerInstrumentation.java b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/EventTracerInstrumentation.java index 0f1d9b8ae990..82069ff2d749 100644 --- a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/EventTracerInstrumentation.java +++ b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/EventTracerInstrumentation.java @@ -5,8 +5,6 @@ import datadog.trace.agent.tooling.InstrumenterModule; import datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers; import datadog.trace.bootstrap.InstrumentationContext; -import java.util.HashMap; -import java.util.Map; import net.bytebuddy.asm.Advice; import org.mule.runtime.api.component.Component; import org.mule.runtime.api.event.EventContext; @@ -15,36 +13,8 @@ import org.mule.runtime.tracer.api.span.info.InitialSpanInfo; @AutoService(InstrumenterModule.class) -public class EventTracerInstrumentation extends InstrumenterModule.Tracing +public class EventTracerInstrumentation extends AbstractMuleInstrumentation implements Instrumenter.ForSingleType { - public EventTracerInstrumentation() { - super("mule"); - } - - @Override - protected boolean defaultEnabled() { - return false; - } - - @Override - public Map contextStore() { - final Map contextStore = new HashMap<>(); - contextStore.put("org.mule.runtime.api.event.EventContext", packageName + ".SpanState"); - contextStore.put( - "org.mule.runtime.tracer.api.span.info.InitialSpanInfo", - "org.mule.runtime.api.component.Component"); - return contextStore; - } - - @Override - public String[] helperClassNames() { - return new String[] { - packageName + ".MuleDecorator", - packageName + ".DDEventTracer", - packageName + ".SpanState", - packageName + ".NoopMuleSpan", - }; - } @Override public String instrumentedType() { diff --git a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/ExecutionInitialSpanInfoInstrumentation.java b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/ExecutionInitialSpanInfoInstrumentation.java index d775a59c21a2..debf205b17f9 100644 --- a/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/ExecutionInitialSpanInfoInstrumentation.java +++ b/dd-java-agent/instrumentation/mule-4/src/main/java/datadog/trace/instrumentation/mule4/ExecutionInitialSpanInfoInstrumentation.java @@ -22,6 +22,11 @@ public ExecutionInitialSpanInfoInstrumentation() { super("mule"); } + @Override + protected boolean defaultEnabled() { + return false; + } + @Override public String instrumentedType() { return "org.mule.runtime.tracer.customization.impl.info.ExecutionInitialSpanInfo";