opentelemetry-java-instrume.../gradle/instrumentation.gradle

134 lines
4.7 KiB
Groovy

// common gradle file for instrumentation
import io.opentelemetry.instrumentation.gradle.bytebuddy.ByteBuddyPluginConfigurator
apply plugin: 'net.bytebuddy.byte-buddy'
apply plugin: 'muzzle'
apply plugin: 'com.github.johnrengelman.shadow'
ext {
packageInAgentBundle = true
mavenGroupId = 'io.opentelemetry.javaagent.instrumentation'
// Shadow is only for testing, not publishing.
noShadowPublish = true
}
apply from: "$rootDir/gradle/java.gradle"
if (project.ext.find("skipPublish") != true) {
apply from: "$rootDir/gradle/publish.gradle"
}
apply from: "$rootDir/gradle/instrumentation-common.gradle"
if (projectDir.name == 'javaagent') {
archivesBaseName = projectDir.parentFile.name
}
configurations {
toolingRuntime {
canBeConsumed = false
canBeResolved = true
}
bootstrapRuntime {
canBeConsumed = false
canBeResolved = true
}
}
afterEvaluate {
dependencies {
compileOnly project(':instrumentation-api')
compileOnly project(':javaagent-api')
compileOnly project(':javaagent-bootstrap')
// Apply common dependencies for instrumentation.
compileOnly(project(':javaagent-tooling')) {
// OpenTelemetry SDK is not needed for compilation
exclude group: 'io.opentelemetry', module: 'opentelemetry-sdk'
}
compileOnly deps.bytebuddy
annotationProcessor deps.autoservice
compileOnly deps.autoservice
compileOnly deps.slf4j
testImplementation deps.opentelemetryApi
testImplementation project(':testing-common')
testAnnotationProcessor deps.autoservice
testCompileOnly deps.autoservice
testImplementation deps.testcontainers
toolingRuntime(project(path: ":javaagent-tooling", configuration: 'instrumentationMuzzle'))
bootstrapRuntime(project(path: ":javaagent-bootstrap", configuration: 'instrumentationMuzzle'))
}
def pluginName = 'io.opentelemetry.javaagent.tooling.muzzle.collector.MuzzleCodeGenerationPlugin'
new ByteBuddyPluginConfigurator(project, sourceSets.main, pluginName,
configurations.toolingRuntime + configurations.runtimeClasspath
).configure()
}
configurations {
testInstrumentation
}
shadowJar {
configurations = [project.configurations.runtimeClasspath, project.configurations.testInstrumentation]
mergeServiceFiles()
archiveFileName = 'agent-testing.jar'
// rewrite library instrumentation dependencies
relocate "io.opentelemetry.instrumentation", "io.opentelemetry.javaagent.shaded.instrumentation"
// Prevents conflict with other SLF4J instances. Important for premain.
relocate 'org.slf4j', 'io.opentelemetry.javaagent.slf4j'
// rewrite dependencies calling Logger.getLogger
relocate 'java.util.logging.Logger', 'io.opentelemetry.javaagent.bootstrap.PatchLogger'
// prevents conflict with library instrumentation
relocate 'io.opentelemetry.instrumentation.api', 'io.opentelemetry.javaagent.shaded.instrumentation.api'
// relocate OpenTelemetry API usage
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.spi", "io.opentelemetry.javaagent.shaded.io.opentelemetry.spi"
relocate "io.opentelemetry.context", "io.opentelemetry.javaagent.shaded.io.opentelemetry.context"
// relocate OpenTelemetry extensions
relocate "io.opentelemetry.extension.kotlin", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.kotlin"
relocate "io.opentelemetry.extension.trace.propagation", "io.opentelemetry.javaagent.shaded.io.opentelemetry.extension.trace.propagation"
// this is for instrumentation on opentelemetry-api itself
relocate "application.io.opentelemetry", "io.opentelemetry"
}
evaluationDependsOn(":testing:agent-for-testing")
tasks.withType(Test).configureEach {
jvmArgs "-Dotel.javaagent.debug=true"
jvmArgs "-javaagent:${project(":testing:agent-for-testing").tasks.shadowJar.archiveFile.get().asFile.absolutePath}"
jvmArgs "-Dotel.initializer.jar=${shadowJar.archiveFile.get().asFile.absolutePath}"
jvmArgs "-Dinternal.testing.disable.global.library.ignores=true"
dependsOn shadowJar
dependsOn ":testing:agent-for-testing:shadowJar"
// 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.
classpath = classpath.filter {
if (file("$buildDir/resources/main").equals(it) || file("$buildDir/classes/java/main").equals(it)) {
return false
}
return true
}
}
configurations.configureEach {
if (it.name.toLowerCase().endsWith('testruntimeclasspath')) {
// Added by agent, don't let Gradle bring it in when running tests.
exclude module: 'javaagent-bootstrap'
}
}