From 8293b08622cff5e63c233450fb68d582409498cb Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Thu, 19 Oct 2023 14:00:26 +0300 Subject: [PATCH] Improve disableShadowRelocate --- ...rumentation.javaagent-shadowing.gradle.kts | 12 +++++----- .../kotlin/otel.java-conventions.gradle.kts | 7 +++++- ...ry.instrumentation.muzzle-check.gradle.kts | 24 ++++++++++--------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts b/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts index c8441b862456..66fc10d03d41 100644 --- a/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts +++ b/conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts @@ -24,13 +24,13 @@ tasks.withType().configureEach { exclude("io.opentelemetry.instrumentation.resources.*") exclude("io.opentelemetry.instrumentation.spring.resources.*") } - } - // relocate(OpenTelemetry API) since these classes live in the bootstrap class loader - relocate("io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api") - relocate("io.opentelemetry.semconv", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv") - relocate("io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context") - relocate("io.opentelemetry.extension.incubator", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.incubator") + // relocate(OpenTelemetry API) since these classes live in the bootstrap class loader + relocate("io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api") + relocate("io.opentelemetry.semconv", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv") + relocate("io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context") + relocate("io.opentelemetry.extension.incubator", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.incubator") + } // relocate(the OpenTelemetry extensions that are used by instrumentation modules) // these extensions live in the AgentClassLoader, and are injected into the user's class loader diff --git a/conventions/src/main/kotlin/otel.java-conventions.gradle.kts b/conventions/src/main/kotlin/otel.java-conventions.gradle.kts index 93a80434b5b8..6a34417a38c3 100644 --- a/conventions/src/main/kotlin/otel.java-conventions.gradle.kts +++ b/conventions/src/main/kotlin/otel.java-conventions.gradle.kts @@ -323,7 +323,12 @@ tasks.withType().configureEach { // propagation. jvmArgs("-Dio.opentelemetry.context.enableStrictContext=${rootProject.findProperty("enableStrictContext") ?: true}") // TODO(anuraaga): Have agent map unshaded to shaded. - jvmArgs("-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=${rootProject.findProperty("enableStrictContext") ?: true}") + if (project.findProperty("disableShadowRelocate") != "true") { + jvmArgs("-Dio.opentelemetry.javaagent.shaded.io.opentelemetry.context.enableStrictContext=${rootProject.findProperty("enableStrictContext") ?: true}") + } else { + jvmArgs("-Dotel.instrumentation.opentelemetry-api.enabled=false") + jvmArgs("-Dotel.instrumentation.opentelemetry-instrumentation-api.enabled=false") + } // Disable default resource providers since they cause lots of output we don't need. jvmArgs("-Dotel.java.disabled.resource.providers=$resourceClassesCsv") diff --git a/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts b/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts index 19238cccc7bb..026137ee5d14 100644 --- a/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts +++ b/gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts @@ -85,18 +85,20 @@ tasks.withType().configureEach { // rewrite dependencies calling Logger.getLogger relocate("java.util.logging.Logger", "io.opentelemetry.javaagent.bootstrap.PatchLogger") - // prevents conflict with library instrumentation, since these classes live in the bootstrap class loader - relocate("io.opentelemetry.instrumentation", "io.opentelemetry.javaagent.shaded.instrumentation") { - // Exclude resource providers since they live in the agent class loader - exclude("io.opentelemetry.instrumentation.resources.*") - exclude("io.opentelemetry.instrumentation.spring.resources.*") - } + if (project.findProperty("disableShadowRelocate") != "true") { + // prevents conflict with library instrumentation, since these classes live in the bootstrap class loader + relocate("io.opentelemetry.instrumentation", "io.opentelemetry.javaagent.shaded.instrumentation") { + // Exclude resource providers since they live in the agent class loader + exclude("io.opentelemetry.instrumentation.resources.*") + exclude("io.opentelemetry.instrumentation.spring.resources.*") + } - // relocate(OpenTelemetry API) since these classes live in the bootstrap class loader - relocate("io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api") - relocate("io.opentelemetry.semconv", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv") - relocate("io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context") - relocate("io.opentelemetry.extension.incubator", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.incubator") + // relocate(OpenTelemetry API) since these classes live in the bootstrap class loader + relocate("io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api") + relocate("io.opentelemetry.semconv", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv") + relocate("io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context") + relocate("io.opentelemetry.extension.incubator", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.incubator") + } // relocate(the OpenTelemetry extensions that are used by instrumentation modules) // these extensions live in the AgentClassLoader, and are injected into the user's class loader