-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tracer logging when instrumenting Gradle Daemon (#6080)
- Loading branch information
1 parent
8f42a2c
commit 9824b2e
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../main/groovy/datadog/trace/instrumentation/gradle/GradleDaemonLoggingInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package datadog.trace.instrumentation.gradle; | ||
|
||
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.logging.GlobalLogLevelSwitcher; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
@AutoService(Instrumenter.class) | ||
public class GradleDaemonLoggingInstrumentation extends Instrumenter.CiVisibility | ||
implements Instrumenter.ForSingleType { | ||
|
||
public GradleDaemonLoggingInstrumentation() { | ||
super("gradle", "gradle-daemon-logging"); | ||
} | ||
|
||
@Override | ||
public String instrumentedType() { | ||
return "org.gradle.launcher.daemon.bootstrap.DaemonMain"; | ||
} | ||
|
||
@Override | ||
public void adviceTransformations(AdviceTransformation transformation) { | ||
transformation.applyAdvice( | ||
named("initialiseLogging"), | ||
GradleDaemonLoggingInstrumentation.class.getName() + "$ReinitialiseLogging"); | ||
} | ||
|
||
/** | ||
* Gradle Daemon closes original {@link System.out} and {@link System.err} streams (see {@link | ||
* org.gradle.launcher.daemon.bootstrap.DaemonMain#daemonStarted}), and replaces them with Gradle | ||
* Daemon log streams (see {@link | ||
* org.gradle.launcher.daemon.bootstrap.DaemonMain#initialiseLogging}). | ||
* | ||
* <p>{@link datadog.trace.logging.simplelogger.SLCompatFactory} that contains logging settings | ||
* gets initialized before Gradle Daemon, so DD logging settings refer to the original streams | ||
* that the daemon closes. They need to refer to the new streams created by the daemon, so here we | ||
* reset the settings letting them re-initialize to capture the new streams. | ||
*/ | ||
public static class ReinitialiseLogging { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void reinitialiseTracerLogging() { | ||
GlobalLogLevelSwitcher.get().reinitialize(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters