Skip to content

Commit

Permalink
Support turning on debug after the native image has been built
Browse files Browse the repository at this point in the history
  • Loading branch information
mcculls committed Dec 18, 2022
1 parent 376c9c2 commit 7dae46f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dd-java-agent/instrumentation/graal/native-image/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ apply plugin: "idea"
}

dependencies {
compileOnly project(':dd-java-agent:agent-logging')

main_java11CompileOnly group: 'org.graalvm.nativeimage', name: 'svm', version: '20.0.0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.Config;
import datadog.trace.logging.GlobalLogLevelSwitcher;
import datadog.trace.logging.LogLevel;
import net.bytebuddy.asm.Advice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@AutoService(Instrumenter.class)
public final class VMRuntimeInstrumentation extends AbstractNativeImageInstrumentation
Expand Down Expand Up @@ -36,6 +41,16 @@ public boolean injectHelperDependencies() {
public static class InitializeAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void onEnter() {
if (Config.get().isDebugEnabled()) {
// was this native image originally built with debug off?
Logger configLogger = LoggerFactory.getLogger(Config.class);
if (!configLogger.isDebugEnabled()) {
// patch logger level and re-log configuration details
GlobalLogLevelSwitcher.get().switchLevel(LogLevel.DEBUG);
configLogger.debug("New instance: {}", Config.get());
}
}

datadog.trace.agent.tooling.nativeimage.TracerActivation.activate();
}
}
Expand Down

0 comments on commit 7dae46f

Please sign in to comment.