123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- plugins {
- id "java"
- /*
- Instrumentation agent extension mechanism expects a single jar containing everything required
- for your extension. This also includes any external libraries that your extension uses and
- cannot access from application classpath (see comment below about `javax.servlet-api` dependency).
- Thus we use Shadow Gradle plugin to package our classes and all required runtime dependencies
- into a single jar.
- See https://imperceptiblethoughts.com/shadow/ for more details about Shadow plugin.
- */
- id "com.github.johnrengelman.shadow" version "6.1.0"
- id "io.opentelemetry.instrumentation.muzzle-generation" version "0.1.0-SNAPSHOT"
- }
- group 'io.opentelemetry.example'
- version '1.0'
- ext {
- versions = [
- opentelemetry : "1.4.1",
- opentelemetryAlpha : "1.4.1-alpha",
- opentelemetryJavaagent : "1.4.0",
- opentelemetryJavaagentAlpha: "1.4.0-alpha",
- ]
- deps = [
- autoservice: dependencies.create(group: 'com.google.auto.service', name: 'auto-service', version: '1.0')
- ]
- }
- repositories {
- mavenCentral()
- maven {
- url = uri("https://oss.sonatype.org/content/repositories/snapshots")
- }
- }
- configurations {
- /*
- We create a separate gradle configuration to grab a published Otel instrumentation agent.
- We don't need the agent during development of this extension module.
- This agent is used only during integration test.
- */
- otel
- }
- dependencies {
- /*
- Interfaces and SPIs that we implement. We use `compileOnly` dependency because during
- runtime all necessary classes are provided by javaagent itself.
- */
- compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${versions.opentelemetryAlpha}")
- compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:${versions.opentelemetryJavaagentAlpha}")
- compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
- //Provides @AutoService annotation that makes registration of our SPI implementations much easier
- compileOnly deps.autoservice
- annotationProcessor deps.autoservice
- /*
- Used by our demo instrumentation module to reference classes of the target instrumented library.
- We again use `compileOnly` here because during runtime these classes are provided by the
- actual application that we instrument.
- NB! Only Advice (and "helper") classes of instrumentation modules can access classes from application classpath.
- See https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/writing-instrumentation-module.md#advice-classes
- */
- compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
- /*
- This dependency is required for DemoSpanProcessor both during compile and runtime.
- Only dependencies added to `implementation` configuration will be picked up by Shadow plugin
- and added to the resulting jar for our extension's distribution.
- */
- implementation 'org.apache.commons:commons-lang3:3.11'
- //All dependencies below are only for tests
- testImplementation("org.testcontainers:testcontainers:1.15.3")
- testImplementation("com.fasterxml.jackson.core:jackson-databind:2.11.2")
- testImplementation("com.google.protobuf:protobuf-java-util:3.12.4")
- testImplementation("com.squareup.okhttp3:okhttp:3.12.12")
- testImplementation("io.opentelemetry:opentelemetry-api:${versions.opentelemetry}")
- testImplementation("io.opentelemetry:opentelemetry-proto:${versions.opentelemetryAlpha}")
- testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2")
- testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2")
- testRuntimeOnly("ch.qos.logback:logback-classic:1.2.3")
- //Otel Java instrumentation that we use and extend during integration tests
- otel("io.opentelemetry.javaagent:opentelemetry-javaagent:${versions.opentelemetryJavaagent}:all")
- }
- //Extracts manifest from OpenTelemetry Java agent to reuse it later
- task agentManifest(type: Copy) {
- from zipTree(configurations.otel.singleFile).matching {
- include 'META-INF/MANIFEST.MF'
- }
- into buildDir
- }
- //Produces a copy of upstream javaagent with this extension jar included inside it
- //The location of extension directory inside agent jar is hard-coded in the agent source code
- task extendedAgent(type: Jar) {
- dependsOn agentManifest
- archiveFileName = "opentelemetry-javaagent-all.jar"
- manifest.from "$buildDir/META-INF/MANIFEST.MF"
- from zipTree(configurations.otel.singleFile)
- from(tasks.shadowJar.archiveFile) {
- into "extensions"
- }
- }
- tasks {
- test {
- useJUnitPlatform()
- inputs.files(layout.files(tasks.shadowJar))
- inputs.files(layout.files(tasks.extendedAgent))
- systemProperty 'io.opentelemetry.smoketest.agentPath', configurations.otel.singleFile.absolutePath
- systemProperty 'io.opentelemetry.smoketest.extendedAgentPath', tasks.extendedAgent.archiveFile.get().asFile.absolutePath
- systemProperty 'io.opentelemetry.smoketest.extensionPath', tasks.shadowJar.archiveFile.get().asFile.absolutePath
- }
- compileJava {
- options.release.set(11)
- }
- assemble.dependsOn(shadowJar)
- }
|