Skip to content

Commit

Permalink
Support testing library/agent instrumentation interoperability
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Dec 2, 2021
1 parent 137225a commit b083079
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tasks.withType<ShadowJar>().configureEach {
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
// these extensions live in the AgentClassLoader, and are injected into the user's class loader
// by the instrumentation modules that use them
relocate("io.opentelemetry.extension.aws", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.aws")
relocate("io.opentelemetry.extension.kotlin", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.kotlin")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,19 @@ afterEvaluate {
// We do fine-grained filtering of the classpath of this codebase's sources since Gradle's
// configurations will include transitive dependencies as well, which tests do often need.
classpath = classpath.filter {
// The sources are packaged into the testing jar so we need to make sure to exclude from the test
// classpath, which automatically inherits them, to ensure our shaded versions are used.
if (file("${buildDir}/resources/main").equals(it) || file("${buildDir}/classes/java/main").equals(it)) {
// The sources are packaged into the testing jar, so we need to exclude them from the test
// classpath, which automatically inherits them, to ensure our shaded versions are used.
return@filter false
}

// TODO(anuraaga): Better not to have this folder structure constraints, we can likely use
// TODO(anuraaga): Better not to have this naming constraint, we can likely use
// plugin identification instead.

// If agent depends on some shared instrumentation module that is not a testing module, it will
// be packaged into the testing jar so we need to make sure to exclude from the test classpath.
val lib = it.absoluteFile
val instrumentationDir = file("${rootDir}/instrumentation/").absoluteFile
if (lib.startsWith(instrumentationDir) &&
lib.extension == "jar" &&
!lib.absolutePath.substring(instrumentationDir.absolutePath.length).contains("testing")) {
if (lib.name.startsWith("opentelemetry-javaagent-")) {
// These dependencies are packaged into the testing jar, so we need to exclude them from the test
// classpath, which automatically inherits them, to ensure our shaded versions are used.
return@filter false
}
return@filter true
Expand Down

0 comments on commit b083079

Please sign in to comment.