Fix double log capture (#299)

This commit is contained in:
Trask Stalnaker 2020-04-01 10:49:45 -07:00 committed by GitHub
parent 64b9585306
commit 10d93ac2a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -85,13 +85,26 @@ public class Log4jSpansInstrumentation extends Instrumenter.Default {
public static class LogMessageAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void methodEnter(
public static boolean methodEnter(
@Advice.This final Logger logger,
@Advice.Argument(1) final Level level,
@Advice.Argument(3) final Message message,
@Advice.Argument(4) final Throwable t) {
// need to track call depth across all loggers in order to avoid double capture when one
// logging framework delegates to another
final boolean topLevel = CallDepthThreadLocalMap.incrementCallDepth("logger") == 0;
if (topLevel) {
Log4jSpans.capture(logger, level, message, t);
}
return topLevel;
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit(@Advice.Enter final boolean topLevel) {
if (topLevel) {
CallDepthThreadLocalMap.reset("logger");
}
}
}
public static class LogAdvice {