make ratpack indy-ready (#14679)

This commit is contained in:
SylvainJuge 2025-09-18 14:02:46 +02:00 committed by GitHub
parent 2caff625dd
commit 626c296066
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 60 additions and 22 deletions

View File

@ -14,6 +14,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import ratpack.func.Block;
@ -41,9 +43,10 @@ public class ContinuationInstrumentation implements TypeInstrumentation {
@SuppressWarnings("unused")
public static class ResumeAdvice {
@AssignReturned.ToArguments(@ToArgument(0))
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void wrap(@Advice.Argument(value = 0, readOnly = false) Block block) {
block = BlockWrapper.wrapIfNeeded(block);
public static Block wrap(@Advice.Argument(0) Block block) {
return BlockWrapper.wrapIfNeeded(block);
}
}
}

View File

@ -14,6 +14,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import ratpack.func.Block;
@ -40,9 +42,10 @@ public class ContinuationStreamInstrumentation implements TypeInstrumentation {
@SuppressWarnings("unused")
public static class WrapBlockAdvice {
@AssignReturned.ToArguments(@ToArgument(0))
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void wrap(@Advice.Argument(value = 0, readOnly = false) Block block) {
block = BlockWrapper.wrapIfNeeded(block);
public static Block wrap(@Advice.Argument(0) Block block) {
return BlockWrapper.wrapIfNeeded(block);
}
}
}

View File

@ -16,6 +16,8 @@ import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import ratpack.func.Action;
@ -41,22 +43,31 @@ public class DefaultExecStarterInstrumentation implements TypeInstrumentation {
@SuppressWarnings("unused")
public static class WrapActionAdvice {
@AssignReturned.ToArguments(@ToArgument(0))
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void wrapAction(@Advice.Argument(value = 0, readOnly = false) Action<?> action) {
action = ActionWrapper.wrapIfNeeded(action);
public static Action<?> wrapAction(@Advice.Argument(0) Action<?> action) {
return ActionWrapper.wrapIfNeeded(action);
}
}
@SuppressWarnings("unused")
public static class StartAdvice {
@AssignReturned.ToArguments(@ToArgument(value = 0, index = 1))
@Advice.OnMethodEnter(suppress = Throwable.class)
public static Scope enter(@Advice.Argument(value = 0, readOnly = false) Action<?> action) {
action = ActionWrapper.wrapIfNeeded(action);
return Java8BytecodeBridge.rootContext().makeCurrent();
public static Object[] enter(@Advice.Argument(0) Action<?> action) {
// wrapping method is relying on current context
// thus we must wrap first to avoid using the root context
Action<?> wrappedAction = ActionWrapper.wrapIfNeeded(action);
// root context scope must be made current after wrapping
Scope scope = Java8BytecodeBridge.rootContext().makeCurrent();
return new Object[] {scope, wrappedAction};
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void exit(@Advice.Enter Scope scope) {
public static void exit(@Advice.Enter Object[] enterResult) {
Scope scope = (Scope) enterResult[0];
if (scope != null) {
scope.close();
}

View File

@ -12,6 +12,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import ratpack.exec.internal.Continuation;
@ -36,12 +38,18 @@ public class DefaultExecutionInstrumentation implements TypeInstrumentation {
@SuppressWarnings("unused")
public static class DelimitAdvice {
@AssignReturned.ToArguments({
@ToArgument(value = 0, index = 0),
@ToArgument(value = 1, index = 1)
})
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void wrap(
@Advice.Argument(value = 0, readOnly = false) Action<? super Throwable> onError,
@Advice.Argument(value = 1, readOnly = false) Action<? super Continuation> segment) {
onError = ActionWrapper.wrapIfNeeded(onError);
segment = ActionWrapper.wrapIfNeeded(segment);
public static Object[] wrap(
@Advice.Argument(0) Action<? super Throwable> originalOnError,
@Advice.Argument(1) Action<? super Continuation> originalSegment) {
Action<? super Throwable> onError = ActionWrapper.wrapIfNeeded(originalOnError);
Action<? super Continuation> segment = ActionWrapper.wrapIfNeeded(originalSegment);
return new Object[] {onError, segment};
}
}
}

View File

@ -13,6 +13,8 @@ import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.reactivestreams.Subscriber;
@ -36,10 +38,10 @@ public class ExecutionBoundPublisherInstrumentation implements TypeInstrumentati
@SuppressWarnings("unused")
public static class SubscribeAdvice {
@AssignReturned.ToArguments(@ToArgument(0))
@Advice.OnMethodEnter(suppress = Throwable.class)
public static <T> void wrap(
@Advice.Argument(value = 0, readOnly = false) Subscriber<T> subscriber) {
subscriber = new TracingSubscriber<>(subscriber, Java8BytecodeBridge.currentContext());
public static <T> Subscriber<T> wrap(@Advice.Argument(0) Subscriber<T> subscriber) {
return new TracingSubscriber<>(subscriber, Java8BytecodeBridge.currentContext());
}
}
}

View File

@ -37,4 +37,9 @@ public class RatpackInstrumentationModule extends InstrumentationModule
new ServerErrorHandlerInstrumentation(),
new ServerRegistryInstrumentation());
}
@Override
public boolean isIndyReady() {
return true;
}
}

View File

@ -12,6 +12,7 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import ratpack.handling.HandlerDecorator;
@ -34,11 +35,11 @@ public class ServerRegistryInstrumentation implements TypeInstrumentation {
@SuppressWarnings("unused")
public static class BuildAdvice {
@AssignReturned.ToReturned
@Advice.OnMethodExit(suppress = Throwable.class)
public static void injectTracing(@Advice.Return(readOnly = false) Registry registry) {
registry =
registry.join(
Registry.builder().add(HandlerDecorator.prepend(TracingHandler.INSTANCE)).build());
public static Registry injectTracing(@Advice.Return Registry registry) {
return registry.join(
Registry.builder().add(HandlerDecorator.prepend(TracingHandler.INSTANCE)).build());
}
}
}

View File

@ -41,4 +41,9 @@ public class RatpackInstrumentationModule extends InstrumentationModule
new HttpClientInstrumentation(),
new RequestActionSupportInstrumentation());
}
@Override
public boolean isIndyReady() {
return true;
}
}