Reduce debug logging
MODIFY
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/TransformSafeLogger.java
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/TransformSafeLogger.java
package io.opentelemetry.javaagent.tooling;
+import static org.slf4j.event.Level.DEBUG;
+import static org.slf4j.event.Level.TRACE;
+
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.event.Level;
/**
* Debug logging that is performed under class file transform needs to use this class, because
@@ -49,7 +53,7 @@ public class TransformSafeLogger {
public void debug(String format, Object arg) {
if (logMessageQueue != null) {
- logMessageQueue.offer(new LogMessage(logger, format, arg));
+ logMessageQueue.offer(new LogMessage(DEBUG, logger, format, arg));
} else {
logger.debug(format, arg);
}
@@ -57,7 +61,7 @@ public class TransformSafeLogger {
public void debug(String format, Object arg1, Object arg2) {
if (logMessageQueue != null) {
- logMessageQueue.offer(new LogMessage(logger, format, arg1, arg2));
+ logMessageQueue.offer(new LogMessage(DEBUG, logger, format, arg1, arg2));
} else {
logger.debug(format, arg1, arg2);
}
@@ -65,7 +69,7 @@ public class TransformSafeLogger {
public void debug(String format, Object... arguments) {
if (logMessageQueue != null) {
- logMessageQueue.offer(new LogMessage(logger, format, arguments));
+ logMessageQueue.offer(new LogMessage(DEBUG, logger, format, arguments));
} else {
logger.debug(format, arguments);
}
@@ -75,13 +79,48 @@ public class TransformSafeLogger {
return logger.isDebugEnabled();
}
+ public void trace(String format, Object arg) {
+ if (logMessageQueue != null) {
+ logMessageQueue.offer(new LogMessage(TRACE, logger, format, arg));
+ } else {
+ logger.trace(format, arg);
+ }
+ }
+
+ public void trace(String format, Object arg1, Object arg2) {
+ if (logMessageQueue != null) {
+ logMessageQueue.offer(new LogMessage(TRACE, logger, format, arg1, arg2));
+ } else {
+ logger.trace(format, arg1, arg2);
+ }
+ }
+
+ public void trace(String format, Object... arguments) {
+ if (logMessageQueue != null) {
+ logMessageQueue.offer(new LogMessage(TRACE, logger, format, arguments));
+ } else {
+ logger.trace(format, arguments);
+ }
+ }
+
+ public boolean isTraceEnabled() {
+ return logger.isTraceEnabled();
+ }
+
private static class LogMessageQueueReader implements Runnable {
@Override
public void run() {
try {
while (true) {
LogMessage logMessage = logMessageQueue.take();
+ if (logMessage.level == DEBUG) {
logMessage.logger.debug(logMessage.format, logMessage.arguments);
+ } else if (logMessage.level == TRACE) {
+ logMessage.logger.trace(logMessage.format, logMessage.arguments);
+ } else {
+ logMessage.logger.warn(
+ "level {} not implemented yet in TransformSafeLogger", logMessage.level);
+ }
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
@@ -90,11 +129,13 @@ public class TransformSafeLogger {
}
private static class LogMessage {
+ private final Level level;
private final Logger logger;
private final String format;
private final Object[] arguments;
- private LogMessage(Logger logger, String format, Object... arguments) {
+ private LogMessage(Level level, Logger logger, String format, Object... arguments) {
+ this.level = level;
this.logger = logger;
this.format = format;
this.arguments = arguments;

MODIFY
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/context/FieldBackedProvider.java
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/context/FieldBackedProvider.java
@@ -198,7 +198,7 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
.equals(owner)
&& CONTEXT_GET_METHOD.getName().equals(name)
&& Type.getMethodDescriptor(CONTEXT_GET_METHOD).equals(descriptor)) {
- log.debug("Found context-store access in {}", instrumenterClass.getName());
+ log.trace("Found context-store access in {}", instrumenterClass.getName());
/*
The idea here is that the rest if this method visitor collects last three instructions in `insnStack`
variable. Once we get here we check if those last three instructions constitute call that looks like
@@ -213,8 +213,8 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
String keyClassName = ((Type) stack[1]).getClassName();
TypeDescription contextStoreImplementationClass =
getContextStoreImplementation(keyClassName, contextClassName);
- if (log.isDebugEnabled()) {
- log.debug(
+ if (log.isTraceEnabled()) {
+ log.trace(
"Rewriting context-store map fetch for instrumenter {}: {} -> {}",
instrumenterClass.getName(),
keyClassName,
@@ -373,11 +373,11 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
*/
synchronized (INSTALLED_CONTEXT_MATCHERS) {
if (INSTALLED_CONTEXT_MATCHERS.contains(entry)) {
- log.debug("Skipping builder for {} {}", instrumenterClass.getName(), entry);
+ log.trace("Skipping builder for {} {}", instrumenterClass.getName(), entry);
continue;
}
- log.debug("Making builder for {} {}", instrumenterClass.getName(), entry);
+ log.trace("Making builder for {} {}", instrumenterClass.getName(), entry);
INSTALLED_CONTEXT_MATCHERS.add(entry);
/*

Reduce debug logging (#2296)