Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
amarziali committed Nov 27, 2024
1 parent 735e827 commit d57ed80
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 83 deletions.
2 changes: 1 addition & 1 deletion dd-java-agent/instrumentation/mule-4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> contextStore() {
final Map<String, String> 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",
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> 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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
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
* the system. We attach the active span to the concrete implementation of the {@code EventContext}
* 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[] {
Expand All @@ -34,18 +23,6 @@ public String[] knownMatchingTypes() {
};
}

@Override
public Map<String, String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> contextStore() {
final Map<String, String> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit d57ed80

Please sign in to comment.