-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add agent instrumentation for Ratpack 1.7+ (#12572)
- Loading branch information
1 parent
11773aa
commit 8a3f1eb
Showing
36 changed files
with
831 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
instrumentation/ratpack/ratpack-1.7/javaagent/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("io.ratpack") | ||
module.set("ratpack-core") | ||
versions.set("[1.7.0,)") | ||
} | ||
fail { | ||
group.set("io.ratpack") | ||
module.set("ratpack-core") | ||
versions.set("[1.0,1.7)") | ||
} | ||
} | ||
|
||
dependencies { | ||
library("io.ratpack:ratpack-core:1.7.0") | ||
|
||
implementation(project(":instrumentation:netty:netty-4.1:library")) | ||
implementation(project(":instrumentation:ratpack:ratpack-1.7:library")) | ||
|
||
testImplementation(project(":instrumentation:ratpack:ratpack-1.4:testing")) | ||
testInstrumentation(project(":instrumentation:ratpack:ratpack-1.4:javaagent")) | ||
} | ||
|
||
tasks { | ||
withType<Test>().configureEach { | ||
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) | ||
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true") | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...elemetry/javaagent/instrumentation/ratpack/v1_7/DefaultExecControllerInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.ratpack.v1_7; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import io.opentelemetry.instrumentation.ratpack.v1_7.internal.OpenTelemetryExecInitializer; | ||
import io.opentelemetry.instrumentation.ratpack.v1_7.internal.OpenTelemetryExecInterceptor; | ||
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.ToArguments.ToArgument; | ||
import net.bytebuddy.asm.Advice.AssignReturned.ToFields.ToField; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import ratpack.exec.ExecInitializer; | ||
import ratpack.exec.ExecInterceptor; | ||
|
||
public class DefaultExecControllerInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("ratpack.exec.internal.DefaultExecController"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
named("setInitializers") | ||
.and(takesArgument(0, named("com.google.common.collect.ImmutableList"))), | ||
DefaultExecControllerInstrumentation.class.getName() + "$SetInitializersAdvice"); | ||
|
||
transformer.applyAdviceToMethod( | ||
named("setInterceptors") | ||
.and(takesArgument(0, named("com.google.common.collect.ImmutableList"))), | ||
DefaultExecControllerInstrumentation.class.getName() + "$SetInterceptorsAdvice"); | ||
|
||
transformer.applyAdviceToMethod( | ||
isConstructor(), | ||
DefaultExecControllerInstrumentation.class.getName() + "$ConstructorAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class SetInitializersAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
@Advice.AssignReturned.ToArguments(@ToArgument(0)) | ||
public static ImmutableList<? extends ExecInitializer> enter( | ||
@Advice.Argument(0) ImmutableList<? extends ExecInitializer> initializers) { | ||
return ImmutableList.<ExecInitializer>builder() | ||
.addAll(initializers) | ||
.add(OpenTelemetryExecInitializer.INSTANCE) | ||
.build(); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class SetInterceptorsAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
@Advice.AssignReturned.ToArguments(@ToArgument(0)) | ||
public static ImmutableList<? extends ExecInterceptor> enter( | ||
@Advice.Argument(0) ImmutableList<? extends ExecInterceptor> interceptors) { | ||
return ImmutableList.<ExecInterceptor>builder() | ||
.addAll(interceptors) | ||
.add(OpenTelemetryExecInterceptor.INSTANCE) | ||
.build(); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class ConstructorAdvice { | ||
|
||
@SuppressWarnings("UnusedVariable") | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
@Advice.AssignReturned.ToFields({ | ||
@ToField(value = "initializers", index = 0), | ||
@ToField(value = "interceptors", index = 1) | ||
}) | ||
public static Object[] exit( | ||
@Advice.FieldValue("initializers") ImmutableList<? extends ExecInitializer> initializers, | ||
@Advice.FieldValue("interceptors") ImmutableList<? extends ExecInterceptor> interceptors) { | ||
return new Object[] { | ||
ImmutableList.of(OpenTelemetryExecInitializer.INSTANCE), | ||
ImmutableList.of(OpenTelemetryExecInterceptor.INSTANCE) | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.