10
10
import static datadog .trace .util .AgentThreadFactory .AgentThread .PROFILER_STARTUP ;
11
11
import static datadog .trace .util .AgentThreadFactory .AgentThread .TRACE_STARTUP ;
12
12
import static datadog .trace .util .AgentThreadFactory .newAgentThread ;
13
- import static datadog .trace .util .Strings .getResourceName ;
14
13
import static datadog .trace .util .Strings .propertyNameToSystemPropertyName ;
15
14
import static datadog .trace .util .Strings .toEnvVar ;
16
15
@@ -348,7 +347,7 @@ public void run() {
348
347
* logging facility. Likewise on IBM JDKs OkHttp may indirectly load 'IBMSASL' which in turn loads LogManager.
349
348
*/
350
349
InstallDatadogTracerCallback installDatadogTracerCallback =
351
- new InstallDatadogTracerCallback (initTelemetry , inst );
350
+ new InstallDatadogTracerCallback (initTelemetry , inst , delayOkHttp );
352
351
if (delayOkHttp ) {
353
352
log .debug ("Custom logger detected. Delaying Datadog Tracer initialization." );
354
353
registerLogManagerCallback (installDatadogTracerCallback );
@@ -497,28 +496,21 @@ public void execute() {
497
496
}
498
497
499
498
protected static class InstallDatadogTracerCallback extends ClassLoadCallBack {
500
- private final InitializationTelemetry initTelemetry ;
501
499
private final Instrumentation instrumentation ;
500
+ private final Object sco ;
501
+ private final Class <?> scoClass ;
502
+ private final boolean delayOkHttp ;
502
503
503
504
public InstallDatadogTracerCallback (
504
- InitializationTelemetry initTelemetry , Instrumentation instrumentation ) {
505
- this .initTelemetry = initTelemetry ;
505
+ InitializationTelemetry initTelemetry ,
506
+ Instrumentation instrumentation ,
507
+ boolean delayOkHttp ) {
508
+ this .delayOkHttp = delayOkHttp ;
506
509
this .instrumentation = instrumentation ;
507
- }
508
-
509
- @ Override
510
- public AgentThread agentThread () {
511
- return TRACE_STARTUP ;
512
- }
513
-
514
- @ Override
515
- public void execute () {
516
- Object sco ;
517
- Class <?> scoClass ;
518
510
try {
519
511
scoClass =
520
512
AGENT_CLASSLOADER .loadClass ("datadog.communication.ddagent.SharedCommunicationObjects" );
521
- sco = scoClass .getConstructor ().newInstance ();
513
+ sco = scoClass .getConstructor (boolean . class ).newInstance (delayOkHttp );
522
514
} catch (ClassNotFoundException
523
515
| NoSuchMethodException
524
516
| InstantiationException
@@ -528,10 +520,23 @@ public void execute() {
528
520
}
529
521
530
522
installDatadogTracer (initTelemetry , scoClass , sco );
523
+ maybeInstallLogsIntake (scoClass , sco );
524
+ }
525
+
526
+ @ Override
527
+ public AgentThread agentThread () {
528
+ return TRACE_STARTUP ;
529
+ }
530
+
531
+ @ Override
532
+ public void execute () {
533
+ if (delayOkHttp ) {
534
+ resumeRemoteComponents ();
535
+ }
536
+
531
537
maybeStartAppSec (scoClass , sco );
532
538
maybeStartIast (instrumentation , scoClass , sco );
533
539
maybeStartCiVisibility (instrumentation , scoClass , sco );
534
- maybeStartLogsIntake (scoClass , sco );
535
540
// start debugger before remote config to subscribe to it before starting to poll
536
541
maybeStartDebugger (instrumentation , scoClass , sco );
537
542
maybeStartRemoteConfig (scoClass , sco );
@@ -540,6 +545,18 @@ public void execute() {
540
545
startTelemetry (instrumentation , scoClass , sco );
541
546
}
542
547
}
548
+
549
+ private void resumeRemoteComponents () {
550
+ try {
551
+ // remote components were paused for custom log-manager/jmx-builder
552
+ // add small delay before resuming remote I/O to help stabilization
553
+ Thread .sleep (1_000 );
554
+ scoClass .getMethod ("resume" ).invoke (sco );
555
+ } catch (InterruptedException ignore ) {
556
+ } catch (Throwable e ) {
557
+ log .error ("Error resuming remote components" , e );
558
+ }
559
+ }
543
560
}
544
561
545
562
protected static class StartProfilingAgentCallback extends ClassLoadCallBack {
@@ -866,17 +883,18 @@ private static void maybeStartCiVisibility(Instrumentation inst, Class<?> scoCla
866
883
}
867
884
}
868
885
869
- private static void maybeStartLogsIntake (Class <?> scoClass , Object sco ) {
886
+ private static void maybeInstallLogsIntake (Class <?> scoClass , Object sco ) {
870
887
if (agentlessLogSubmissionEnabled ) {
871
888
StaticEventLogger .begin ("Logs Intake" );
872
889
873
890
try {
874
891
final Class <?> logsIntakeSystemClass =
875
892
AGENT_CLASSLOADER .loadClass ("datadog.trace.logging.intake.LogsIntakeSystem" );
876
- final Method logsIntakeInstallerMethod = logsIntakeSystemClass .getMethod ("start" , scoClass );
893
+ final Method logsIntakeInstallerMethod =
894
+ logsIntakeSystemClass .getMethod ("install" , scoClass );
877
895
logsIntakeInstallerMethod .invoke (null , sco );
878
896
} catch (final Throwable e ) {
879
- log .warn ("Not starting Logs Intake subsystem" , e );
897
+ log .warn ("Not installing Logs Intake subsystem" , e );
880
898
}
881
899
882
900
StaticEventLogger .end ("Logs Intake" );
@@ -1267,14 +1285,8 @@ private static boolean isAppUsingCustomLogManager(final EnumSet<Library> librari
1267
1285
1268
1286
final String logManagerProp = System .getProperty ("java.util.logging.manager" );
1269
1287
if (logManagerProp != null ) {
1270
- final boolean onSysClasspath =
1271
- ClassLoader .getSystemResource (getResourceName (logManagerProp )) != null ;
1272
1288
log .debug ("Prop - logging.manager: {}" , logManagerProp );
1273
- log .debug ("logging.manager on system classpath: {}" , onSysClasspath );
1274
- // Some applications set java.util.logging.manager but never actually initialize the logger.
1275
- // Check to see if the configured manager is on the system classpath.
1276
- // If so, it should be safe to initialize jmxfetch which will setup the log manager.
1277
- return !onSysClasspath ;
1289
+ return true ;
1278
1290
}
1279
1291
1280
1292
return false ;
@@ -1305,14 +1317,8 @@ private static boolean isAppUsingCustomJMXBuilder(final EnumSet<Library> librari
1305
1317
1306
1318
final String jmxBuilderProp = System .getProperty ("javax.management.builder.initial" );
1307
1319
if (jmxBuilderProp != null ) {
1308
- final boolean onSysClasspath =
1309
- ClassLoader .getSystemResource (getResourceName (jmxBuilderProp )) != null ;
1310
1320
log .debug ("Prop - javax.management.builder.initial: {}" , jmxBuilderProp );
1311
- log .debug ("javax.management.builder.initial on system classpath: {}" , onSysClasspath );
1312
- // Some applications set javax.management.builder.initial but never actually initialize JMX.
1313
- // Check to see if the configured JMX builder is on the system classpath.
1314
- // If so, it should be safe to initialize jmxfetch which will setup JMX.
1315
- return !onSysClasspath ;
1321
+ return true ;
1316
1322
}
1317
1323
1318
1324
return false ;
0 commit comments