diff --git a/.github/instructions/instrumentation-gradle.instructions.md b/.github/instructions/instrumentation-gradle.instructions.md index f2a49879abe8..7c327a991d87 100644 --- a/.github/instructions/instrumentation-gradle.instructions.md +++ b/.github/instructions/instrumentation-gradle.instructions.md @@ -52,10 +52,13 @@ or test failure that CI will report. of the same coordinate does not test both versions: Gradle resolves one dependency graph, normally selecting the higher version. Exercise the newer runtime in a wired version-specific test suite. -- Inspect test sources before requiring `testcontainersBuildService`: declare `usesService` - on tasks that really use containers, not every task with a transitive dependency. Use - `withType().configureEach` for configuration shared by multiple explicitly declared - test tasks; not for a module with only `tasks.test` (implicit `latestDepTest` does not count). +- Inspect test sources before requiring `testcontainersBuildService`; a transitive dependency + alone is not enough. In projects that use Testcontainers, register it once for all test tasks, + including container-free variants. Narrower registration requires a demonstrated scheduling + problem. +- Prefer `tasks.test` for single-test-task projects. Use `withType().configureEach` for + configuration shared by multiple explicitly declared test tasks or JVM test suites. + Implicit `latestDepTest` does not count. Keep unrelated JVM settings and properties scoped. - Check metadata collection when its wiring or collected telemetry changes, not as unrelated cleanup. Collect default telemetry and supported non-default telemetry modes. Register representative tasks in `.github/scripts/instrumentations.sh` covering each profile's diff --git a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/build.gradle.kts b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/build.gradle.kts index 15c5cff8a634..4d2b4ce61bb6 100644 --- a/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/build.gradle.kts +++ b/instrumentation/aws-sdk/aws-sdk-2.2/javaagent/build.gradle.kts @@ -137,14 +137,6 @@ testing { implementation(project(":instrumentation:aws-sdk:aws-sdk-2.2:library")) implementation("org.testcontainers:testcontainers-localstack") } - - targets { - all { - testTask.configure { - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) - } - } - } } register("testBedrockRuntime") { @@ -193,6 +185,7 @@ tasks { } withType().configureEach { + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) systemProperty("testLatestDeps", otelProps.testLatestDeps) } diff --git a/instrumentation/jms/jms-1.1/javaagent/build.gradle.kts b/instrumentation/jms/jms-1.1/javaagent/build.gradle.kts index de8f0606037b..5900332e8bea 100644 --- a/instrumentation/jms/jms-1.1/javaagent/build.gradle.kts +++ b/instrumentation/jms/jms-1.1/javaagent/build.gradle.kts @@ -55,7 +55,7 @@ testing { } tasks { - test { + withType().configureEach { usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } diff --git a/instrumentation/jmx-metrics/library/build.gradle.kts b/instrumentation/jmx-metrics/library/build.gradle.kts index 70c2b0a4b788..0b2c3e20fed2 100644 --- a/instrumentation/jmx-metrics/library/build.gradle.kts +++ b/instrumentation/jmx-metrics/library/build.gradle.kts @@ -72,7 +72,6 @@ tasks { filter { includeTestsMatching(testClass) } - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } } @@ -81,6 +80,8 @@ tasks { } withType().configureEach { + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) + // the base agent only contains the agent machinery and the internal instrumentations that it // requires, the JMX instrumentation is added on top of it. Using the full agent would capture // telemetry from the target systems that is unrelated to JMX metrics. diff --git a/instrumentation/kafka/kafka-streams-0.11/javaagent/build.gradle.kts b/instrumentation/kafka/kafka-streams-0.11/javaagent/build.gradle.kts index 8d949e24f421..556f630e640f 100644 --- a/instrumentation/kafka/kafka-streams-0.11/javaagent/build.gradle.kts +++ b/instrumentation/kafka/kafka-streams-0.11/javaagent/build.gradle.kts @@ -43,11 +43,8 @@ testing { tasks { withType().configureEach { - if (name != "unitTests") { - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) - - systemProperty("testLatestDeps", otelProps.testLatestDeps) - } + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) + systemProperty("testLatestDeps", otelProps.testLatestDeps) } val testReceiveSpansDisabled = register("testReceiveSpansDisabled") { diff --git a/instrumentation/reactor/reactor-kafka-1.0/javaagent/build.gradle.kts b/instrumentation/reactor/reactor-kafka-1.0/javaagent/build.gradle.kts index eaa1c45842ee..9bc0b340b803 100644 --- a/instrumentation/reactor/reactor-kafka-1.0/javaagent/build.gradle.kts +++ b/instrumentation/reactor/reactor-kafka-1.0/javaagent/build.gradle.kts @@ -121,9 +121,7 @@ testing { tasks { withType().configureEach { - if (!name.endsWith("unitTests", ignoreCase = true)) { - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) - } + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } val agentTestSuites = testing.suites.withType(JvmTestSuite::class) diff --git a/instrumentation/spring/spring-integration-4.1/javaagent/build.gradle.kts b/instrumentation/spring/spring-integration-4.1/javaagent/build.gradle.kts index 989e85a5e821..c1afcc90930c 100644 --- a/instrumentation/spring/spring-integration-4.1/javaagent/build.gradle.kts +++ b/instrumentation/spring/spring-integration-4.1/javaagent/build.gradle.kts @@ -136,10 +136,8 @@ tasks { } withType().configureEach { + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) systemProperty("testLatestDeps", otelProps.testLatestDeps) - if (name != "version41Test") { - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) - } } } diff --git a/instrumentation/spring/spring-integration-4.1/library/build.gradle.kts b/instrumentation/spring/spring-integration-4.1/library/build.gradle.kts index 8aebff333541..54cfbb3c1864 100644 --- a/instrumentation/spring/spring-integration-4.1/library/build.gradle.kts +++ b/instrumentation/spring/spring-integration-4.1/library/build.gradle.kts @@ -36,9 +36,12 @@ testing { } tasks { + withType().configureEach { + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) + } + test { systemProperty("testLatestDeps", otelProps.testLatestDeps) - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } check { dependsOn(testing.suites) diff --git a/instrumentation/spring/spring-jms/spring-jms-6.0/javaagent/build.gradle.kts b/instrumentation/spring/spring-jms/spring-jms-6.0/javaagent/build.gradle.kts index 7d85db64a2aa..c2432f1b414f 100644 --- a/instrumentation/spring/spring-jms/spring-jms-6.0/javaagent/build.gradle.kts +++ b/instrumentation/spring/spring-jms/spring-jms-6.0/javaagent/build.gradle.kts @@ -70,7 +70,6 @@ tasks { val testJmsDisabled = register("testJmsDisabled") { testClassesDirs = sourceSets.test.get().output.classesDirs classpath = sourceSets.test.get().runtimeClasspath - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) filter { includeTestsMatching("*.testSpringJmsListenerWithJmsDisabled") } diff --git a/instrumentation/spring/spring-rabbit-1.1/javaagent/build.gradle.kts b/instrumentation/spring/spring-rabbit-1.1/javaagent/build.gradle.kts index 0b4b3d38799e..1dca263a4b1f 100644 --- a/instrumentation/spring/spring-rabbit-1.1/javaagent/build.gradle.kts +++ b/instrumentation/spring/spring-rabbit-1.1/javaagent/build.gradle.kts @@ -59,11 +59,7 @@ testing { tasks { withType().configureEach { - if (!name.endsWith("unitTests", ignoreCase = true)) { - if (name != "testSpringDisabled") { - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) - } - } + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) systemProperty("testLatestDeps", otelProps.testLatestDeps) // add byte buddy agent for mockito diff --git a/instrumentation/vertx/vertx-sql-client/vertx-sql-client-5.0/javaagent/build.gradle.kts b/instrumentation/vertx/vertx-sql-client/vertx-sql-client-5.0/javaagent/build.gradle.kts index 1c515a2ba052..b24e073d81d5 100644 --- a/instrumentation/vertx/vertx-sql-client/vertx-sql-client-5.0/javaagent/build.gradle.kts +++ b/instrumentation/vertx/vertx-sql-client/vertx-sql-client-5.0/javaagent/build.gradle.kts @@ -61,12 +61,10 @@ testing { } tasks { - withType() - .matching { it.name != "unitTests" } - .configureEach { - usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) - systemProperty("testLatestDeps", otelProps.testLatestDeps) - } + withType().configureEach { + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) + systemProperty("testLatestDeps", otelProps.testLatestDeps) + } val testPreviewSemconv = register("testPreviewSemconv") { testClassesDirs = sourceSets.test.get().output.classesDirs