Stop relocating :instrumentation:resources:library
Per the discussion in the today's SIG and this
[comment](https://github.com/open-telemetry/opentelemetry-java/issues/4919#issuecomment-1305774636).
MODIFY
conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts
conventions/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-shadowing.gradle.kts
@@ -18,7 +18,11 @@ tasks.withType<ShadowJar>().configureEach {
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")
+ 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")

MODIFY
examples/distro/gradle/shadow.gradle
examples/distro/gradle/shadow.gradle
ext.relocatePackages = { shadowJar ->
// rewrite dependencies calling Logger.getLogger
- shadowJar.relocate 'java.util.logging.Logger', 'io.opentelemetry.javaagent.bootstrap.PatchLogger'
+ shadowJar.relocate("java.util.logging.Logger", "io.opentelemetry.javaagent.bootstrap.PatchLogger")
- // rewrite library instrumentation dependencies
- shadowJar.relocate "io.opentelemetry.instrumentation", "io.opentelemetry.javaagent.shaded.instrumentation"
+ // prevents conflict with library instrumentation, since these classes live in the bootstrap class loader
+ shadowJar.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 usage
- shadowJar.relocate "io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api"
- shadowJar.relocate "io.opentelemetry.semconv", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv"
- shadowJar.relocate "io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context"
+ // relocate(OpenTelemetry API) since these classes live in the bootstrap class loader
+ shadowJar.relocate("io.opentelemetry.api", "io.opentelemetry.javaagent.shaded.io.opentelemetry.api")
+ shadowJar.relocate("io.opentelemetry.semconv", "io.opentelemetry.javaagent.shaded.io.opentelemetry.semconv")
+ shadowJar.relocate("io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context")
// 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
// by the instrumentation modules that use them
- shadowJar.relocate "io.opentelemetry.extension.aws", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.aws"
- shadowJar.relocate "io.opentelemetry.extension.kotlin", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.kotlin"
+ shadowJar.relocate("io.opentelemetry.extension.aws", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.aws")
+ shadowJar.relocate("io.opentelemetry.extension.kotlin", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.kotlin")
}

MODIFY
gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts
gradle-plugins/src/main/kotlin/io.opentelemetry.instrumentation.muzzle-check.gradle.kts
@@ -85,10 +85,14 @@ tasks.withType<ShadowJar>().configureEach {
// rewrite dependencies calling Logger.getLogger
relocate("java.util.logging.Logger", "io.opentelemetry.javaagent.bootstrap.PatchLogger")
- // prevents conflict with library instrumentation
- relocate("io.opentelemetry.instrumentation", "io.opentelemetry.javaagent.shaded.instrumentation")
+ // 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)
+ // 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")
@@ -230,7 +234,7 @@ fun newRepositorySystemSession(system: RepositorySystem): RepositorySystemSessio
val muzzleRepo = file("${buildDir}/muzzleRepo")
val localRepo = LocalRepository(muzzleRepo)
return MavenRepositorySystemUtils.newSession().apply {
- setLocalRepositoryManager(system.newLocalRepositoryManager(this, localRepo))
+ localRepositoryManager = system.newLocalRepositoryManager(this, localRepo)
}
}

MODIFY
instrumentation/resources/library/build.gradle.kts
instrumentation/resources/library/build.gradle.kts
plugins {
- id("otel.library-instrumentation")
+ id("otel.sdk-extension")
}
val mrJarVersions = listOf(9, 11)

MODIFY
javaagent-tooling/build.gradle.kts
javaagent-tooling/build.gradle.kts
@@ -14,7 +14,6 @@ dependencies {
implementation(project(":javaagent-tooling:javaagent-tooling-java9"))
implementation(project(":instrumentation-api"))
implementation(project(":instrumentation-annotations-support"))
- implementation(project(":instrumentation:resources:library"))
implementation(project(":muzzle"))
implementation("io.opentelemetry:opentelemetry-api")

Stop relocating :instrumentation:resources:library (#7136)

Per the discussion in the today's SIG and this
[comment](https://github.com/open-telemetry/opentelemetry-java/issues/4919#issuecomment-1305774636).

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>