Skip to content

Commit 6e420d4

Browse files
committed
(chore) make indy compatible
1 parent 2ab2ad3 commit 6e420d4

File tree

5 files changed

+72
-49
lines changed

5 files changed

+72
-49
lines changed

instrumentation/ratpack/ratpack-1.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/v1_7/DefaultExecControllerInstrumentation.java

+33-26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1616
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1717
import net.bytebuddy.asm.Advice;
18+
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
19+
import net.bytebuddy.asm.Advice.AssignReturned.ToFields.ToField;
1820
import net.bytebuddy.description.type.TypeDescription;
1921
import net.bytebuddy.matcher.ElementMatcher;
2022
import ratpack.exec.ExecInitializer;
@@ -44,43 +46,48 @@ public void transform(TypeTransformer transformer) {
4446
DefaultExecControllerInstrumentation.class.getName() + "$ConstructorAdvice");
4547
}
4648

49+
@SuppressWarnings("unused")
4750
public static class SetInitializersAdvice {
48-
@Advice.OnMethodEnter(suppress = Throwable.class)
49-
public static void enter(
50-
@Advice.Argument(value = 0, readOnly = false)
51-
ImmutableList<? extends ExecInitializer> initializers) {
52-
initializers =
53-
ImmutableList.<ExecInitializer>builder()
54-
.addAll(initializers)
55-
.add(OpenTelemetryExecInitializer.INSTANCE)
56-
.build();
51+
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
52+
@Advice.AssignReturned.ToArguments(@ToArgument(0))
53+
public static ImmutableList<? extends ExecInitializer> enter(
54+
@Advice.Argument(0) ImmutableList<? extends ExecInitializer> initializers) {
55+
return ImmutableList.<ExecInitializer>builder()
56+
.addAll(initializers)
57+
.add(OpenTelemetryExecInitializer.INSTANCE)
58+
.build();
5759
}
5860
}
5961

62+
@SuppressWarnings("unused")
6063
public static class SetInterceptorsAdvice {
61-
@Advice.OnMethodEnter(suppress = Throwable.class)
62-
public static void enter(
63-
@Advice.Argument(value = 0, readOnly = false)
64-
ImmutableList<? extends ExecInterceptor> interceptors) {
65-
interceptors =
66-
ImmutableList.<ExecInterceptor>builder()
67-
.addAll(interceptors)
68-
.add(OpenTelemetryExecInterceptor.INSTANCE)
69-
.build();
64+
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
65+
@Advice.AssignReturned.ToArguments(@ToArgument(0))
66+
public static ImmutableList<? extends ExecInterceptor> enter(
67+
@Advice.Argument(0) ImmutableList<? extends ExecInterceptor> interceptors) {
68+
return ImmutableList.<ExecInterceptor>builder()
69+
.addAll(interceptors)
70+
.add(OpenTelemetryExecInterceptor.INSTANCE)
71+
.build();
7072
}
7173
}
7274

75+
@SuppressWarnings("unused")
7376
public static class ConstructorAdvice {
7477

7578
@SuppressWarnings("UnusedVariable")
76-
@Advice.OnMethodExit(suppress = Throwable.class)
77-
public static void exit(
78-
@Advice.FieldValue(value = "initializers", readOnly = false)
79-
ImmutableList<? extends ExecInitializer> initializers,
80-
@Advice.FieldValue(value = "interceptors", readOnly = false)
81-
ImmutableList<? extends ExecInterceptor> interceptors) {
82-
initializers = ImmutableList.of(OpenTelemetryExecInitializer.INSTANCE);
83-
interceptors = ImmutableList.of(OpenTelemetryExecInterceptor.INSTANCE);
79+
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
80+
@Advice.AssignReturned.ToFields({
81+
@ToField(value = "initializers", index = 0),
82+
@ToField(value = "interceptors", index = 1)
83+
})
84+
public static Object[] exit(
85+
@Advice.FieldValue("initializers") ImmutableList<? extends ExecInitializer> initializers,
86+
@Advice.FieldValue("interceptors") ImmutableList<? extends ExecInterceptor> interceptors) {
87+
return new Object[] {
88+
ImmutableList.of(OpenTelemetryExecInitializer.INSTANCE),
89+
ImmutableList.of(OpenTelemetryExecInterceptor.INSTANCE)
90+
};
8491
}
8592
}
8693
}

instrumentation/ratpack/ratpack-1.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/v1_7/HttpClientInstrumentation.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public void transform(TypeTransformer transformer) {
3737
@SuppressWarnings("unused")
3838
public static class OfAdvice {
3939

40-
@Advice.OnMethodExit(suppress = Throwable.class)
41-
public static void injectTracing(@Advice.Return(readOnly = false) HttpClient httpClient)
42-
throws Exception {
43-
httpClient = RatpackSingletons.telemetry().instrumentHttpClient(httpClient);
40+
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
41+
@Advice.AssignReturned.ToReturned
42+
public static HttpClient injectTracing(@Advice.Return HttpClient httpClient) throws Exception {
43+
return RatpackSingletons.telemetry().instrumentHttpClient(httpClient);
4444
}
4545
}
4646
}

instrumentation/ratpack/ratpack-1.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/v1_7/RatpackInstrumentationModule.java

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public String getModuleGroup() {
2828
return "netty";
2929
}
3030

31+
@Override
32+
public boolean isIndyModule() {
33+
return true;
34+
}
35+
3136
@Override
3237
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
3338
// Only activate when running ratpack 1.7 or later

instrumentation/ratpack/ratpack-1.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/v1_7/RequestActionSupportInstrumentation.java

+23-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1919
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2020
import net.bytebuddy.asm.Advice;
21+
import net.bytebuddy.asm.Advice.AssignReturned.ToArguments.ToArgument;
2122
import net.bytebuddy.description.type.TypeDescription;
2223
import net.bytebuddy.matcher.ElementMatcher;
2324
import ratpack.exec.Downstream;
@@ -41,30 +42,40 @@ public void transform(TypeTransformer transformer) {
4142
RequestActionSupportInstrumentation.class.getName() + "$SendAdvice");
4243
transformer.applyAdviceToMethod(
4344
isMethod().and(named("connect")).and(takesArgument(0, named("ratpack.exec.Downstream"))),
44-
RequestActionSupportInstrumentation.class.getName() + "$ConnectAdvice");
45+
RequestActionSupportInstrumentation.class.getName() + "$ConnectDownstreamAdvice");
46+
transformer.applyAdviceToMethod(
47+
isMethod().and(named("connect")).and(takesArgument(0, named("ratpack.exec.Downstream"))),
48+
RequestActionSupportInstrumentation.class.getName() + "$ContextAdvice");
4549
}
4650

4751
@SuppressWarnings("unused")
4852
public static class SendAdvice {
4953

5054
@Advice.OnMethodEnter(suppress = Throwable.class)
5155
public static void injectChannelAttribute(
52-
@Advice.FieldValue("execution") Execution execution,
53-
@Advice.Argument(value = 0, readOnly = false) Downstream<?> downstream,
54-
@Advice.Argument(value = 1, readOnly = false) Channel channel) {
56+
@Advice.FieldValue("execution") Execution execution, @Advice.Argument(1) Channel channel) {
5557
RatpackSingletons.propagateContextToChannel(execution, channel);
5658
}
5759
}
5860

59-
public static class ConnectAdvice {
61+
@SuppressWarnings("unused")
62+
public static class ConnectDownstreamAdvice {
6063

61-
@Advice.OnMethodEnter(suppress = Throwable.class)
62-
public static Scope injectChannelAttribute(
63-
@Advice.FieldValue("execution") Execution execution,
64-
@Advice.Argument(value = 0, readOnly = false) Downstream<?> downstream) {
64+
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
65+
@Advice.AssignReturned.ToArguments(@ToArgument(0))
66+
public static Object wrapDownstream(@Advice.Argument(0) Downstream<?> downstream) {
6567
// Propagate the current context to downstream
66-
// since that the is the subsequent
67-
downstream = DownstreamWrapper.wrapIfNeeded(downstream);
68+
// since that is the subsequent code chained to the http client call
69+
return DownstreamWrapper.wrapIfNeeded(downstream);
70+
}
71+
}
72+
73+
@SuppressWarnings("unused")
74+
public static class ContextAdvice {
75+
76+
@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
77+
public static Scope injectChannelAttribute(
78+
@Advice.FieldValue("execution") Execution execution) {
6879

6980
// Capture the CLIENT span and make it current before cally Netty layer
7081
return execution
@@ -74,7 +85,7 @@ public static Scope injectChannelAttribute(
7485
.orElse(null);
7586
}
7687

77-
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
88+
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
7889
public static void exit(@Advice.Enter Scope scope) {
7990
if (scope != null) {
8091
scope.close();

instrumentation/ratpack/ratpack-1.7/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/ratpack/v1_7/ServerRegistryInstrumentation.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public void transform(TypeTransformer transformer) {
3434
@SuppressWarnings("unused")
3535
public static class BuildAdvice {
3636

37-
@Advice.OnMethodExit(suppress = Throwable.class)
38-
public static void injectTracing(@Advice.Return(readOnly = false) Registry registry) {
39-
registry =
40-
registry.join(
41-
Registry.single(
42-
HandlerDecorator.prepend(
43-
RatpackSingletons.telemetry().getOpenTelemetryServerHandler())));
37+
@Advice.OnMethodExit(suppress = Throwable.class, inline = false)
38+
@Advice.AssignReturned.ToReturned
39+
public static Registry injectTracing(@Advice.Return Registry registry) {
40+
return registry.join(
41+
Registry.single(
42+
HandlerDecorator.prepend(
43+
RatpackSingletons.telemetry().getOpenTelemetryServerHandler())));
4444
}
4545
}
4646
}

0 commit comments

Comments
 (0)