@@ -75,7 +75,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
7575 def agentArgs = jacocoCoverage ? [
7676 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_JACOCO_PLUGIN_VERSION)} =${ JACOCO_PLUGIN_VERSION} " as String
7777 ] : []
78- def exitCode = whenRunningMavenBuild(agentArgs, commandLineParams)
78+ def exitCode = whenRunningMavenBuild(agentArgs, commandLineParams, [:] )
7979
8080 if (expectSuccess) {
8181 assert exitCode == 0
@@ -118,7 +118,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
118118 def exitCode = whenRunningMavenBuild([
119119 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_GIT_CLIENT_ENABLED)} =false" as String ,
120120 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_IMPACTED_TESTS_BACKEND_REQUEST_ENABLED)} =true" as String
121- ], [])
121+ ], [], [:] )
122122 assert exitCode == 0
123123
124124 verifyEventsAndCoverages(projectName, " maven" , mavenVersion, mockBackend. waitForEvents(5 ), mockBackend. waitForCoverages(1 ))
@@ -143,7 +143,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
143143
144144 mockBackend. givenAttemptToFixTests(" Maven Smoke Tests Project maven-surefire-plugin default-test" , " datadog.smoke.TestFailed" , " test_another_failed" )
145145
146- def exitCode = whenRunningMavenBuild([], [])
146+ def exitCode = whenRunningMavenBuild([], [], [:] )
147147 assert exitCode == 0
148148
149149 verifyEventsAndCoverages(projectName, " maven" , mavenVersion, mockBackend. waitForEvents(15 ), mockBackend. waitForCoverages(6 ))
@@ -228,6 +228,22 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
228228 ] | 12
229229 }
230230
231+ def " test service name is propagated to child processes" () {
232+ givenWrapperPropertiesFile(mavenVersion)
233+ givenMavenProjectFiles(projectName)
234+ givenMavenDependenciesAreLoaded(projectName, mavenVersion)
235+
236+ def exitCode = whenRunningMavenBuild([], [], [:], false )
237+ assert exitCode == 0
238+
239+ def additionalDynamicPaths = [" content.service" ]
240+ verifyEventsAndCoverages(projectName, " maven" , mavenVersion, mockBackend. waitForEvents(5 ), mockBackend. waitForCoverages(1 ), additionalDynamicPaths)
241+
242+ where :
243+ projectName | mavenVersion
244+ " test_successful_maven_run_child_service_propagation" | " 3.9.9"
245+ }
246+
231247 private void givenWrapperPropertiesFile (String mavenVersion ) {
232248 def distributionUrl = " https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${ mavenVersion} /apache-maven-${ mavenVersion} -bin.zip"
233249
@@ -291,7 +307,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
291307 private static final Collection<String > LOADED_DEPENDENCIES = new HashSet<> ()
292308
293309 private void retryUntilSuccessfulOrNoAttemptsLeft (List<String > mvnCommand , Map<String , String > additionalEnvVars = [:]) {
294- def processBuilder = createProcessBuilder(mvnCommand, false , [], additionalEnvVars)
310+ def processBuilder = createProcessBuilder(mvnCommand, false , false , [], additionalEnvVars)
295311 for (int attempt = 0 ; attempt < DEPENDENCIES_DOWNLOAD_RETRIES ; attempt++ ) {
296312 def exitCode = runProcess(processBuilder. start())
297313 if (exitCode == 0 ) {
@@ -301,8 +317,8 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
301317 throw new AssertionError ((Object ) " Tried $DEPENDENCIES_DOWNLOAD_RETRIES times to execute $mvnCommand and failed" )
302318 }
303319
304- private int whenRunningMavenBuild (List<String > additionalAgentArgs , List<String > additionalCommandLineParams , Map<String , String > additionalEnvVars = [:] ) {
305- def processBuilder = createProcessBuilder([" -B" , " test" ] + additionalCommandLineParams, true , additionalAgentArgs, additionalEnvVars)
320+ private int whenRunningMavenBuild (List<String > additionalAgentArgs , List<String > additionalCommandLineParams , Map<String , String > additionalEnvVars , boolean setServiceName = true ) {
321+ def processBuilder = createProcessBuilder([" -B" , " test" ] + additionalCommandLineParams, true , setServiceName, additionalAgentArgs, additionalEnvVars)
306322
307323 processBuilder. environment(). put(" DD_API_KEY" , " 01234567890abcdef123456789ABCDEF" )
308324
@@ -323,13 +339,13 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
323339 return p. exitValue()
324340 }
325341
326- ProcessBuilder createProcessBuilder (List<String > mvnCommand , boolean runWithAgent , List<String > additionalAgentArgs , Map<String , String > additionalEnvVars ) {
342+ ProcessBuilder createProcessBuilder (List<String > mvnCommand , boolean runWithAgent , boolean setServiceName , List<String > additionalAgentArgs , Map<String , String > additionalEnvVars ) {
327343 String mavenRunnerShadowJar = System . getProperty(" datadog.smoketest.maven.jar.path" )
328344 assert new File (mavenRunnerShadowJar). isFile()
329345
330346 List<String > command = new ArrayList<> ()
331347 command. add(javaPath())
332- command. addAll(jvmArguments(runWithAgent, additionalAgentArgs))
348+ command. addAll(jvmArguments(runWithAgent, setServiceName, additionalAgentArgs))
333349 command. addAll((String []) [" -jar" , mavenRunnerShadowJar])
334350 command. addAll(programArguments())
335351 command. addAll(mvnCommand)
@@ -350,7 +366,7 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
350366 return System . getProperty(" java.home" ) + separator + " bin" + separator + " java"
351367 }
352368
353- List<String > jvmArguments (boolean runWithAgent , List<String > additionalAgentArgs ) {
369+ List<String > jvmArguments (boolean runWithAgent , boolean setServiceName , List<String > additionalAgentArgs ) {
354370 def arguments = [
355371 " -D${ MavenWrapperMain.MVNW_VERBOSE} =true" . toString(),
356372 " -Duser.dir=${ projectHome.toAbsolutePath()} " . toString(),
@@ -368,7 +384,6 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
368384 (System . getenv(" DD_CIVISIBILITY_SMOKETEST_DEBUG_CHILD" ) != null ? " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_DEBUG_PORT)} =5055," : " " ) +
369385 " ${ Strings.propertyNameToSystemPropertyName(GeneralConfig.TRACE_DEBUG)} =true," +
370386 " ${ Strings.propertyNameToSystemPropertyName(GeneralConfig.ENV)} =${ TEST_ENVIRONMENT_NAME} ," +
371- " ${ Strings.propertyNameToSystemPropertyName(GeneralConfig.SERVICE_NAME)} =${ TEST_SERVICE_NAME} ," +
372387 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_ENABLED)} =true," +
373388 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_ENABLED)} =true," +
374389 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_CIPROVIDER_INTEGRATION_ENABLED)} =false," +
@@ -377,6 +392,10 @@ class MavenSmokeTest extends CiVisibilitySmokeTest {
377392 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_AGENTLESS_URL)} =${ mockBackend.intakeUrl} ," +
378393 " ${ Strings.propertyNameToSystemPropertyName(CiVisibilityConfig.CIVISIBILITY_FLAKY_RETRY_ONLY_KNOWN_FLAKES)} =true,"
379394
395+ if (setServiceName) {
396+ agentArgument + = " ${ Strings.propertyNameToSystemPropertyName(GeneralConfig.SERVICE_NAME)} =${ TEST_SERVICE_NAME} ,"
397+ }
398+
380399 agentArgument + = additionalAgentArgs. join(" ," )
381400
382401 arguments + = agentArgument. toString()
0 commit comments