File tree Expand file tree Collapse file tree 4 files changed +43
-32
lines changed
dd-java-agent/instrumentation/mule-4
java11/datadog/trace/instrumentation/mule4
java/datadog/trace/instrumentation/mule4 Expand file tree Collapse file tree 4 files changed +43
-32
lines changed Original file line number Diff line number Diff line change @@ -139,8 +139,13 @@ dependencies {
139139 compileOnly group : ' org.mule.runtime' , name : ' mule-core' , version : muleVersion
140140 compileOnly group : ' org.mule.runtime' , name : ' mule-tracer-customization-impl' , version : muleVersion
141141 compileOnly sourceSets. main_java11. output
142- testImplementation sourceSets. main_java11. output
143142
143+ main_java11CompileOnly project(' :internal-api' )
144+ main_java11CompileOnly project(' :dd-java-agent:agent-tooling' )
145+ main_java11CompileOnly project(' :dd-java-agent:agent-bootstrap' )
146+ main_java11CompileOnly group : ' org.mule.runtime' , name : ' mule-core' , version : muleVersion
147+
148+ testImplementation sourceSets. main_java11. output
144149 testImplementation project(' :dd-java-agent:instrumentation:aws-common' )
145150 testImplementation project(' :dd-java-agent:instrumentation:reactor-core-3.1' )
146151 testImplementation project(' :dd-java-agent:instrumentation:reactive-streams' )
Original file line number Diff line number Diff line change 66import datadog .trace .agent .tooling .Instrumenter ;
77import datadog .trace .agent .tooling .InstrumenterModule ;
88import datadog .trace .api .Platform ;
9- import net .bytebuddy .asm .Advice ;
10- import net .bytebuddy .implementation .bytecode .assign .Assigner ;
11- import org .mule .runtime .tracer .api .EventTracer ;
129
1310@ AutoService (InstrumenterModule .class )
1411public class JpmsMuleInstrumentation extends InstrumenterModule .Tracing
@@ -41,18 +38,6 @@ public String[] helperClassNames() {
4138 @ Override
4239 public void methodAdvice (MethodTransformer transformer ) {
4340 // it does not work with typeInitializer()
44- transformer .applyAdvice (isConstructor (), getClass ().getName () + "$JpmsClearanceAdvice" );
45- }
46-
47- public static class JpmsClearanceAdvice {
48- @ Advice .OnMethodExit (suppress = Throwable .class )
49- public static void openOnReturn (@ Advice .This (typing = Assigner .Typing .DYNAMIC ) Object self ) {
50- JpmsAdvisingHelper .allowAccessOnModuleClass (self .getClass ());
51- }
52-
53- private static void muzzleCheck (final EventTracer <?> tracer ) {
54- // introduced in 4.5.0
55- tracer .endCurrentSpan (null );
56- }
41+ transformer .applyAdvice (isConstructor (), packageName + ".JpmsClearanceAdvice" );
5742 }
5843}
Original file line number Diff line number Diff line change 11package datadog .trace .instrumentation .mule4 ;
22
3- import java .util .WeakHashMap ;
3+ import datadog .trace .api .GenericClassValue ;
4+ import java .util .concurrent .atomic .AtomicBoolean ;
45
56public class JpmsAdvisingHelper {
6- private static final WeakHashMap <Class <?>, Boolean > ALREADY_PROCESSED_CACHE = new WeakHashMap <>();
7-
8- public static void allowAccessOnModuleClass (final Class <?> cls ) {
9- if (Boolean .TRUE .equals (ALREADY_PROCESSED_CACHE .putIfAbsent (cls , Boolean .TRUE ))) {
10- return ;
11- }
12- final Module module = cls .getModule ();
13- if (module != null ) {
14- try {
15- module .addExports (cls .getPackageName (), module .getClassLoader ().getUnnamedModule ());
16- } catch (Throwable ignored ) {
17- }
18- }
19- }
7+ public static final ClassValue <AtomicBoolean > ALREADY_PROCESSED_CACHE =
8+ GenericClassValue .constructing (AtomicBoolean .class );
209
2110 private JpmsAdvisingHelper () {}
2211}
Original file line number Diff line number Diff line change 1+ package datadog .trace .instrumentation .mule4 ;
2+
3+ import static datadog .trace .instrumentation .mule4 .JpmsAdvisingHelper .ALREADY_PROCESSED_CACHE ;
4+
5+ import net .bytebuddy .asm .Advice ;
6+ import net .bytebuddy .implementation .bytecode .assign .Assigner ;
7+ import org .mule .runtime .tracer .api .EventTracer ;
8+
9+ public class JpmsClearanceAdvice {
10+ @ Advice .OnMethodExit (suppress = Throwable .class )
11+ public static void openOnReturn (@ Advice .This (typing = Assigner .Typing .DYNAMIC ) Object self ) {
12+ final Class <?> cls = self .getClass ();
13+ if (ALREADY_PROCESSED_CACHE .get (cls ).compareAndSet (false , true )) {
14+ final Module module = cls .getModule ();
15+ if (module != null ) {
16+ try {
17+ // This call needs imperatively to be done from the same module we're adding exports
18+ // because the jdk is checking that the caller belongs to the same module.
19+ // The code of this advice is getting inlined into the constructor of the class belonging
20+ // to that package so it will work. Moving the same to a helper won't.
21+ module .addExports (cls .getPackageName (), module .getClassLoader ().getUnnamedModule ());
22+ } catch (Throwable ignored ) {
23+ }
24+ }
25+ }
26+ }
27+
28+ private static void muzzleCheck (final EventTracer <?> tracer ) {
29+ // introduced in 4.5.0
30+ tracer .endCurrentSpan (null );
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments