Refactor agent-for-testing build
MODIFY
testing/agent-exporter/build.gradle.kts
testing/agent-exporter/build.gradle.kts
plugins {
- id("io.opentelemetry.instrumentation.javaagent-shadowing")
-
id("otel.java-conventions")
}
dependencies {
- compileOnly("net.bytebuddy:byte-buddy")
- compileOnly("io.opentelemetry:opentelemetry-sdk")
- compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
- compileOnly("org.slf4j:slf4j-api")
-
annotationProcessor("com.google.auto.service:auto-service")
compileOnly("com.google.auto.service:auto-service")
- implementation(project(":instrumentation-api"))
- implementation(project(":javaagent-instrumentation-api"))
implementation(project(":javaagent-extension-api"))
+ implementation(project(":javaagent-instrumentation-api"))
implementation(project(":javaagent-tooling"))
- implementation("io.opentelemetry:opentelemetry-proto")
+
+ implementation("io.grpc:grpc-core:1.33.1")
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
implementation("io.opentelemetry:opentelemetry-exporter-otlp-metrics")
- implementation("io.grpc:grpc-testing:1.33.1")
-
- // Include instrumentations instrumenting core JDK classes tp ensure interoperability with other instrumentation
- implementation(project(":instrumentation:executors:javaagent"))
- // FIXME: we should enable this, but currently this fails tests for google http client
- //testImplementation project(":instrumentation:http-url-connection:javaagent")
- implementation(project(":instrumentation:internal:internal-class-loader:javaagent"))
- implementation(project(":instrumentation:internal:internal-eclipse-osgi-3.6:javaagent"))
- implementation(project(":instrumentation:internal:internal-proxy:javaagent"))
- implementation(project(":instrumentation:internal:internal-url-class-loader:javaagent"))
-
- // Many tests use OpenTelemetry API calls, e.g., via ServerTraceUtils.runUnderServerTrace
- implementation(project(":instrumentation:opentelemetry-annotations-1.0:javaagent"))
- // TODO (trask) is full OTel API interop needed, or is @WithSpan enough?
- implementation(project(":instrumentation:opentelemetry-api-1.0:javaagent"))
-}
-
-tasks {
- jar {
- enabled = false
- }
- shadowJar {
- archiveFileName.set("testing-agent-classloader.jar")
- }
+ implementation("io.opentelemetry:opentelemetry-proto")
+ implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
+ implementation("org.slf4j:slf4j-api")
}

MODIFY
testing/agent-for-testing/build.gradle.kts
testing/agent-for-testing/build.gradle.kts
@@ -14,7 +14,16 @@ val bootstrapLibs by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
}
-val javaagentLibs by configurations.creating
+val javaagentLibs by configurations.creating {
+ isCanBeResolved = true
+ isCanBeConsumed = false
+
+ // exclude dependencies that are to be placed in bootstrap - they won't be added to inst/
+ exclude("org.slf4j")
+ exclude("io.opentelemetry", "opentelemetry-api")
+ exclude("io.opentelemetry", "opentelemetry-api-metrics")
+ exclude("io.opentelemetry", "opentelemetry-semconv")
+}
dependencies {
bootstrapLibs(project(":instrumentation-api"))
@@ -23,7 +32,22 @@ dependencies {
bootstrapLibs(project(":javaagent-instrumentation-api"))
bootstrapLibs("org.slf4j:slf4j-simple")
- javaagentLibs(project(":testing:agent-exporter", configuration = "shadow"))
+ javaagentLibs(project(":testing:agent-exporter"))
+ javaagentLibs(project(":javaagent-extension-api"))
+ javaagentLibs(project(":javaagent-tooling"))
+
+ // Include instrumentations instrumenting core JDK classes tp ensure interoperability with other instrumentation
+ javaagentLibs(project(":instrumentation:executors:javaagent"))
+ // FIXME: we should enable this, but currently this fails tests for google http client
+ //testImplementation project(":instrumentation:http-url-connection:javaagent")
+ javaagentLibs(project(":instrumentation:internal:internal-class-loader:javaagent"))
+ javaagentLibs(project(":instrumentation:internal:internal-eclipse-osgi-3.6:javaagent"))
+ javaagentLibs(project(":instrumentation:internal:internal-proxy:javaagent"))
+ javaagentLibs(project(":instrumentation:internal:internal-url-class-loader:javaagent"))
+
+ // Many tests use OpenTelemetry API calls, e.g. via InstrumentationTestRunner.runWithSpan
+ javaagentLibs(project(":instrumentation:opentelemetry-annotations-1.0:javaagent"))
+ javaagentLibs(project(":instrumentation:opentelemetry-api-1.0:javaagent"))
testImplementation(project(":testing-common"))
testImplementation("io.opentelemetry:opentelemetry-api")
@@ -44,6 +68,25 @@ project(":instrumentation").subprojects {
}
}
+tasks {
+ jar {
+ enabled = false
+ }
+
+ val relocateJavaagentLibs by registering(ShadowJar::class) {
+ configurations = listOf(javaagentLibs)
+
+ archiveFileName.set("javaagentLibs-relocated.jar")
+
+ // exclude bootstrap projects from javaagent libs - they won't be added to inst/
+ dependencies {
+ exclude(project(":instrumentation-api"))
+ exclude(project(":instrumentation-api-annotation-support"))
+ exclude(project(":javaagent-bootstrap"))
+ exclude(project(":javaagent-instrumentation-api"))
+ }
+ }
+
fun isolateAgentClasses (jars: Iterable<File>): CopySpec {
return copySpec {
jars.forEach {
@@ -58,19 +101,11 @@ fun isolateAgentClasses (jars: Iterable<File>): CopySpec {
}
}
-evaluationDependsOn(":testing:agent-exporter")
-
-tasks {
- jar {
- enabled = false
- }
-
val shadowJar by existing(ShadowJar::class) {
- dependsOn(":testing:agent-exporter:shadowJar")
+ dependsOn(relocateJavaagentLibs)
configurations = listOf(bootstrapLibs)
-
- with(isolateAgentClasses(javaagentLibs.files))
+ with(isolateAgentClasses(relocateJavaagentLibs.get().outputs.files))
archiveClassifier.set("")

Refactor agent-for-testing build (#3600)