Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void applyNewConfiguration(Configuration newConfiguration) {
}
currentConfiguration = newConfiguration;
if (changes.hasProbeRelatedChanges()) {
LOGGER.info("Applying new probe configuration, changes: {}", changes);
LOGGER.debug("Applying new probe configuration, changes: {}", changes);
handleProbesChanges(changes, newConfiguration);
}
} finally {
Expand Down Expand Up @@ -208,7 +208,7 @@ private void recordInstrumentationProgress(
private void retransformClasses(List<Class<?>> classesToBeTransformed) {
for (Class<?> clazz : classesToBeTransformed) {
try {
LOGGER.info("Re-transforming class: {}", clazz.getTypeName());
LOGGER.debug("Re-transforming class: {}", clazz.getTypeName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

instrumentation.retransformClasses(clazz);
} catch (Exception ex) {
ExceptionHelper.logException(LOGGER, ex, "Re-transform error:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* debugger configuration
*/
public class DebuggerTransformer implements ClassFileTransformer {
private static final Logger log = LoggerFactory.getLogger(DebuggerTransformer.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DebuggerTransformer.class);
private static final String CANNOT_FIND_METHOD = "Cannot find method %s::%s%s";
private static final String INSTRUMENTATION_FAILS = "Instrumentation fails for %s";
private static final String CANNOT_FIND_LINE = "No executable code was found at %s:L%s";
Expand Down Expand Up @@ -148,7 +148,7 @@ public DebuggerTransformer(
} else if (itwType.equals("line")) {
probeCreator = this::createLineProbes;
} else {
log.warn(
LOGGER.warn(
"Invalid value for 'dd.debugger.instrument-the-world' property: {}. "
+ "Valid values are 'method' or 'line'.",
itwType);
Expand Down Expand Up @@ -202,7 +202,7 @@ private void processITWFiles(
for (String fileName : fileNames) {
Path excludePath = Paths.get(fileName);
if (!Files.exists(excludePath)) {
log.warn("Cannot find exclude file: {}", excludePath);
LOGGER.warn("Cannot find exclude file: {}", excludePath);
continue;
}
try {
Expand All @@ -223,7 +223,7 @@ private void processITWFiles(
classes.add(line);
});
} catch (IOException ex) {
log.warn("Error reading exclude file '{}' for Instrument-The-World: ", fileName, ex);
LOGGER.warn("Error reading exclude file '{}' for Instrument-The-World: ", fileName, ex);
}
}
}
Expand All @@ -250,7 +250,7 @@ public byte[] transform(
if (definitions.isEmpty()) {
return null;
}
log.debug("Matching definitions for class[{}]: {}", fullyQualifiedClassName, definitions);
LOGGER.debug("Matching definitions for class[{}]: {}", fullyQualifiedClassName, definitions);
if (!instrumentationIsAllowed(fullyQualifiedClassName, definitions)) {
return null;
}
Expand All @@ -260,22 +260,22 @@ public byte[] transform(
if (transformed) {
return writeClassFile(definitions, loader, classFilePath, classNode);
}
// This is an info log because in case of SourceFile definition and multiple top-level
// We are logging this because in case of SourceFile definition and multiple top-level
// classes, type may match, but there is one classfile per top-level class so source file
// will match, but not the classfile.
// e.g. Main.java contains Main & TopLevel class, line numbers are in TopLevel class
log.info(
LOGGER.debug(
"type {} matched but no transformation for definitions: {}", classFilePath, definitions);
} catch (Throwable ex) {
log.warn("Cannot transform: ", ex);
LOGGER.warn("Cannot transform: ", ex);
reportInstrumentationFails(definitions, fullyQualifiedClassName);
}
return null;
}

private boolean skipInstrumentation(ClassLoader loader, String classFilePath) {
if (definitionMatcher.isEmpty()) {
log.debug("No debugger definitions present.");
LOGGER.debug("No debugger definitions present.");
return true;
}
if (classFilePath == null) {
Expand Down Expand Up @@ -311,7 +311,7 @@ private byte[] transformTheWorld(
location = codeSource.getLocation();
}
}
log.debug(
LOGGER.debug(
"Parsing class '{}' {}B loaded from loader='{}' location={}",
classFilePath,
classfileBuffer.length,
Expand All @@ -320,7 +320,7 @@ private byte[] transformTheWorld(
ClassNode classNode = parseClassFile(classFilePath, classfileBuffer);
if (isClassLoaderRelated(classNode)) {
// Skip ClassLoader classes
log.debug("Skipping ClassLoader class: {}", classFilePath);
LOGGER.debug("Skipping ClassLoader class: {}", classFilePath);
excludeClasses.add(classFilePath);
return null;
}
Expand All @@ -337,10 +337,10 @@ private byte[] transformTheWorld(
if (transformed) {
return writeClassFile(probes, loader, classFilePath, classNode);
} else {
log.debug("Class not transformed: {}", classFilePath);
LOGGER.debug("Class not transformed: {}", classFilePath);
}
} catch (Throwable ex) {
log.warn("Cannot transform: ", ex);
LOGGER.warn("Cannot transform: ", ex);
writeToInstrumentationLog(classFilePath);
}
return null;
Expand All @@ -354,7 +354,7 @@ private boolean isMethodIncludedForTransformation(
}
String fqnMethod = classNode.name + "::" + methodNode.name;
if (excludeMethods.contains(fqnMethod)) {
log.debug("Skipping method: {}", fqnMethod);
LOGGER.debug("Skipping method: {}", fqnMethod);
return false;
}
return methodNames.add(methodNode.name);
Expand Down Expand Up @@ -404,7 +404,7 @@ private synchronized void writeToInstrumentationLog(String classFilePath) {
writer.write(classFilePath);
writer.write("\n");
} catch (Exception ex) {
log.warn("Cannot write to instrumentation.log", ex);
LOGGER.warn("Cannot write to instrumentation.log", ex);
}
}

Expand Down Expand Up @@ -443,7 +443,7 @@ private boolean isIncludedForTransformation(String classFilePath) {
private boolean instrumentationIsAllowed(
String fullyQualifiedClassName, List<ProbeDefinition> definitions) {
if (denyListHelper.isDenied(fullyQualifiedClassName)) {
log.info("Instrumentation denied for {}", fullyQualifiedClassName);
LOGGER.debug("Instrumentation denied for {}", fullyQualifiedClassName);
InstrumentationResult result =
InstrumentationResult.Factory.blocked(
fullyQualifiedClassName,
Expand All @@ -455,7 +455,7 @@ private boolean instrumentationIsAllowed(
return false;
}
if (!allowListHelper.isAllowAll() && !allowListHelper.isAllowed(fullyQualifiedClassName)) {
log.info("Instrumentation not allowed for {}", fullyQualifiedClassName);
LOGGER.debug("Instrumentation not allowed for {}", fullyQualifiedClassName);
InstrumentationResult result =
InstrumentationResult.Factory.blocked(
fullyQualifiedClassName,
Expand Down Expand Up @@ -487,11 +487,11 @@ private byte[] writeClassFile(
classNode.version = Opcodes.V1_8;
}
ClassWriter writer = new SafeClassWriter(loader);
log.debug("Generating bytecode for class: {}", Strings.getClassName(classFilePath));
LOGGER.debug("Generating bytecode for class: {}", Strings.getClassName(classFilePath));
try {
classNode.accept(writer);
} catch (Throwable t) {
log.error("Cannot write classfile for class: {} Exception: ", classFilePath, t);
LOGGER.error("Cannot write classfile for class: {} Exception: ", classFilePath, t);
reportInstrumentationFails(definitions, Strings.getClassName(classFilePath));
return null;
}
Expand Down Expand Up @@ -526,8 +526,8 @@ private void verifyByteCode(String classFilePath, byte[] classFile) {
printWriter.flush();
String result = stringWriter.toString();
if (!result.isEmpty()) {
log.warn("Verification of instrumented class {} failed", classFilePath);
log.debug("Verify result: {}", stringWriter);
LOGGER.warn("Verification of instrumented class {} failed", classFilePath);
LOGGER.debug("Verify result: {}", stringWriter);
throw new RuntimeException("Generated bytecode is invalid for " + classFilePath);
}
}
Expand Down Expand Up @@ -560,9 +560,9 @@ private boolean performInstrumentation(
if (matchingDefs.isEmpty()) {
continue;
}
if (log.isDebugEnabled()) {
if (LOGGER.isDebugEnabled()) {
List<String> probeIds = matchingDefs.stream().map(ProbeDefinition::getId).collect(toList());
log.debug(
LOGGER.debug(
"Instrumenting method: {}.{}{} for probe ids: {}",
fullyQualifiedClassName,
methodNode.name,
Expand Down Expand Up @@ -627,7 +627,7 @@ private void reportErrorForAllProbes(List<ProbeDefinition> definitions, String m
private void addDiagnostics(
ProbeDefinition definition, List<DiagnosticMessage> diagnosticMessages) {
debuggerSink.addDiagnostics(definition.getProbeId(), diagnosticMessages);
log.debug("Diagnostic messages for definition[{}]: {}", definition, diagnosticMessages);
LOGGER.debug("Diagnostic messages for definition[{}]: {}", definition, diagnosticMessages);
}

private void notifyBlockedDefinitions(
Expand Down Expand Up @@ -658,7 +658,7 @@ private InstrumentationResult applyInstrumentation(
status = definition.instrument(methodInfo, probeDiagnostics, toInstrumentInfo.probeIds);
}
} catch (Throwable t) {
log.warn("Exception during instrumentation: ", t);
LOGGER.warn("Exception during instrumentation: ", t);
status = InstrumentationResult.Status.ERROR;
addDiagnosticForAllProbes(
new DiagnosticMessage(DiagnosticMessage.Kind.ERROR, t), diagnostics);
Expand Down Expand Up @@ -694,7 +694,7 @@ private List<ToInstrumentInfo> filterAndSortDefinitions(
// and therefore need to be instrumented once
// note: exception probes are log probes and are handled the same way
if (!Config.get().isDistributedDebuggerEnabled() && definition instanceof TriggerProbe) {
log.debug(
LOGGER.debug(
"The distributed debugger feature is disabled. Trigger probes will not be installed.");
} else if (isCapturedContextProbe(definition)) {
if (definition.isLineProbe()) {
Expand Down Expand Up @@ -871,7 +871,7 @@ private List<MethodNode> matchMethodDescription(
}
}
} catch (Exception ex) {
log.warn("Cannot match method: {}", ex.toString());
LOGGER.warn("Cannot match method: {}", ex.toString());
}
return result;
}
Expand All @@ -888,22 +888,22 @@ private MethodNode matchSourceFile(
if (matchingMethods != null) {
matchingMethods.forEach(
methodNode -> {
log.debug("Found lineNode {} method: {}", matchingLine, methodNode.name);
LOGGER.debug("Found lineNode {} method: {}", matchingLine, methodNode.name);
});
// pick the first matching method.
// TODO need a way to disambiguate if multiple methods match the same line
return matchingMethods.isEmpty() ? null : matchingMethods.get(0);
}
log.debug("Cannot find line: {} in class {}", matchingLine, classNode.name);
LOGGER.debug("Cannot find line: {} in class {}", matchingLine, classNode.name);
return null;
}

private void dumpInstrumentedClassFile(String className, byte[] data) {
if (config.isDynamicInstrumentationClassFileDumpEnabled()) {
log.debug("Generated bytecode len: {}", data.length);
LOGGER.debug("Generated bytecode len: {}", data.length);
Path classFilePath = dumpClassFile(className, data);
if (classFilePath != null) {
log.debug("Instrumented class saved as: {}", classFilePath.toString());
LOGGER.debug("Instrumented class saved as: {}", classFilePath.toString());
}
}
}
Expand All @@ -912,7 +912,7 @@ private void dumpOriginalClassFile(String className, byte[] classfileBuffer) {
if (config.isDynamicInstrumentationClassFileDumpEnabled()) {
Path classFilePath = dumpClassFile(className + "_orig", classfileBuffer);
if (classFilePath != null) {
log.debug("Original class saved as: {}", classFilePath.toString());
LOGGER.debug("Original class saved as: {}", classFilePath.toString());
}
}
}
Expand All @@ -924,7 +924,7 @@ private static Path dumpClassFile(String className, byte[] classfileBuffer) {
Files.write(classFilePath, classfileBuffer, StandardOpenOption.CREATE);
return classFilePath;
} catch (IOException e) {
log.error("", e);
LOGGER.error("", e);
return null;
}
}
Expand Down Expand Up @@ -981,7 +981,7 @@ protected String getCommonSuperClass(String type1, String type2) {
}
return common.getInternalName();
} catch (Exception ex) {
ExceptionHelper.logException(log, ex, "getCommonSuperClass failed: ");
ExceptionHelper.logException(LOGGER, ex, "getCommonSuperClass failed: ");
return tpDatadogClassLoader.describe("java.lang.Object").resolve().getInternalName();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public DefaultCodeOriginRecorder(

@Override
public String captureCodeOrigin(boolean entry) {
if (!entry) {
LOG.debug("Not capturing code origin for exit");
return null;
}
StackTraceElement element = findPlaceInStack();
String fingerprint = Fingerprinter.fingerprint(element);
CodeOriginProbe probe = probesByFingerprint.get(fingerprint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.jetbrains.annotations.NotNull;
import org.joor.Reflect;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class CodeOriginTest extends CapturingTestBase {
Expand Down Expand Up @@ -212,6 +213,7 @@ public void testCaptureCodeOriginEntry() {
}

@Test
@Disabled("Exit spans are disabled for now")
public void testCaptureCodeOriginExit() {
installProbes();
CodeOriginProbe probe =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestApplicationHelper {
private static final String INSTRUMENTATION_DONE_TASK_THREAD =
"[dd-task-scheduler] DEBUG com.datadog.debugger.agent.DebuggerTransformer - Generating bytecode for class: %s";
private static final String RENTRANSFORMATION_CLASS =
"[dd-remote-config] INFO com.datadog.debugger.agent.ConfigurationUpdater - Re-transforming class: %s";
"[dd-remote-config] DEBUG com.datadog.debugger.agent.ConfigurationUpdater - Re-transforming class: %s";
private static final String RETRANSFORMATION_DONE =
"com.datadog.debugger.agent.ConfigurationUpdater - Re-transformation done";
private static final long SLEEP_MS = 100;
Expand Down