Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class GwtInstrumentationModule extends InstrumentationModule {
public class GwtInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

public GwtInstrumentationModule() {
super("gwt", "gwt-2.0");
Expand All @@ -31,4 +33,9 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new GwtRpcInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import java.lang.reflect.Method;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
Expand Down Expand Up @@ -53,35 +54,54 @@ public void transform(TypeTransformer transformer) {
@SuppressWarnings("unused")
public static class InvokeAndEncodeResponseAdvice {

public static class AdviceScope {
private final Context context;
private final Scope scope;

private AdviceScope(Context context, Scope scope) {
this.context = context;
this.scope = scope;
}

@Nullable
public static AdviceScope start(Method method) {
Context parentContext = Context.current();
if (!instrumenter().shouldStart(parentContext, method)) {
return null;
}
Context context =
instrumenter().start(parentContext, method).with(GwtSingletons.RPC_CONTEXT_KEY, true);
return new AdviceScope(context, context.makeCurrent());
}

public void end(Method method, @Nullable Throwable throwable) {
scope.close();
instrumenter().end(context, method, null, throwable);
}
}

@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(
@Advice.Argument(1) Method method,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
context =
instrumenter()
.start(Java8BytecodeBridge.currentContext(), method)
.with(GwtSingletons.RPC_CONTEXT_KEY, true);
scope = context.makeCurrent();
public static AdviceScope onEnter(@Advice.Argument(1) Method method) {
return AdviceScope.start(method);
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onExit(
@Advice.Argument(1) Method method,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope,
@Advice.Thrown Throwable throwable) {
scope.close();

instrumenter().end(context, method, null, throwable);
@Advice.Thrown @Nullable Throwable throwable,
@Advice.Enter @Nullable AdviceScope adviceScope) {
if (adviceScope != null) {
adviceScope.end(method, throwable);
}
}
}

@SuppressWarnings("unused")
public static class EncodeResponseForFailureAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter(@Advice.Argument(1) Throwable throwable) {
public static void onEnter(@Advice.Argument(1) @Nullable Throwable throwable) {
if (throwable == null) {
return;
}
Expand Down
Loading