33import static datadog .environment .JavaVirtualMachine .isJavaVersionAtLeast ;
44import static datadog .environment .JavaVirtualMachine .isOracleJDK8 ;
55import static datadog .trace .api .ConfigDefaults .DEFAULT_STARTUP_LOGS_ENABLED ;
6+ import static datadog .trace .api .config .GeneralConfig .DATA_JOBS_COMMAND_PATTERN ;
7+ import static datadog .trace .api .config .GeneralConfig .DATA_JOBS_ENABLED ;
68import static datadog .trace .api .telemetry .LogCollector .SEND_TELEMETRY ;
79import static datadog .trace .bootstrap .Library .WILDFLY ;
810import static datadog .trace .bootstrap .Library .detectLibraries ;
11+ import static datadog .trace .bootstrap .config .provider .StableConfigSource .FLEET ;
12+ import static datadog .trace .bootstrap .config .provider .StableConfigSource .LOCAL ;
913import static datadog .trace .util .AgentThreadFactory .AgentThread .JMX_STARTUP ;
1014import static datadog .trace .util .AgentThreadFactory .AgentThread .PROFILER_STARTUP ;
1115import static datadog .trace .util .AgentThreadFactory .AgentThread .TRACE_STARTUP ;
@@ -212,74 +216,11 @@ public static void start(
212216 injectAgentArgsConfig (agentArgs );
213217 }
214218
215- // Retro-compatibility for the old way to configure CI Visibility
216- if ("true" .equals (ddGetProperty ("dd.integration.junit.enabled" ))
217- || "true" .equals (ddGetProperty ("dd.integration.testng.enabled" ))) {
218- setSystemPropertyDefault (AgentFeature .CIVISIBILITY .getSystemProp (), "true" );
219- }
220-
221- ciVisibilityEnabled = isFeatureEnabled (AgentFeature .CIVISIBILITY );
222- if (ciVisibilityEnabled ) {
223- // if CI Visibility is enabled, all the other features are disabled by default
224- // unless the user had explicitly enabled them.
225- setSystemPropertyDefault (AgentFeature .JMXFETCH .getSystemProp (), "false" );
226- setSystemPropertyDefault (AgentFeature .PROFILING .getSystemProp (), "false" );
227- setSystemPropertyDefault (AgentFeature .APPSEC .getSystemProp (), "false" );
228- setSystemPropertyDefault (AgentFeature .IAST .getSystemProp (), "false" );
229- setSystemPropertyDefault (AgentFeature .REMOTE_CONFIG .getSystemProp (), "false" );
230- setSystemPropertyDefault (AgentFeature .CWS .getSystemProp (), "false" );
231-
232- /*if CI Visibility is enabled, the PrioritizationType should be {@code Prioritization.ENSURE_TRACE} */
233- setSystemPropertyDefault (
234- propertyNameToSystemPropertyName (TracerConfig .PRIORITIZATION_TYPE ), "ENSURE_TRACE" );
235-
236- try {
237- setSystemPropertyDefault (
238- propertyNameToSystemPropertyName (CiVisibilityConfig .CIVISIBILITY_AGENT_JAR_URI ),
239- agentJarURL .toURI ().toString ());
240- } catch (URISyntaxException e ) {
241- throw new IllegalArgumentException (
242- "Could not create URI from agent JAR URL: " + agentJarURL , e );
243- }
244- }
245-
246- // Enable automatic fetching of git tags from datadog_git.properties only if CI Visibility is
247- // not enabled
248- if (!ciVisibilityEnabled ) {
249- GitInfoProvider .INSTANCE .registerGitInfoBuilder (new EmbeddedGitInfoBuilder ());
250- }
251-
252- boolean dataJobsEnabled = isFeatureEnabled (AgentFeature .DATA_JOBS );
253- if (dataJobsEnabled ) {
254- log .info ("Data Jobs Monitoring enabled, enabling spark integrations" );
255-
256- setSystemPropertyDefault (
257- propertyNameToSystemPropertyName (TracerConfig .TRACE_LONG_RUNNING_ENABLED ), "true" );
258- setSystemPropertyDefault (
259- propertyNameToSystemPropertyName ("integration.spark.enabled" ), "true" );
260- setSystemPropertyDefault (
261- propertyNameToSystemPropertyName ("integration.spark-executor.enabled" ), "true" );
262- // needed for e2e pipeline
263- setSystemPropertyDefault (propertyNameToSystemPropertyName ("data.streams.enabled" ), "true" );
264- setSystemPropertyDefault (
265- propertyNameToSystemPropertyName ("integration.aws-sdk.enabled" ), "true" );
266- setSystemPropertyDefault (
267- propertyNameToSystemPropertyName ("integration.kafka.enabled" ), "true" );
219+ configureCiVisibility (agentJarURL );
268220
269- if (Config .get ().isDataJobsOpenLineageEnabled ()) {
270- setSystemPropertyDefault (
271- propertyNameToSystemPropertyName ("integration.spark-openlineage.enabled" ), "true" );
272- }
273-
274- String javaCommand = String .join (" " , JavaVirtualMachine .getCommandArguments ());
275- String dataJobsCommandPattern = Config .get ().getDataJobsCommandPattern ();
276- if (!isDataJobsSupported (javaCommand , dataJobsCommandPattern )) {
277- log .warn (
278- "Data Jobs Monitoring is not compatible with non-spark command {} based on command pattern {}. dd-trace-java will not be installed" ,
279- javaCommand ,
280- dataJobsCommandPattern );
281- return ;
282- }
221+ // Halt agent start if DJM is enabled and is not successfully configure
222+ if (!configureDataJobsMonitoring ()) {
223+ return ;
283224 }
284225
285226 if (!isSupportedAppSecArch ()) {
@@ -446,6 +387,43 @@ public static void start(
446387 StaticEventLogger .end ("Agent.start" );
447388 }
448389
390+ private static boolean configureDataJobsMonitoring () {
391+ boolean dataJobsEnabled = isFeatureEnabled (AgentFeature .DATA_JOBS );
392+ if (dataJobsEnabled ) {
393+ log .info ("Data Jobs Monitoring enabled, enabling spark integrations" );
394+
395+ setSystemPropertyDefault (
396+ propertyNameToSystemPropertyName (TracerConfig .TRACE_LONG_RUNNING_ENABLED ), "true" );
397+ setSystemPropertyDefault (
398+ propertyNameToSystemPropertyName ("integration.spark.enabled" ), "true" );
399+ setSystemPropertyDefault (
400+ propertyNameToSystemPropertyName ("integration.spark-executor.enabled" ), "true" );
401+ // needed for e2e pipeline
402+ setSystemPropertyDefault (propertyNameToSystemPropertyName ("data.streams.enabled" ), "true" );
403+ setSystemPropertyDefault (
404+ propertyNameToSystemPropertyName ("integration.aws-sdk.enabled" ), "true" );
405+ setSystemPropertyDefault (
406+ propertyNameToSystemPropertyName ("integration.kafka.enabled" ), "true" );
407+
408+ if ("true" .equals (ddGetProperty (propertyNameToSystemPropertyName (DATA_JOBS_ENABLED )))) {
409+ setSystemPropertyDefault (
410+ propertyNameToSystemPropertyName ("integration.spark-openlineage.enabled" ), "true" );
411+ }
412+
413+ String javaCommand = String .join (" " , JavaVirtualMachine .getCommandArguments ());
414+ String dataJobsCommandPattern =
415+ ddGetProperty (propertyNameToSystemPropertyName (DATA_JOBS_COMMAND_PATTERN ));
416+ if (!isDataJobsSupported (javaCommand , dataJobsCommandPattern )) {
417+ log .warn (
418+ "Data Jobs Monitoring is not compatible with non-spark command {} based on command pattern {}. dd-trace-java will not be installed" ,
419+ javaCommand ,
420+ dataJobsCommandPattern );
421+ return false ;
422+ }
423+ }
424+ return true ;
425+ }
426+
449427 private static void injectAgentArgsConfig (String agentArgs ) {
450428 try {
451429 final Class <?> agentArgsInjectorClass =
@@ -458,6 +436,45 @@ private static void injectAgentArgsConfig(String agentArgs) {
458436 }
459437 }
460438
439+ private static void configureCiVisibility (URL agentJarURL ) {
440+ // Retro-compatibility for the old way to configure CI Visibility
441+ if ("true" .equals (ddGetProperty ("dd.integration.junit.enabled" ))
442+ || "true" .equals (ddGetProperty ("dd.integration.testng.enabled" ))) {
443+ setSystemPropertyDefault (AgentFeature .CIVISIBILITY .getSystemProp (), "true" );
444+ }
445+
446+ ciVisibilityEnabled = isFeatureEnabled (AgentFeature .CIVISIBILITY );
447+ if (ciVisibilityEnabled ) {
448+ // if CI Visibility is enabled, all the other features are disabled by default
449+ // unless the user had explicitly enabled them.
450+ setSystemPropertyDefault (AgentFeature .JMXFETCH .getSystemProp (), "false" );
451+ setSystemPropertyDefault (AgentFeature .PROFILING .getSystemProp (), "false" );
452+ setSystemPropertyDefault (AgentFeature .APPSEC .getSystemProp (), "false" );
453+ setSystemPropertyDefault (AgentFeature .IAST .getSystemProp (), "false" );
454+ setSystemPropertyDefault (AgentFeature .REMOTE_CONFIG .getSystemProp (), "false" );
455+ setSystemPropertyDefault (AgentFeature .CWS .getSystemProp (), "false" );
456+
457+ /*if CI Visibility is enabled, the PrioritizationType should be {@code Prioritization.ENSURE_TRACE} */
458+ setSystemPropertyDefault (
459+ propertyNameToSystemPropertyName (TracerConfig .PRIORITIZATION_TYPE ), "ENSURE_TRACE" );
460+
461+ try {
462+ setSystemPropertyDefault (
463+ propertyNameToSystemPropertyName (CiVisibilityConfig .CIVISIBILITY_AGENT_JAR_URI ),
464+ agentJarURL .toURI ().toString ());
465+ } catch (URISyntaxException e ) {
466+ throw new IllegalArgumentException (
467+ "Could not create URI from agent JAR URL: " + agentJarURL , e );
468+ }
469+ }
470+
471+ // Enable automatic fetching of git tags from datadog_git.properties only if CI Visibility is
472+ // not enabled
473+ if (!ciVisibilityEnabled ) {
474+ GitInfoProvider .INSTANCE .registerGitInfoBuilder (new EmbeddedGitInfoBuilder ());
475+ }
476+ }
477+
461478 public static void shutdown (final boolean sync ) {
462479 StaticEventLogger .end ("Agent" );
463480 StaticEventLogger .stop ();
@@ -1401,13 +1418,13 @@ private static boolean isFeatureEnabled(AgentFeature feature) {
14011418 final String featureSystemProp = feature .getSystemProp ();
14021419 String featureEnabled = SystemProperties .get (featureSystemProp );
14031420 if (featureEnabled == null ) {
1404- featureEnabled = getStableConfig (StableConfigSource . FLEET , featureConfigKey );
1421+ featureEnabled = getStableConfig (FLEET , featureConfigKey );
14051422 }
14061423 if (featureEnabled == null ) {
14071424 featureEnabled = ddGetEnv (featureSystemProp );
14081425 }
14091426 if (featureEnabled == null ) {
1410- featureEnabled = getStableConfig (StableConfigSource . LOCAL , featureConfigKey );
1427+ featureEnabled = getStableConfig (LOCAL , featureConfigKey );
14111428 }
14121429
14131430 if (feature .isEnabledByDefault ()) {
@@ -1431,13 +1448,13 @@ private static boolean isFullyDisabled(final AgentFeature feature) {
14311448 final String featureSystemProp = feature .getSystemProp ();
14321449 String settingValue = getNullIfEmpty (SystemProperties .get (featureSystemProp ));
14331450 if (settingValue == null ) {
1434- settingValue = getNullIfEmpty (getStableConfig (StableConfigSource . FLEET , featureConfigKey ));
1451+ settingValue = getNullIfEmpty (getStableConfig (FLEET , featureConfigKey ));
14351452 }
14361453 if (settingValue == null ) {
14371454 settingValue = getNullIfEmpty (ddGetEnv (featureSystemProp ));
14381455 }
14391456 if (settingValue == null ) {
1440- settingValue = getNullIfEmpty (getStableConfig (StableConfigSource . LOCAL , featureConfigKey ));
1457+ settingValue = getNullIfEmpty (getStableConfig (LOCAL , featureConfigKey ));
14411458 }
14421459
14431460 // defaults to inactive
0 commit comments