Skip to content

Commit e33ba87

Browse files
committed
make gwt indy-ready
1 parent 94b2fb4 commit e33ba87

File tree

2 files changed

+44
-17
lines changed

2 files changed

+44
-17
lines changed

instrumentation/gwt-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/gwt/GwtInstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import com.google.auto.service.AutoService;
1212
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1313
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1415
import java.util.List;
1516
import net.bytebuddy.matcher.ElementMatcher;
1617

1718
@AutoService(InstrumentationModule.class)
18-
public class GwtInstrumentationModule extends InstrumentationModule {
19+
public class GwtInstrumentationModule extends InstrumentationModule
20+
implements ExperimentalInstrumentationModule {
1921

2022
public GwtInstrumentationModule() {
2123
super("gwt", "gwt-2.0");
@@ -31,4 +33,9 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
3133
public List<TypeInstrumentation> typeInstrumentations() {
3234
return singletonList(new GwtRpcInstrumentation());
3335
}
36+
37+
@Override
38+
public boolean isIndyReady() {
39+
return true;
40+
}
3441
}

instrumentation/gwt-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/gwt/GwtRpcInstrumentation.java

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1717
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1818
import java.lang.reflect.Method;
19+
import javax.annotation.Nullable;
1920
import net.bytebuddy.asm.Advice;
2021
import net.bytebuddy.description.type.TypeDescription;
2122
import net.bytebuddy.matcher.ElementMatcher;
@@ -53,35 +54,54 @@ public void transform(TypeTransformer transformer) {
5354
@SuppressWarnings("unused")
5455
public static class InvokeAndEncodeResponseAdvice {
5556

57+
public static class AdviceScope {
58+
private final Context context;
59+
private final Scope scope;
60+
61+
private AdviceScope(Context context, Scope scope) {
62+
this.context = context;
63+
this.scope = scope;
64+
}
65+
66+
@Nullable
67+
public static AdviceScope start(Method method) {
68+
Context parentContext = Context.current();
69+
if (!instrumenter().shouldStart(parentContext, method)) {
70+
return null;
71+
}
72+
Context context =
73+
instrumenter().start(parentContext, method).with(GwtSingletons.RPC_CONTEXT_KEY, true);
74+
return new AdviceScope(context, context.makeCurrent());
75+
}
76+
77+
public void end(Method method, @Nullable Throwable throwable) {
78+
scope.close();
79+
instrumenter().end(context, method, null, throwable);
80+
}
81+
}
82+
83+
@Nullable
5684
@Advice.OnMethodEnter(suppress = Throwable.class)
57-
public static void onEnter(
58-
@Advice.Argument(1) Method method,
59-
@Advice.Local("otelContext") Context context,
60-
@Advice.Local("otelScope") Scope scope) {
61-
context =
62-
instrumenter()
63-
.start(Java8BytecodeBridge.currentContext(), method)
64-
.with(GwtSingletons.RPC_CONTEXT_KEY, true);
65-
scope = context.makeCurrent();
85+
public static AdviceScope onEnter(@Advice.Argument(1) Method method) {
86+
return AdviceScope.start(method);
6687
}
6788

6889
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
6990
public static void onExit(
7091
@Advice.Argument(1) Method method,
71-
@Advice.Local("otelContext") Context context,
72-
@Advice.Local("otelScope") Scope scope,
73-
@Advice.Thrown Throwable throwable) {
74-
scope.close();
75-
76-
instrumenter().end(context, method, null, throwable);
92+
@Advice.Thrown @Nullable Throwable throwable,
93+
@Advice.Enter @Nullable AdviceScope adviceScope) {
94+
if (adviceScope != null) {
95+
adviceScope.end(method, throwable);
96+
}
7797
}
7898
}
7999

80100
@SuppressWarnings("unused")
81101
public static class EncodeResponseForFailureAdvice {
82102

83103
@Advice.OnMethodEnter(suppress = Throwable.class)
84-
public static void onEnter(@Advice.Argument(1) Throwable throwable) {
104+
public static void onEnter(@Advice.Argument(1) @Nullable Throwable throwable) {
85105
if (throwable == null) {
86106
return;
87107
}

0 commit comments

Comments
 (0)