1- import io.sentry.gradle.ChildJvmTestArguments
1+ import io.sentry.gradle.otelAgentTests
22import net.ltgt.gradle.errorprone.errorprone
33import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
44import org.springframework.boot.gradle.plugin.SpringBootPlugin
@@ -7,6 +7,7 @@ plugins {
77 `java- library`
88 id(" io.sentry.javadoc" )
99 id(" io.sentry.spring-boot-matrix" )
10+ id(" io.sentry.otel-agent-tests" )
1011 alias(libs.plugins.kotlin.jvm)
1112 alias(libs.plugins.kotlin.spring)
1213 alias(libs.plugins.errorprone)
@@ -163,22 +164,7 @@ kotlin {
163164 }
164165}
165166
166- // The OpenTelemetry agent tests run this app in a child JVM, on its own classpath like a real app
167- // with the agent attached, rather than on the test's classpath.
168- val agentFixture = sourceSets.create(" agentFixture" )
169-
170- // The built agent jar, rather than the plain jar the unit tests compile against.
171- val otelAgentJar =
172- configurations.create(" otelAgentJar" ) {
173- isCanBeResolved = true
174- isCanBeConsumed = false
175- isTransitive = false
176- attributes {
177- attribute(Usage .USAGE_ATTRIBUTE , objects.named(Usage .JAVA_RUNTIME ))
178- attribute(Bundling .BUNDLING_ATTRIBUTE , objects.named(Bundling .SHADOWED ))
179- }
180- }
181-
167+ // The app the OpenTelemetry agent tests run in a child JVM.
182168dependencies {
183169 " agentFixtureImplementation" (platform(SpringBootPlugin .BOM_COORDINATES ))
184170 " agentFixtureImplementation" (projects.sentrySpringBoot4Starter)
@@ -201,8 +187,6 @@ dependencies {
201187 " agentFixtureImplementation" (libs.springboot4.starter.webclient)
202188 " agentFixtureImplementation" (libs.springboot4.starter.webflux)
203189 " agentFixtureRuntimeOnly" (libs.hsqldb)
204-
205- otelAgentJar(projects.sentryOpentelemetry.sentryOpentelemetryAgent)
206190}
207191
208192// Swaps Logback for Log4j2 where a classpath has both starters, which only
@@ -337,9 +321,8 @@ testing {
337321 }
338322 }
339323
340- // Runs agentFixture's app with the agent initializing Sentry.
341- register<JvmTestSuite >(" integrationTestOtelAgent" ) {
342- useJUnit()
324+ // The OpenTelemetry agent tests, against agentFixture's app.
325+ named<JvmTestSuite >(" integrationTestOtelAgent" ) {
343326 dependencies {
344327 implementation(platform(SpringBootPlugin .BOM_COORDINATES ))
345328 implementation(projects.sentryTestSupport)
@@ -351,7 +334,6 @@ testing {
351334 implementation(libs.springboot4.starter.test)
352335 implementation(libs.spring.kafka4.test)
353336 }
354- targets.all { testTask.configure { runAgentFixture(autoInit = true ) } }
355337 }
356338
357339 // The servlet app with the OpenTelemetry Spring Boot starter, set up by
@@ -389,37 +371,6 @@ testing {
389371 }
390372}
391373
392- /* *
393- * Has the OpenTelemetry agent tests start agentFixture's app in a child JVM, with the built agent
394- * attached. [autoInit] decides whether the agent initializes Sentry or, as with
395- * `SENTRY_AUTO_INIT=false`, the Spring Boot starter. [appClasspath] is the app's classpath for
396- * another Spring Boot version.
397- */
398- fun Test.runAgentFixture (
399- autoInit : Boolean ,
400- appClasspath : FileCollection = agentFixture.runtimeClasspath,
401- ) {
402- jvmArgumentProviders.add(
403- objects.newInstance<ChildJvmTestArguments >().apply {
404- agentJar.from(otelAgentJar)
405- this .appClasspath.from(appClasspath)
406- }
407- )
408- systemProperty(" sentry.test.agentAutoInit" , autoInit)
409- }
410-
411- // The same tests with the Spring Boot starter initializing Sentry. Each test JVM starts one app, so
412- // this mode needs a task of its own, which Gradle runs in parallel with the suite's.
413- tasks.register<Test >(" integrationTestOtelAgentWithoutAutoInit" ) {
414- description = " Runs the OpenTelemetry agent tests with SENTRY_AUTO_INIT=false."
415- group = LifecycleBasePlugin .VERIFICATION_GROUP
416- val sources = sourceSets[" integrationTestOtelAgent" ]
417- testClassesDirs = sources.output.classesDirs
418- classpath = sources.runtimeClasspath
419- useJUnit()
420- runAgentFixture(autoInit = false )
421- }
422-
423374// The Spring Boot Gradle plugin compiles apps with parameter names, which Spring reads, for example
424375// to resolve `#id` in a cache key.
425376listOf (
@@ -441,10 +392,5 @@ springBootMatrix {
441392 test(" integrationTestWebflux" )
442393 test(" integrationTestOtelNoAgent" )
443394 test(" integrationTestOtlp" )
444- test(" integrationTestOtelAgent" ) { version ->
445- runAgentFixture(autoInit = true , appClasspath = runtimeClasspath(" agentFixture" , version))
446- }
447- test(" integrationTestOtelAgent" , name = " integrationTestOtelAgentWithoutAutoInit" ) { version ->
448- runAgentFixture(autoInit = false , appClasspath = runtimeClasspath(" agentFixture" , version))
449- }
395+ otelAgentTests()
450396}
0 commit comments