Skip to content

Commit

Permalink
muzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
amarziali committed Jan 13, 2025
1 parent 8c76abb commit a853a04
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
5 changes: 1 addition & 4 deletions dd-java-agent/instrumentation/mule-4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ tasks.named("compileLatestDepForkedTestJava").configure {
dependencies {
compileOnly group: 'org.mule.runtime', name: 'mule-core', version: muleVersion
compileOnly group: 'org.mule.runtime', name: 'mule-tracer-customization-impl', version: muleVersion
main_java11CompileOnly project(':internal-api')
main_java11CompileOnly project(':dd-java-agent:agent-tooling')
main_java11CompileOnly project(':dd-java-agent:agent-bootstrap')
main_java11CompileOnly sourceSets.main.output
compileOnly sourceSets.main_java11.output
testImplementation project(':dd-java-agent:instrumentation:aws-common')
testImplementation project(':dd-java-agent:instrumentation:reactor-core-3.1')
testImplementation project(':dd-java-agent:instrumentation:reactive-streams')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.agent.tooling.InstrumenterModule;
import datadog.trace.api.Platform;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.implementation.bytecode.assign.Assigner;
import org.mule.runtime.tracer.api.EventTracer;

@AutoService(InstrumenterModule.class)
public class JpmsMuleInstrumentation extends InstrumenterModule.Tracing
Expand Down Expand Up @@ -38,6 +41,18 @@ public String[] helperClassNames() {
@Override
public void methodAdvice(MethodTransformer transformer) {
// it does not work with typeInitializer()
transformer.applyAdvice(isConstructor(), packageName + ".JpmsClearanceAdvice");
transformer.applyAdvice(isConstructor(), packageName + "$JpmsClearanceAdvice");
}

public static class JpmsClearanceAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openOnReturn(@Advice.This(typing = Assigner.Typing.DYNAMIC) Object self) {
JpmsAdvisingHelper.allowAccessOnModuleClass(self.getClass());
}

private static void muzzleCheck(final EventTracer<?> tracer) {
// introduced in 4.5.0
tracer.endCurrentSpan(null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
public class JpmsAdvisingHelper {
private static final WeakHashMap<Module, Boolean> ALREADY_PROCESSED_CACHE = new WeakHashMap<>();

public static boolean isModuleAlreadyProcessed(final Module module) {
return Boolean.TRUE.equals(ALREADY_PROCESSED_CACHE.putIfAbsent(module, Boolean.TRUE));
public static void allowAccessOnModuleClass(final Class<?> cls) {
final Module module = cls.getModule();
if (module == null
|| Boolean.TRUE.equals(ALREADY_PROCESSED_CACHE.putIfAbsent(module, Boolean.TRUE))) {
return;
}
for (String pn : module.getPackages()) {
try {
module.addExports(pn, module.getClassLoader().getUnnamedModule());
} catch (Throwable ignored) {
}
}
}

private JpmsAdvisingHelper() {}
Expand Down

This file was deleted.

0 comments on commit a853a04

Please sign in to comment.