Skip to content

Commit e761494

Browse files
authored
Upgrade otel 1 5 3 (#346)
* ⬆️ upgrade otel * 🐛 fix buildSrc for instantiation of muzzle * 🐛 fix muzzle codegen class name * 🐛 add missing netty dependencies * ➕ add missing vertx dependency * 💩 🚧 WIP, try to make MuzzleGradlePluginUtil available * 🐛 use instrumentation CL for muzzle * ♻️ remove constrants as they are not needed in 0.7.0 * ➕ add muzzle-check gradle plugin to tooling project * ⬆️ upgrade otel instrumentation version * ♻️ depend on gradle-plugins rather than muzzle-check plugin
1 parent ebfda74 commit e761494

File tree

20 files changed

+43
-34
lines changed

20 files changed

+43
-34
lines changed

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ subprojects {
3232
description = "Hypertrace OpenTelemetry Javaagent"
3333

3434
extra.set("versions", mapOf(
35-
"opentelemetry" to "1.4.1",
36-
"opentelemetry_java_agent" to "1.4.1-alpha",
37-
"opentelemetry_java_agent_all" to "1.4.1",
35+
"opentelemetry" to "1.5.0",
36+
"opentelemetry_java_agent" to "1.5.3-alpha",
37+
"opentelemetry_java_agent_all" to "1.5.3",
3838
"byte_buddy" to "1.11.2",
3939
"slf4j" to "1.7.30"
4040
))

buildSrc/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ dependencies {
2828
implementation(gradleApi())
2929
implementation(localGroovy())
3030

31+
implementation("io.opentelemetry.instrumentation.muzzle-generation:io.opentelemetry.instrumentation.muzzle-generation.gradle.plugin:0.7.0")
32+
implementation("io.opentelemetry.instrumentation.muzzle-check:io.opentelemetry.instrumentation.muzzle-check.gradle.plugin:0.7.0")
3133
implementation("com.github.jengelman.gradle.plugins:shadow:6.0.0")
3234
implementation("org.eclipse.aether", "aether-connector-basic", "1.1.0")
3335
implementation("org.eclipse.aether", "aether-transport-http", "1.1.0")

buildSrc/src/main/groovy/MuzzlePlugin.groovy

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
7+
import org.gradle.api.file.FileCollection
8+
69
import java.lang.reflect.Method
710
import java.security.SecureClassLoader
811
import java.util.concurrent.atomic.AtomicReference
@@ -31,6 +34,8 @@ import org.gradle.api.Project
3134
import org.gradle.api.Task
3235
import org.gradle.api.model.ObjectFactory
3336

37+
import java.util.stream.StreamSupport
38+
3439
/**
3540
* muzzle task plugin which runs muzzle validation against a range of dependencies.
3641
*/
@@ -75,7 +80,7 @@ class MuzzlePlugin implements Plugin<Project> {
7580
project.getLogger().info('No muzzle pass directives configured. Asserting pass against instrumentation compile-time dependencies')
7681
ClassLoader userCL = createCompileDepsClassLoader(project, bootstrapProject)
7782
ClassLoader instrumentationCL = createInstrumentationClassloader(project, toolingProject)
78-
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.tooling.muzzle.matcher.MuzzleGradlePluginUtil')
83+
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.muzzle.matcher.MuzzleGradlePluginUtil')
7984
.getMethod('assertInstrumentationMuzzled', ClassLoader.class, ClassLoader.class, boolean.class)
8085
assertionMethod.invoke(null, instrumentationCL, userCL, true)
8186
}
@@ -87,7 +92,7 @@ class MuzzlePlugin implements Plugin<Project> {
8792
description = "Print references created by instrumentation muzzle"
8893
doLast {
8994
ClassLoader instrumentationCL = createInstrumentationClassloader(project, toolingProject)
90-
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.tooling.muzzle.matcher.MuzzleGradlePluginUtil')
95+
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.muzzle.matcher.MuzzleGradlePluginUtil')
9196
.getMethod('printMuzzleReferences', ClassLoader.class)
9297
assertionMethod.invoke(null, instrumentationCL)
9398
}
@@ -167,7 +172,8 @@ class MuzzlePlugin implements Plugin<Project> {
167172
private static ClassLoader createInstrumentationClassloader(Project project, Project toolingProject) {
168173
project.getLogger().info("Creating instrumentation classpath for: " + project.getName())
169174
Set<URL> urls = new HashSet<>()
170-
for (File f : project.sourceSets.main.runtimeClasspath.getFiles()) {
175+
FileCollection classpath = project.sourceSets.main.runtimeClasspath + toolingProject.configurations.named("instrumentationMuzzle").get()
176+
StreamSupport.stream(classpath.spliterator(), false).forEach { f ->
171177
project.getLogger().info('--' + f)
172178
urls.add(f.toURI().toURL())
173179
}
@@ -370,26 +376,19 @@ class MuzzlePlugin implements Plugin<Project> {
370376
doLast {
371377
ClassLoader instrumentationCL = createInstrumentationClassloader(instrumentationProject, toolingProject)
372378
def ccl = Thread.currentThread().contextClassLoader
373-
def bogusLoader = new SecureClassLoader() {
374-
@Override
375-
String toString() {
376-
return "bogus"
377-
}
378-
379-
}
380-
Thread.currentThread().contextClassLoader = bogusLoader
379+
Thread.currentThread().contextClassLoader = instrumentationCL
381380
ClassLoader userCL = createClassLoaderForTask(instrumentationProject, bootstrapProject, taskName)
382381
try {
383382
// find all instrumenters, get muzzle, and assert
384-
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.tooling.muzzle.matcher.MuzzleGradlePluginUtil')
383+
Method assertionMethod = instrumentationCL.loadClass('io.opentelemetry.javaagent.muzzle.matcher.MuzzleGradlePluginUtil')
385384
.getMethod('assertInstrumentationMuzzled', ClassLoader.class, ClassLoader.class, boolean.class)
386385
assertionMethod.invoke(null, instrumentationCL, userCL, muzzleDirective.assertPass)
387386
} finally {
388387
Thread.currentThread().contextClassLoader = ccl
389388
}
390389

391390
for (Thread thread : Thread.getThreads()) {
392-
if (thread.contextClassLoader == bogusLoader || thread.contextClassLoader == instrumentationCL || thread.contextClassLoader == userCL) {
391+
if (thread.contextClassLoader == instrumentationCL || thread.contextClassLoader == userCL) {
393392
throw new GradleException("Task $taskName has spawned a thread: $thread with classloader $thread.contextClassLoader. This will prevent GC of dynamic muzzle classes. Aborting muzzle run.")
394393
}
395394
}

buildSrc/src/main/java/io/opentelemetry/instrumentation/gradle/bytebuddy/ClasspathByteBuddyPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public boolean matches(TypeDescription typeDefinitions) {
6060
private static Plugin pluginFromClassPath(
6161
Iterable<File> classPath, File sourceDirectory, String className) {
6262
try {
63-
ClassLoader classLoader = classLoaderFromClassPath(classPath, sourceDirectory);
63+
URLClassLoader classLoader = classLoaderFromClassPath(classPath, sourceDirectory);
6464
Class<?> clazz = Class.forName(className, false, classLoader);
65-
return (Plugin) clazz.getDeclaredConstructor().newInstance();
65+
return (Plugin) clazz.getDeclaredConstructor(URLClassLoader.class).newInstance(classLoader);
6666
} catch (Exception e) {
6767
throw new RuntimeException("Failed to create ByteBuddy plugin instance", e);
6868
}
6969
}
7070

71-
private static ClassLoader classLoaderFromClassPath(
71+
private static URLClassLoader classLoaderFromClassPath(
7272
Iterable<File> classPath, File sourceDirectory) {
7373
List<URL> urls = new ArrayList<>();
7474
urls.add(fileAsUrl(sourceDirectory));

instrumentation/apache-httpasyncclient-4.1/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ muzzle {
1919
afterEvaluate{
2020
io.opentelemetry.instrumentation.gradle.bytebuddy.ByteBuddyPluginConfigurator(project,
2121
sourceSets.main.get(),
22-
"io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin",
22+
io.opentelemetry.javaagent.muzzle.generation.MuzzleCodeGenerationPlugin::class.java.name,
2323
project(":javaagent-tooling").configurations["instrumentationMuzzle"] + configurations.runtimeClasspath
2424
).configure()
2525
}

instrumentation/apache-httpclient-4.0/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ muzzle {
3131
afterEvaluate{
3232
io.opentelemetry.instrumentation.gradle.bytebuddy.ByteBuddyPluginConfigurator(project,
3333
sourceSets.main.get(),
34-
"io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin",
34+
io.opentelemetry.javaagent.muzzle.generation.MuzzleCodeGenerationPlugin::class.java.name,
3535
project(":javaagent-tooling").configurations["instrumentationMuzzle"] + configurations.runtimeClasspath
3636
).configure()
3737
}

instrumentation/grpc-1.6/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ muzzle {
2323
afterEvaluate{
2424
io.opentelemetry.instrumentation.gradle.bytebuddy.ByteBuddyPluginConfigurator(project,
2525
sourceSets.main.get(),
26-
"io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin",
26+
io.opentelemetry.javaagent.muzzle.generation.MuzzleCodeGenerationPlugin::class.java.name,
2727
project(":javaagent-tooling").configurations["instrumentationMuzzle"] + configurations.runtimeClasspath
2828
).configure()
2929
}

instrumentation/grpc-shaded-netty-1.9/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ muzzle {
1717
afterEvaluate{
1818
io.opentelemetry.instrumentation.gradle.bytebuddy.ByteBuddyPluginConfigurator(project,
1919
sourceSets.main.get(),
20-
"io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin",
20+
io.opentelemetry.javaagent.muzzle.generation.MuzzleCodeGenerationPlugin::class.java.name,
2121
project(":javaagent-tooling").configurations["instrumentationMuzzle"] + configurations.runtimeClasspath
2222
).configure()
2323
}

instrumentation/java-streams/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ muzzle {
1414
afterEvaluate{
1515
io.opentelemetry.instrumentation.gradle.bytebuddy.ByteBuddyPluginConfigurator(project,
1616
sourceSets.main.get(),
17-
"io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin",
17+
io.opentelemetry.javaagent.muzzle.generation.MuzzleCodeGenerationPlugin::class.java.name,
1818
project(":javaagent-tooling").configurations["instrumentationMuzzle"] + configurations.runtimeClasspath
1919
).configure()
2020
}

instrumentation/jaxrs-client-2.0/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ muzzle {
2424
afterEvaluate{
2525
io.opentelemetry.instrumentation.gradle.bytebuddy.ByteBuddyPluginConfigurator(project,
2626
sourceSets.main.get(),
27-
"io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin",
27+
io.opentelemetry.javaagent.muzzle.generation.MuzzleCodeGenerationPlugin::class.java.name,
2828
project(":javaagent-tooling").configurations["instrumentationMuzzle"] + configurations.runtimeClasspath
2929
).configure()
3030
}

0 commit comments

Comments
 (0)