instrumentation.gradle 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. apply plugin: 'java'
  2. apply plugin: 'com.github.johnrengelman.shadow'
  3. apply plugin: 'io.opentelemetry.instrumentation.muzzle-generation'
  4. apply plugin: 'io.opentelemetry.instrumentation.muzzle-check'
  5. apply from: "$rootDir/gradle/shadow.gradle"
  6. def relocatePackages = ext.relocatePackages
  7. configurations {
  8. testInstrumentation
  9. testAgent
  10. }
  11. dependencies {
  12. compileOnly("io.opentelemetry:opentelemetry-sdk:${versions.opentelemetry}")
  13. compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:${versions.opentelemetryJavaagent}")
  14. compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
  15. compileOnly deps.bytebuddy
  16. annotationProcessor deps.autoservice
  17. compileOnly deps.autoservice
  18. // the javaagent that is going to be used when running instrumentation unit tests
  19. testAgent(project(path: ":testing:agent-for-testing", configuration: "shadow"))
  20. // test dependencies
  21. testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common:${versions.opentelemetryJavaagentAlpha}")
  22. testImplementation("io.opentelemetry:opentelemetry-sdk-testing:${versions.opentelemetry}")
  23. testImplementation("org.assertj:assertj-core:3.19.0")
  24. add("codegen", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}")
  25. add("muzzleBootstrap", "io.opentelemetry.instrumentation:opentelemetry-instrumentation-annotations-support:${versions.opentelemetryJavaagentAlpha}")
  26. add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${versions.opentelemetryJavaagentAlpha}")
  27. add("muzzleTooling", "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:${versions.opentelemetryJavaagentAlpha}")
  28. }
  29. shadowJar {
  30. configurations = [project.configurations.runtimeClasspath, project.configurations.testInstrumentation]
  31. mergeServiceFiles()
  32. archiveFileName = 'agent-testing.jar'
  33. relocatePackages(it)
  34. }
  35. tasks.withType(Test).configureEach {
  36. inputs.file(shadowJar.archiveFile)
  37. jvmArgs "-Dotel.javaagent.debug=true"
  38. jvmArgs "-javaagent:${configurations.testAgent.files.first().absolutePath}"
  39. jvmArgs "-Dotel.javaagent.experimental.initializer.jar=${shadowJar.archiveFile.get().asFile.absolutePath}"
  40. jvmArgs "-Dotel.javaagent.testing.additional-library-ignores.enabled=false"
  41. jvmArgs "-Dotel.javaagent.testing.fail-on-context-leak=true"
  42. // prevent sporadic gradle deadlocks, see SafeLogger for more details
  43. jvmArgs "-Dotel.javaagent.testing.transform-safe-logging.enabled=true"
  44. jvmArgs "-Dotel.metrics.exporter=otlp"
  45. dependsOn shadowJar
  46. dependsOn configurations.testAgent.buildDependencies
  47. // The sources are packaged into the testing jar so we need to make sure to exclude from the test
  48. // classpath, which automatically inherits them, to ensure our shaded versions are used.
  49. classpath = classpath.filter {
  50. if (it == file("$buildDir/resources/main") || it == file("$buildDir/classes/java/main")) {
  51. return false
  52. }
  53. return true
  54. }
  55. }