Skip to content

Commit ebfda74

Browse files
authored
Upgrade otel 1 4 1 (#345)
* ⬆️ upgrade to 1.3.1 * ♻️ update ComponentInstaller to AgentListener * ♻️ refactor IgnoreMatcherProvider to IgnoredTypesConfigurer * ♻️ refactor java-streams instrumentation * ♻️ refactor ApacheClientInstrumentationModule to use new Instrumentation API * ♻️ refactor apache-httpasyncclient-4.1 to use new instrumentation api and fix usage of DelegatingRequestProducer * ♻️ update grpc to use new instrumentation API * ♻️ update jaxrs-client-2.0 to use new instrumentation extension API and hardcode string * ♻️ update servlet-3.0 to use new instrumentation extension API * ♻️ update servlet test instrumentation * ✨ add library to unshade the netty-4.0-all JAR * ♻️ refactor netty-4.0 to use the unshaded jar library * ✨ create project to unshade netty-4.1 otel dependency * ♻️ refactor netty to use unsahded JAR * ♻️ update usage of instrumentation api in okhttp module * ♻️ move configuration of instrumentation subproject dependencies to plugin * ♻️ refactor unshade logic into plugin * 🐛 fix id of plugin for netty 4.1 * 🐛 fix netty-4.1 * ♻️ refactor undertow-1.4 build to rely on unshaded otel JAR * ♻️ refactor undertow instrumentation to use new instrumentation api * 🚚 move vertx-web to dedicated folder * 🐛 include vertx-web instrumentation in instrumentation JAR * ♻️ make vertx depend on shaded jar * ♻️ refactor vertx to use new instrumentation api * 🔥 remove shadow plugin version * ♻️ update grpc-shaded-netty-1.9 to use new instrumentation api * ⬆️ upgrade byte buddy * ✅ add grpc-netty dependency for runtime usage by the grpc client * ⚗️ add extension-api to tooling dependencies * ⚗️ refactor buildSrc to match otel more * ♻️ update instrumentation projects to account for muzzle plugin being ported to java * 🔥 delete manual meta-inf entry for MuzzlePlugin' * 🔥 remove extension-api from dependent tasks for mzuzle * Revert "🔥 remove extension-api from dependent tasks for mzuzle" This reverts commit 471b9bd. * Revert ":fire: delete manual meta-inf entry for MuzzlePlugin'" This reverts commit 28ce72f. * Revert ":recycle: update instrumentation projects to account for muzzle plugin being ported to java" This reverts commit 75168f9. * Revert ":alembic: refactor buildSrc to match otel more" This reverts commit 232bbc7. * ♻️ gradle lazy configuration * ➕ add bootstrap to testing-common * ⚗️ initialize AgentClassLoader as app class loader * ♻️ relocate shaded slf4j * 🐛 unsshade otel httpasync module for testing * 🐛 unshade apache-httpclient for testing purposes * 🐛 unshade grpc for testing purposes' * ♻️ refactor java-streams test instrumentation to match new instrumentation api * 🐛 unshade jaxrs-client for testing purposes' * 🐛 use unshaded netty for micronaut * 🐛 unshade spark instrumentation deps for testing purposes' * 🐛 unshade struts instrumentation deps for testing purposes * relocate netty lib usage * 🐛 unshade okhttp instrumentation deps for testing purposes * ♻️ use unshaded servlet 3.0 instrumentation for testing purposes * 🐛 relocate shaded standalone instrumentation library * ➕ add missing tracing library as dependency to servlet-3.0 * ♻️ refactor servle-rw test instrumentation to use the new instrumentation API * 🔥 remove unused otel dependencies * 🐛 fix bug where muzzle found violations by restricting what is in the shaded module * 🐛 fix missing async response bodies/headers as a result of a the span being marked as ended earlier in otel pr 2992 * ♻️ make sure request buffer gets reset * 🐛 fix bug where bad key was used in call depth map * ♻️ add back in inheritance * 🐛 get client context from superclass volatile field * 🐛 fix bug where two traces are sent * 🐛 fix flaky test * recycle: levearge unshaded jaxrs library in insturmentation module * ♻️ remove unneded changes to netty module * Revert "recycle: levearge unshaded jaxrs library in insturmentation module" This reverts commit 3586a4b. * ⬆️ upgrade otel * ♻️ rename instrumentation api artifact dependency * ♻️ update otel-extensions to account for changes in the upstream API * ♻️ refactor usages of CallDepthThreadLocalMap and safeHasSuperType * 🐛 fix compile errors with apachehttpasync module * 🐛 fix compile errors with apache-httpclient * 🐛 fix compile errors with grpc-1.6 instrumentation module * 🐛 fix compile errors with jaxrs-client * 🐛 fix compile errors with spark * 🐛 fix compile errors with servlet-rw * 🐛 fix compile errors with servlet-3.0 * 🐛 fix compile bugs with struts-2.3 * ♻️ fix compile errors in okhttp * 🐛 fxi netty compile errors * 🐛 fix micronaut compile errors' * 🐛 fix bug with undertow compile * 🐛 fix compile bug with vertx * ⬆️ upgrade to 1.4.1 * :WIP functioning build script * 🚧 semi-working apache http async client module * Revert "🚧 semi-working apache http async client module" This reverts commit e44c35b. * Revert ":WIP functioning build script" This reverts commit 31a95b4. * 💩 new build logic * 🔥 disable non-otlp receivers as they dont seem to work anymore * 🐛 fix bug where InstrumentationHolder is no longer set * 🐛 set contextStorageProvider * 🐛 put in bootstrap classes into test source set * 🔥 delete unshade plugin * ♻️ use contrib image * 🔥 remove jaeger reciever * 🔥 remove muzzle comment * 💡 document workaroudn for OpenTelemetryInstaller * 💡 document workaround * 🔥 remove extra build scripts
1 parent 994bef6 commit ebfda74

File tree

83 files changed

+848
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+848
-625
lines changed

build.gradle.kts

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ subprojects {
3232
description = "Hypertrace OpenTelemetry Javaagent"
3333

3434
extra.set("versions", mapOf(
35-
"opentelemetry" to "1.2.0",
36-
"opentelemetry_java_agent" to "1.2.0-alpha",
37-
"opentelemetry_java_agent_all" to "1.2.0",
38-
"byte_buddy" to "1.10.18",
35+
"opentelemetry" to "1.4.1",
36+
"opentelemetry_java_agent" to "1.4.1-alpha",
37+
"opentelemetry_java_agent_all" to "1.4.1",
38+
"byte_buddy" to "1.11.2",
3939
"slf4j" to "1.7.30"
4040
))
4141

buildSrc/build.gradle.kts

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ gradlePlugin {
2020
repositories {
2121
mavenLocal()
2222
jcenter()
23+
gradlePluginPortal()
2324
mavenCentral()
2425
}
2526

2627
dependencies {
2728
implementation(gradleApi())
2829
implementation(localGroovy())
2930

31+
implementation("com.github.jengelman.gradle.plugins:shadow:6.0.0")
3032
implementation("org.eclipse.aether", "aether-connector-basic", "1.1.0")
3133
implementation("org.eclipse.aether", "aether-transport-http", "1.1.0")
3234
implementation("org.apache.maven", "maven-aether-provider", "3.3.9")
@@ -35,7 +37,7 @@ dependencies {
3537
implementation("org.ow2.asm", "asm", "7.0-beta")
3638
implementation("org.ow2.asm", "asm-tree", "7.0-beta")
3739
implementation("org.apache.httpcomponents:httpclient:4.5.10")
38-
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.10.18")
40+
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.11.2")
3941

4042
testImplementation("org.spockframework", "spock-core", "1.3-groovy-2.5")
4143
testImplementation("org.codehaus.groovy", "groovy-all", "2.5.8")

buildSrc/src/main/java/io/opentelemetry/instrumentation/gradle/AutoInstrumentationPlugin.java

+42
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77

88
import java.io.File;
99
import java.util.Arrays;
10+
import java.util.Map;
11+
import java.util.Objects;
12+
import org.gradle.api.Action;
1013
import org.gradle.api.Plugin;
1114
import org.gradle.api.Project;
1215
import org.gradle.api.artifacts.Configuration;
1316
import org.gradle.api.artifacts.Dependency;
17+
import org.gradle.api.artifacts.dsl.DependencyHandler;
18+
import org.gradle.api.attributes.AttributeContainer;
19+
import org.gradle.api.attributes.LibraryElements;
1420
import org.gradle.api.plugins.JavaLibraryPlugin;
21+
import org.gradle.api.plugins.JavaPlugin;
1522
import org.gradle.api.tasks.Internal;
1623
import org.gradle.api.tasks.testing.Test;
1724
import org.gradle.process.CommandLineArgumentProvider;
@@ -27,6 +34,7 @@ public class AutoInstrumentationPlugin implements Plugin<Project> {
2734
public void apply(Project project) {
2835
project.getPlugins().apply(JavaLibraryPlugin.class);
2936
createLibraryConfiguration(project);
37+
addDependencies(project);
3038
project
3139
.getTasks()
3240
.withType(
@@ -43,6 +51,40 @@ public void apply(Project project) {
4351
});
4452
}
4553

54+
private void addDependencies(Project project) {
55+
DependencyHandler dependencies = project.getDependencies();
56+
@SuppressWarnings("unchecked") final Map<String, String> versions = Objects.requireNonNull(
57+
(Map<String, String>) project.getExtensions().getExtraProperties().get("versions"));
58+
59+
dependencies.add("implementation", "org.slf4j:slf4j-api:1.7.30");
60+
dependencies.add("compileOnly", "com.google.auto.service:auto-service-annotations:1.0");
61+
dependencies.add("annotationProcessor", "com.google.auto.service:auto-service:1.0");
62+
dependencies.add("implementation", "net.bytebuddy:byte-buddy:" + versions.get("byte_buddy"));
63+
dependencies.add("implementation",
64+
"io.opentelemetry:opentelemetry-api:" + versions.get("opentelemetry"));
65+
dependencies.add("implementation",
66+
"io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:" + versions
67+
.get("opentelemetry_java_agent"));
68+
dependencies.add("implementation",
69+
"io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:" + versions
70+
.get("opentelemetry_java_agent"));
71+
dependencies.add("implementation",
72+
"io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:" + versions
73+
.get("opentelemetry_java_agent"));
74+
dependencies.add("implementation",
75+
"io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:" + versions
76+
.get("opentelemetry_java_agent"));
77+
78+
dependencies.add("implementation", dependencies.project(Map.of("path", ":javaagent-core")));
79+
dependencies.add("implementation", dependencies.project(Map.of("path", ":filter-api")));
80+
81+
project.getConfigurations().named(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME).configure(
82+
files -> files.attributes(attributeContainer -> attributeContainer.attribute(
83+
LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
84+
project.getObjects().named(LibraryElements.class, LibraryElements.JAR))));
85+
86+
}
87+
4688
/**
4789
* Creates a custom dependency configuration called {@code library} inspired by the <a
4890
* href="https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/0b0516bd1a0599c8f536cc6b2151782000681f39/gradle/instrumentation-common.gradle#L8">opentelemetry-java-instrumentation</a>.

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

+63-34
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
import java.io.File;
1010
import java.util.Arrays;
1111
import java.util.List;
12+
import java.util.Objects;
13+
import java.util.stream.Collectors;
1214
import net.bytebuddy.build.gradle.ByteBuddySimpleTask;
1315
import net.bytebuddy.build.gradle.Transformation;
16+
import org.gradle.api.Action;
1417
import org.gradle.api.Project;
1518
import org.gradle.api.Task;
1619
import org.gradle.api.tasks.SourceSet;
20+
import org.gradle.api.tasks.TaskProvider;
1721
import org.gradle.api.tasks.compile.AbstractCompile;
1822

1923
/**
@@ -35,6 +39,7 @@
3539
* of the compile task.
3640
*/
3741
public class ByteBuddyPluginConfigurator {
42+
3843
private static final List<String> LANGUAGES = Arrays.asList("java", "scala", "kotlin");
3944

4045
private final Project project;
@@ -61,43 +66,67 @@ public ByteBuddyPluginConfigurator(
6166

6267
public void configure() {
6368
String taskName = getTaskName();
64-
Task byteBuddyTask = project.getTasks().create(taskName);
65-
66-
for (String language : LANGUAGES) {
67-
AbstractCompile compile = getCompileTask(language);
68-
69-
if (compile != null) {
70-
Task languageTask = createLanguageTask(compile, taskName + language);
71-
// We also process resources for SPI classes.
72-
languageTask.dependsOn(sourceSet.getProcessResourcesTaskName());
73-
byteBuddyTask.dependsOn(languageTask);
74-
}
75-
}
7669

77-
project.getTasks().getByName(sourceSet.getClassesTaskName()).dependsOn(byteBuddyTask);
70+
List<TaskProvider<?>> languageTasks =
71+
LANGUAGES.stream()
72+
.map(
73+
language -> {
74+
if (project.fileTree("src/" + sourceSet.getName() + "/" + language).isEmpty()) {
75+
return null;
76+
}
77+
String compileTaskName = sourceSet.getCompileTaskName(language);
78+
if (!project.getTasks().getNames().contains(compileTaskName)) {
79+
return null;
80+
}
81+
TaskProvider<?> compileTask = project.getTasks().named(compileTaskName);
82+
83+
// We also process resources for SPI classes.
84+
return createLanguageTask(
85+
compileTask, taskName + language, sourceSet.getProcessResourcesTaskName());
86+
})
87+
.filter(Objects::nonNull)
88+
.collect(Collectors.toList());
89+
90+
TaskProvider<?> byteBuddyTask =
91+
project.getTasks().register(taskName, task -> task.dependsOn(languageTasks));
92+
93+
project
94+
.getTasks()
95+
.named(sourceSet.getClassesTaskName())
96+
.configure(task -> task.dependsOn(byteBuddyTask));
7897
}
7998

80-
private Task createLanguageTask(AbstractCompile compileTask, String name) {
81-
ByteBuddySimpleTask task = project.getTasks().create(name, ByteBuddySimpleTask.class);
82-
task.setGroup("Byte Buddy");
83-
task.getOutputs().cacheIf(unused -> true);
84-
85-
File classesDirectory = compileTask.getDestinationDir();
86-
File rawClassesDirectory =
87-
new File(classesDirectory.getParent(), classesDirectory.getName() + "raw")
88-
.getAbsoluteFile();
89-
90-
task.dependsOn(compileTask);
91-
compileTask.setDestinationDir(rawClassesDirectory);
92-
93-
task.setSource(rawClassesDirectory);
94-
task.setTarget(classesDirectory);
95-
task.setClassPath(compileTask.getClasspath());
96-
97-
task.dependsOn(compileTask);
98-
99-
task.getTransformations().add(createTransformation(inputClasspath, pluginClassName));
100-
return task;
99+
private TaskProvider<?> createLanguageTask(
100+
TaskProvider<?> compileTaskProvider, String name, String processResourcesTaskName) {
101+
return project
102+
.getTasks()
103+
.register(
104+
name,
105+
ByteBuddySimpleTask.class,
106+
task -> {
107+
task.setGroup("Byte Buddy");
108+
task.getOutputs().cacheIf(unused -> true);
109+
110+
Task maybeCompileTask = compileTaskProvider.get();
111+
if (maybeCompileTask instanceof AbstractCompile) {
112+
AbstractCompile compileTask = (AbstractCompile) maybeCompileTask;
113+
File classesDirectory = compileTask.getDestinationDirectory().getAsFile().get();
114+
File rawClassesDirectory =
115+
new File(classesDirectory.getParent(), classesDirectory.getName() + "raw")
116+
.getAbsoluteFile();
117+
118+
task.dependsOn(compileTask);
119+
compileTask.getDestinationDirectory().set(rawClassesDirectory);
120+
121+
task.setSource(rawClassesDirectory);
122+
task.setTarget(classesDirectory);
123+
task.setClassPath(compileTask.getClasspath());
124+
125+
task.dependsOn(compileTask, processResourcesTaskName);
126+
}
127+
128+
task.getTransformations().add(createTransformation(inputClasspath, pluginClassName));
129+
});
101130
}
102131

103132
private AbstractCompile getCompileTask(String language) {

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ dependencies {
3030
api(project(":instrumentation:java-streams"))
3131
api(project(":instrumentation:apache-httpclient-4.0"))
3232

33-
api("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-apache-httpasyncclient-4.1:${versions["opentelemetry_java_agent"]}")
34-
33+
implementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-apache-httpasyncclient-4.1:${versions["opentelemetry_java_agent"]}")
3534
library("org.apache.httpcomponents:httpasyncclient:4.1")
3635
testImplementation(testFixtures(project(":testing-common")))
3736
}

0 commit comments

Comments
 (0)