|
3 | 3 | import static datadog.trace.api.ConfigDefaults.DEFAULT_STARTUP_LOGS_ENABLED;
|
4 | 4 | import static datadog.trace.api.Platform.isJavaVersionAtLeast;
|
5 | 5 | import static datadog.trace.api.Platform.isOracleJDK8;
|
| 6 | +import static datadog.trace.api.telemetry.LogCollector.SEND_TELEMETRY; |
6 | 7 | import static datadog.trace.bootstrap.Library.WILDFLY;
|
7 | 8 | import static datadog.trace.bootstrap.Library.detectLibraries;
|
8 | 9 | import static datadog.trace.util.AgentThreadFactory.AgentThread.JMX_STARTUP;
|
|
44 | 45 | import datadog.trace.util.AgentTaskScheduler;
|
45 | 46 | import datadog.trace.util.AgentThreadFactory.AgentThread;
|
46 | 47 | import datadog.trace.util.throwable.FatalAgentMisconfigurationError;
|
| 48 | +import de.thetaphi.forbiddenapis.SuppressForbidden; |
47 | 49 | import java.lang.instrument.Instrumentation;
|
48 | 50 | import java.lang.reflect.InvocationTargetException;
|
49 | 51 | import java.lang.reflect.Method;
|
@@ -291,6 +293,8 @@ public static void start(
|
291 | 293 | codeOriginEnabled = isFeatureEnabled(AgentFeature.CODE_ORIGIN);
|
292 | 294 | agentlessLogSubmissionEnabled = isFeatureEnabled(AgentFeature.AGENTLESS_LOG_SUBMISSION);
|
293 | 295 |
|
| 296 | + patchJPSAccess(inst); |
| 297 | + |
294 | 298 | if (profilingEnabled) {
|
295 | 299 | if (!isOracleJDK8()) {
|
296 | 300 | // Profiling agent startup code is written in a way to allow `startProfilingAgent` be called
|
@@ -420,6 +424,23 @@ private static void injectAgentArgsConfig(String agentArgs) {
|
420 | 424 | }
|
421 | 425 | }
|
422 | 426 |
|
| 427 | + @SuppressForbidden |
| 428 | + public static void patchJPSAccess(Instrumentation inst) { |
| 429 | + if (Platform.isJavaVersionAtLeast(9)) { |
| 430 | + // Unclear if supported for J9, may need to revisit |
| 431 | + try { |
| 432 | + Class.forName("datadog.trace.util.JPMSJPSAccess") |
| 433 | + .getMethod("patchModuleAccess", Instrumentation.class) |
| 434 | + .invoke(null, inst); |
| 435 | + } catch (Exception e) { |
| 436 | + log.debug( |
| 437 | + SEND_TELEMETRY, |
| 438 | + "Failed to patch module access for jvmstat and Java version " |
| 439 | + + Platform.getRuntimeVersion()); |
| 440 | + } |
| 441 | + } |
| 442 | + } |
| 443 | + |
423 | 444 | public static void shutdown(final boolean sync) {
|
424 | 445 | StaticEventLogger.end("Agent");
|
425 | 446 | StaticEventLogger.stop();
|
|
0 commit comments