Fix duplicate log capture, part 2 (#554)

This commit is contained in:
Trask Stalnaker 2020-06-22 01:13:36 -07:00 committed by GitHub
parent 7b06e2fb7a
commit 9dcb079aa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.google.auto.service.AutoService;
import io.opentelemetry.auto.bootstrap.CallDepthThreadLocalMap;
import io.opentelemetry.auto.bootstrap.instrumentation.logging.LoggerDepth;
import io.opentelemetry.auto.tooling.Instrumenter;
import java.util.HashMap;
import java.util.Map;
@ -80,7 +81,7 @@ public class JavaUtilLoggingSpansInstrumentation extends Instrumenter.Default {
@Advice.This final Logger logger, @Advice.Argument(0) final LogRecord logRecord) {
// 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.class) == 0;
final boolean topLevel = CallDepthThreadLocalMap.incrementCallDepth(LoggerDepth.class) == 0;
if (topLevel) {
JavaUtilLoggingSpans.capture(logger, logRecord);
}
@ -90,7 +91,7 @@ public class JavaUtilLoggingSpansInstrumentation extends Instrumenter.Default {
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit(@Advice.Enter final boolean topLevel) {
if (topLevel) {
CallDepthThreadLocalMap.reset(Logger.class);
CallDepthThreadLocalMap.reset(LoggerDepth.class);
}
}
}