Skip to content

Commit

Permalink
Only call shutdownLogsIntake at shutdown if we called maybeStartLogsI…
Browse files Browse the repository at this point in the history
…ntake at startup. (#7198)

This avoids a ClassNotFoundException when shutting down native images - the native-image won't
contain the LogsIntakeSystem class because it wasn't started when the native-image was built,
therefore we should avoid trying to shut it down unconditionally.
  • Loading branch information
mcculls committed Jun 17, 2024
1 parent 19753bb commit e375af2
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ private enum AgentFeature {
USM(propertyNameToSystemPropertyName(UsmConfig.USM_ENABLED), false),
TELEMETRY(propertyNameToSystemPropertyName(GeneralConfig.TELEMETRY_ENABLED), true),
DEBUGGER(propertyNameToSystemPropertyName(DebuggerConfig.DEBUGGER_ENABLED), false),
DATA_JOBS(propertyNameToSystemPropertyName(GeneralConfig.DATA_JOBS_ENABLED), false);
DATA_JOBS(propertyNameToSystemPropertyName(GeneralConfig.DATA_JOBS_ENABLED), false),
AGENTLESS_LOG_SUBMISSION(
propertyNameToSystemPropertyName(GeneralConfig.AGENTLESS_LOG_SUBMISSION_ENABLED), false);

private final String systemProp;
private final boolean enabledByDefault;
Expand Down Expand Up @@ -145,6 +147,7 @@ public boolean isEnabledByDefault() {
private static boolean usmEnabled = false;
private static boolean telemetryEnabled = true;
private static boolean debuggerEnabled = false;
private static boolean agentlessLogSubmissionEnabled = false;

public static void start(final Instrumentation inst, final URL agentJarURL, String agentArgs) {
StaticEventLogger.begin("Agent");
Expand Down Expand Up @@ -231,6 +234,7 @@ public static void start(final Instrumentation inst, final URL agentJarURL, Stri
cwsEnabled = isFeatureEnabled(AgentFeature.CWS);
telemetryEnabled = isFeatureEnabled(AgentFeature.TELEMETRY);
debuggerEnabled = isFeatureEnabled(AgentFeature.DEBUGGER);
agentlessLogSubmissionEnabled = isFeatureEnabled(AgentFeature.AGENTLESS_LOG_SUBMISSION);

if (profilingEnabled) {
if (!isOracleJDK8()) {
Expand Down Expand Up @@ -362,7 +366,9 @@ public static void shutdown(final boolean sync) {
if (telemetryEnabled) {
stopTelemetry();
}
shutdownLogsIntake();
if (agentlessLogSubmissionEnabled) {
shutdownLogsIntake();
}
}

public static synchronized Class<?> installAgentCLI() throws Exception {
Expand Down Expand Up @@ -801,18 +807,20 @@ private static void maybeStartCiVisibility(Instrumentation inst, Class<?> scoCla
}

private static void maybeStartLogsIntake(Class<?> scoClass, Object sco) {
StaticEventLogger.begin("Logs Intake");
if (agentlessLogSubmissionEnabled) {
StaticEventLogger.begin("Logs Intake");

try {
final Class<?> logsIntakeSystemClass =
AGENT_CLASSLOADER.loadClass("datadog.trace.logging.intake.LogsIntakeSystem");
final Method logsIntakeInstallerMethod = logsIntakeSystemClass.getMethod("start", scoClass);
logsIntakeInstallerMethod.invoke(null, sco);
} catch (final Throwable e) {
log.warn("Not starting Logs Intake subsystem", e);
}
try {
final Class<?> logsIntakeSystemClass =
AGENT_CLASSLOADER.loadClass("datadog.trace.logging.intake.LogsIntakeSystem");
final Method logsIntakeInstallerMethod = logsIntakeSystemClass.getMethod("start", scoClass);
logsIntakeInstallerMethod.invoke(null, sco);
} catch (final Throwable e) {
log.warn("Not starting Logs Intake subsystem", e);
}

StaticEventLogger.end("Logs Intake");
StaticEventLogger.end("Logs Intake");
}
}

private static void shutdownLogsIntake() {
Expand Down

0 comments on commit e375af2

Please sign in to comment.