build.gradle 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. plugins {
  2. id "java"
  3. /*
  4. Instrumentation agent extension mechanism expects a single jar containing everything required
  5. for your extension. This also includes any external libraries that your extension uses and
  6. cannot access from application classpath (see comment below about `javax.servlet-api` dependency).
  7. Thus we use Shadow Gradle plugin to package our classes and all required runtime dependencies
  8. into a single jar.
  9. See https://imperceptiblethoughts.com/shadow/ for more details about Shadow plugin.
  10. */
  11. id "com.github.johnrengelman.shadow" version "6.1.0"
  12. id "io.opentelemetry.instrumentation.muzzle-generation" version "0.1.0-SNAPSHOT"
  13. }
  14. group 'io.opentelemetry.example'
  15. version '1.0'
  16. ext {
  17. versions = [
  18. opentelemetry : "1.4.1",
  19. opentelemetryAlpha : "1.4.1-alpha",
  20. opentelemetryJavaagent : "1.4.0",
  21. opentelemetryJavaagentAlpha: "1.4.0-alpha",
  22. ]
  23. deps = [
  24. autoservice: dependencies.create(group: 'com.google.auto.service', name: 'auto-service', version: '1.0')
  25. ]
  26. }
  27. repositories {
  28. mavenCentral()
  29. maven {
  30. url = uri("https://oss.sonatype.org/content/repositories/snapshots")
  31. }
  32. }
  33. configurations {
  34. /*
  35. We create a separate gradle configuration to grab a published Otel instrumentation agent.
  36. We don't need the agent during development of this extension module.
  37. This agent is used only during integration test.
  38. */
  39. otel
  40. }
  41. dependencies {
  42. /*
  43. Interfaces and SPIs that we implement. We use `compileOnly` dependency because during
  44. runtime all necessary classes are provided by javaagent itself.
  45. */
  46. compileOnly("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${versions.opentelemetryAlpha}")
  47. compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-instrumentation-api:${versions.opentelemetryJavaagentAlpha}")
  48. compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
  49. //Provides @AutoService annotation that makes registration of our SPI implementations much easier
  50. compileOnly deps.autoservice
  51. annotationProcessor deps.autoservice
  52. /*
  53. Used by our demo instrumentation module to reference classes of the target instrumented library.
  54. We again use `compileOnly` here because during runtime these classes are provided by the
  55. actual application that we instrument.
  56. NB! Only Advice (and "helper") classes of instrumentation modules can access classes from application classpath.
  57. See https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/writing-instrumentation-module.md#advice-classes
  58. */
  59. compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
  60. /*
  61. This dependency is required for DemoSpanProcessor both during compile and runtime.
  62. Only dependencies added to `implementation` configuration will be picked up by Shadow plugin
  63. and added to the resulting jar for our extension's distribution.
  64. */
  65. implementation 'org.apache.commons:commons-lang3:3.11'
  66. //All dependencies below are only for tests
  67. testImplementation("org.testcontainers:testcontainers:1.15.3")
  68. testImplementation("com.fasterxml.jackson.core:jackson-databind:2.11.2")
  69. testImplementation("com.google.protobuf:protobuf-java-util:3.12.4")
  70. testImplementation("com.squareup.okhttp3:okhttp:3.12.12")
  71. testImplementation("io.opentelemetry:opentelemetry-api:${versions.opentelemetry}")
  72. testImplementation("io.opentelemetry:opentelemetry-proto:${versions.opentelemetryAlpha}")
  73. testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2")
  74. testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2")
  75. testRuntimeOnly("ch.qos.logback:logback-classic:1.2.3")
  76. //Otel Java instrumentation that we use and extend during integration tests
  77. otel("io.opentelemetry.javaagent:opentelemetry-javaagent:${versions.opentelemetryJavaagent}:all")
  78. }
  79. //Extracts manifest from OpenTelemetry Java agent to reuse it later
  80. task agentManifest(type: Copy) {
  81. from zipTree(configurations.otel.singleFile).matching {
  82. include 'META-INF/MANIFEST.MF'
  83. }
  84. into buildDir
  85. }
  86. //Produces a copy of upstream javaagent with this extension jar included inside it
  87. //The location of extension directory inside agent jar is hard-coded in the agent source code
  88. task extendedAgent(type: Jar) {
  89. dependsOn agentManifest
  90. archiveFileName = "opentelemetry-javaagent-all.jar"
  91. manifest.from "$buildDir/META-INF/MANIFEST.MF"
  92. from zipTree(configurations.otel.singleFile)
  93. from(tasks.shadowJar.archiveFile) {
  94. into "extensions"
  95. }
  96. }
  97. tasks {
  98. test {
  99. useJUnitPlatform()
  100. inputs.files(layout.files(tasks.shadowJar))
  101. inputs.files(layout.files(tasks.extendedAgent))
  102. systemProperty 'io.opentelemetry.smoketest.agentPath', configurations.otel.singleFile.absolutePath
  103. systemProperty 'io.opentelemetry.smoketest.extendedAgentPath', tasks.extendedAgent.archiveFile.get().asFile.absolutePath
  104. systemProperty 'io.opentelemetry.smoketest.extensionPath', tasks.shadowJar.archiveFile.get().asFile.absolutePath
  105. }
  106. compileJava {
  107. options.release.set(11)
  108. }
  109. assemble.dependsOn(shadowJar)
  110. }