Skip to content

Commit 79f2e72

Browse files
authored
Disable exit spans (#9581)
Disable exit spans change some info level to debug
1 parent abac8af commit 79f2e72

File tree

5 files changed

+43
-37
lines changed

5 files changed

+43
-37
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/ConfigurationUpdater.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private void applyNewConfiguration(Configuration newConfiguration) {
131131
}
132132
currentConfiguration = newConfiguration;
133133
if (changes.hasProbeRelatedChanges()) {
134-
LOGGER.info("Applying new probe configuration, changes: {}", changes);
134+
LOGGER.debug("Applying new probe configuration, changes: {}", changes);
135135
handleProbesChanges(changes, newConfiguration);
136136
}
137137
} finally {
@@ -208,7 +208,7 @@ private void recordInstrumentationProgress(
208208
private void retransformClasses(List<Class<?>> classesToBeTransformed) {
209209
for (Class<?> clazz : classesToBeTransformed) {
210210
try {
211-
LOGGER.info("Re-transforming class: {}", clazz.getTypeName());
211+
LOGGER.debug("Re-transforming class: {}", clazz.getTypeName());
212212
instrumentation.retransformClasses(clazz);
213213
} catch (Exception ex) {
214214
ExceptionHelper.logException(LOGGER, ex, "Re-transform error:");

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/agent/DebuggerTransformer.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
* debugger configuration
7777
*/
7878
public class DebuggerTransformer implements ClassFileTransformer {
79-
private static final Logger log = LoggerFactory.getLogger(DebuggerTransformer.class);
79+
private static final Logger LOGGER = LoggerFactory.getLogger(DebuggerTransformer.class);
8080
private static final String CANNOT_FIND_METHOD = "Cannot find method %s::%s%s";
8181
private static final String INSTRUMENTATION_FAILS = "Instrumentation fails for %s";
8282
private static final String CANNOT_FIND_LINE = "No executable code was found at %s:L%s";
@@ -148,7 +148,7 @@ public DebuggerTransformer(
148148
} else if (itwType.equals("line")) {
149149
probeCreator = this::createLineProbes;
150150
} else {
151-
log.warn(
151+
LOGGER.warn(
152152
"Invalid value for 'dd.debugger.instrument-the-world' property: {}. "
153153
+ "Valid values are 'method' or 'line'.",
154154
itwType);
@@ -202,7 +202,7 @@ private void processITWFiles(
202202
for (String fileName : fileNames) {
203203
Path excludePath = Paths.get(fileName);
204204
if (!Files.exists(excludePath)) {
205-
log.warn("Cannot find exclude file: {}", excludePath);
205+
LOGGER.warn("Cannot find exclude file: {}", excludePath);
206206
continue;
207207
}
208208
try {
@@ -223,7 +223,7 @@ private void processITWFiles(
223223
classes.add(line);
224224
});
225225
} catch (IOException ex) {
226-
log.warn("Error reading exclude file '{}' for Instrument-The-World: ", fileName, ex);
226+
LOGGER.warn("Error reading exclude file '{}' for Instrument-The-World: ", fileName, ex);
227227
}
228228
}
229229
}
@@ -250,7 +250,7 @@ public byte[] transform(
250250
if (definitions.isEmpty()) {
251251
return null;
252252
}
253-
log.debug("Matching definitions for class[{}]: {}", fullyQualifiedClassName, definitions);
253+
LOGGER.debug("Matching definitions for class[{}]: {}", fullyQualifiedClassName, definitions);
254254
if (!instrumentationIsAllowed(fullyQualifiedClassName, definitions)) {
255255
return null;
256256
}
@@ -260,22 +260,22 @@ public byte[] transform(
260260
if (transformed) {
261261
return writeClassFile(definitions, loader, classFilePath, classNode);
262262
}
263-
// This is an info log because in case of SourceFile definition and multiple top-level
263+
// We are logging this because in case of SourceFile definition and multiple top-level
264264
// classes, type may match, but there is one classfile per top-level class so source file
265265
// will match, but not the classfile.
266266
// e.g. Main.java contains Main & TopLevel class, line numbers are in TopLevel class
267-
log.info(
267+
LOGGER.debug(
268268
"type {} matched but no transformation for definitions: {}", classFilePath, definitions);
269269
} catch (Throwable ex) {
270-
log.warn("Cannot transform: ", ex);
270+
LOGGER.warn("Cannot transform: ", ex);
271271
reportInstrumentationFails(definitions, fullyQualifiedClassName);
272272
}
273273
return null;
274274
}
275275

276276
private boolean skipInstrumentation(ClassLoader loader, String classFilePath) {
277277
if (definitionMatcher.isEmpty()) {
278-
log.debug("No debugger definitions present.");
278+
LOGGER.debug("No debugger definitions present.");
279279
return true;
280280
}
281281
if (classFilePath == null) {
@@ -311,7 +311,7 @@ private byte[] transformTheWorld(
311311
location = codeSource.getLocation();
312312
}
313313
}
314-
log.debug(
314+
LOGGER.debug(
315315
"Parsing class '{}' {}B loaded from loader='{}' location={}",
316316
classFilePath,
317317
classfileBuffer.length,
@@ -320,7 +320,7 @@ private byte[] transformTheWorld(
320320
ClassNode classNode = parseClassFile(classFilePath, classfileBuffer);
321321
if (isClassLoaderRelated(classNode)) {
322322
// Skip ClassLoader classes
323-
log.debug("Skipping ClassLoader class: {}", classFilePath);
323+
LOGGER.debug("Skipping ClassLoader class: {}", classFilePath);
324324
excludeClasses.add(classFilePath);
325325
return null;
326326
}
@@ -337,10 +337,10 @@ private byte[] transformTheWorld(
337337
if (transformed) {
338338
return writeClassFile(probes, loader, classFilePath, classNode);
339339
} else {
340-
log.debug("Class not transformed: {}", classFilePath);
340+
LOGGER.debug("Class not transformed: {}", classFilePath);
341341
}
342342
} catch (Throwable ex) {
343-
log.warn("Cannot transform: ", ex);
343+
LOGGER.warn("Cannot transform: ", ex);
344344
writeToInstrumentationLog(classFilePath);
345345
}
346346
return null;
@@ -354,7 +354,7 @@ private boolean isMethodIncludedForTransformation(
354354
}
355355
String fqnMethod = classNode.name + "::" + methodNode.name;
356356
if (excludeMethods.contains(fqnMethod)) {
357-
log.debug("Skipping method: {}", fqnMethod);
357+
LOGGER.debug("Skipping method: {}", fqnMethod);
358358
return false;
359359
}
360360
return methodNames.add(methodNode.name);
@@ -404,7 +404,7 @@ private synchronized void writeToInstrumentationLog(String classFilePath) {
404404
writer.write(classFilePath);
405405
writer.write("\n");
406406
} catch (Exception ex) {
407-
log.warn("Cannot write to instrumentation.log", ex);
407+
LOGGER.warn("Cannot write to instrumentation.log", ex);
408408
}
409409
}
410410

@@ -443,7 +443,7 @@ private boolean isIncludedForTransformation(String classFilePath) {
443443
private boolean instrumentationIsAllowed(
444444
String fullyQualifiedClassName, List<ProbeDefinition> definitions) {
445445
if (denyListHelper.isDenied(fullyQualifiedClassName)) {
446-
log.info("Instrumentation denied for {}", fullyQualifiedClassName);
446+
LOGGER.debug("Instrumentation denied for {}", fullyQualifiedClassName);
447447
InstrumentationResult result =
448448
InstrumentationResult.Factory.blocked(
449449
fullyQualifiedClassName,
@@ -455,7 +455,7 @@ private boolean instrumentationIsAllowed(
455455
return false;
456456
}
457457
if (!allowListHelper.isAllowAll() && !allowListHelper.isAllowed(fullyQualifiedClassName)) {
458-
log.info("Instrumentation not allowed for {}", fullyQualifiedClassName);
458+
LOGGER.debug("Instrumentation not allowed for {}", fullyQualifiedClassName);
459459
InstrumentationResult result =
460460
InstrumentationResult.Factory.blocked(
461461
fullyQualifiedClassName,
@@ -487,11 +487,11 @@ private byte[] writeClassFile(
487487
classNode.version = Opcodes.V1_8;
488488
}
489489
ClassWriter writer = new SafeClassWriter(loader);
490-
log.debug("Generating bytecode for class: {}", Strings.getClassName(classFilePath));
490+
LOGGER.debug("Generating bytecode for class: {}", Strings.getClassName(classFilePath));
491491
try {
492492
classNode.accept(writer);
493493
} catch (Throwable t) {
494-
log.error("Cannot write classfile for class: {} Exception: ", classFilePath, t);
494+
LOGGER.error("Cannot write classfile for class: {} Exception: ", classFilePath, t);
495495
reportInstrumentationFails(definitions, Strings.getClassName(classFilePath));
496496
return null;
497497
}
@@ -526,8 +526,8 @@ private void verifyByteCode(String classFilePath, byte[] classFile) {
526526
printWriter.flush();
527527
String result = stringWriter.toString();
528528
if (!result.isEmpty()) {
529-
log.warn("Verification of instrumented class {} failed", classFilePath);
530-
log.debug("Verify result: {}", stringWriter);
529+
LOGGER.warn("Verification of instrumented class {} failed", classFilePath);
530+
LOGGER.debug("Verify result: {}", stringWriter);
531531
throw new RuntimeException("Generated bytecode is invalid for " + classFilePath);
532532
}
533533
}
@@ -560,9 +560,9 @@ private boolean performInstrumentation(
560560
if (matchingDefs.isEmpty()) {
561561
continue;
562562
}
563-
if (log.isDebugEnabled()) {
563+
if (LOGGER.isDebugEnabled()) {
564564
List<String> probeIds = matchingDefs.stream().map(ProbeDefinition::getId).collect(toList());
565-
log.debug(
565+
LOGGER.debug(
566566
"Instrumenting method: {}.{}{} for probe ids: {}",
567567
fullyQualifiedClassName,
568568
methodNode.name,
@@ -627,7 +627,7 @@ private void reportErrorForAllProbes(List<ProbeDefinition> definitions, String m
627627
private void addDiagnostics(
628628
ProbeDefinition definition, List<DiagnosticMessage> diagnosticMessages) {
629629
debuggerSink.addDiagnostics(definition.getProbeId(), diagnosticMessages);
630-
log.debug("Diagnostic messages for definition[{}]: {}", definition, diagnosticMessages);
630+
LOGGER.debug("Diagnostic messages for definition[{}]: {}", definition, diagnosticMessages);
631631
}
632632

633633
private void notifyBlockedDefinitions(
@@ -658,7 +658,7 @@ private InstrumentationResult applyInstrumentation(
658658
status = definition.instrument(methodInfo, probeDiagnostics, toInstrumentInfo.probeIds);
659659
}
660660
} catch (Throwable t) {
661-
log.warn("Exception during instrumentation: ", t);
661+
LOGGER.warn("Exception during instrumentation: ", t);
662662
status = InstrumentationResult.Status.ERROR;
663663
addDiagnosticForAllProbes(
664664
new DiagnosticMessage(DiagnosticMessage.Kind.ERROR, t), diagnostics);
@@ -694,7 +694,7 @@ private List<ToInstrumentInfo> filterAndSortDefinitions(
694694
// and therefore need to be instrumented once
695695
// note: exception probes are log probes and are handled the same way
696696
if (!Config.get().isDistributedDebuggerEnabled() && definition instanceof TriggerProbe) {
697-
log.debug(
697+
LOGGER.debug(
698698
"The distributed debugger feature is disabled. Trigger probes will not be installed.");
699699
} else if (isCapturedContextProbe(definition)) {
700700
if (definition.isLineProbe()) {
@@ -871,7 +871,7 @@ private List<MethodNode> matchMethodDescription(
871871
}
872872
}
873873
} catch (Exception ex) {
874-
log.warn("Cannot match method: {}", ex.toString());
874+
LOGGER.warn("Cannot match method: {}", ex.toString());
875875
}
876876
return result;
877877
}
@@ -888,22 +888,22 @@ private MethodNode matchSourceFile(
888888
if (matchingMethods != null) {
889889
matchingMethods.forEach(
890890
methodNode -> {
891-
log.debug("Found lineNode {} method: {}", matchingLine, methodNode.name);
891+
LOGGER.debug("Found lineNode {} method: {}", matchingLine, methodNode.name);
892892
});
893893
// pick the first matching method.
894894
// TODO need a way to disambiguate if multiple methods match the same line
895895
return matchingMethods.isEmpty() ? null : matchingMethods.get(0);
896896
}
897-
log.debug("Cannot find line: {} in class {}", matchingLine, classNode.name);
897+
LOGGER.debug("Cannot find line: {} in class {}", matchingLine, classNode.name);
898898
return null;
899899
}
900900

901901
private void dumpInstrumentedClassFile(String className, byte[] data) {
902902
if (config.isDynamicInstrumentationClassFileDumpEnabled()) {
903-
log.debug("Generated bytecode len: {}", data.length);
903+
LOGGER.debug("Generated bytecode len: {}", data.length);
904904
Path classFilePath = dumpClassFile(className, data);
905905
if (classFilePath != null) {
906-
log.debug("Instrumented class saved as: {}", classFilePath.toString());
906+
LOGGER.debug("Instrumented class saved as: {}", classFilePath.toString());
907907
}
908908
}
909909
}
@@ -912,7 +912,7 @@ private void dumpOriginalClassFile(String className, byte[] classfileBuffer) {
912912
if (config.isDynamicInstrumentationClassFileDumpEnabled()) {
913913
Path classFilePath = dumpClassFile(className + "_orig", classfileBuffer);
914914
if (classFilePath != null) {
915-
log.debug("Original class saved as: {}", classFilePath.toString());
915+
LOGGER.debug("Original class saved as: {}", classFilePath.toString());
916916
}
917917
}
918918
}
@@ -924,7 +924,7 @@ private static Path dumpClassFile(String className, byte[] classfileBuffer) {
924924
Files.write(classFilePath, classfileBuffer, StandardOpenOption.CREATE);
925925
return classFilePath;
926926
} catch (IOException e) {
927-
log.error("", e);
927+
LOGGER.error("", e);
928928
return null;
929929
}
930930
}
@@ -981,7 +981,7 @@ protected String getCommonSuperClass(String type1, String type2) {
981981
}
982982
return common.getInternalName();
983983
} catch (Exception ex) {
984-
ExceptionHelper.logException(log, ex, "getCommonSuperClass failed: ");
984+
ExceptionHelper.logException(LOGGER, ex, "getCommonSuperClass failed: ");
985985
return tpDatadogClassLoader.describe("java.lang.Object").resolve().getInternalName();
986986
}
987987
}

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/codeorigin/DefaultCodeOriginRecorder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public DefaultCodeOriginRecorder(
6060

6161
@Override
6262
public String captureCodeOrigin(boolean entry) {
63+
if (!entry) {
64+
LOG.debug("Not capturing code origin for exit");
65+
return null;
66+
}
6367
StackTraceElement element = findPlaceInStack();
6468
String fingerprint = Fingerprinter.fingerprint(element);
6569
CodeOriginProbe probe = probesByFingerprint.get(fingerprint);

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/origin/CodeOriginTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.jetbrains.annotations.NotNull;
5757
import org.joor.Reflect;
5858
import org.junit.jupiter.api.BeforeEach;
59+
import org.junit.jupiter.api.Disabled;
5960
import org.junit.jupiter.api.Test;
6061

6162
public class CodeOriginTest extends CapturingTestBase {
@@ -212,6 +213,7 @@ public void testCaptureCodeOriginEntry() {
212213
}
213214

214215
@Test
216+
@Disabled("Exit spans are disabled for now")
215217
public void testCaptureCodeOriginExit() {
216218
installProbes();
217219
CodeOriginProbe probe =

dd-smoke-tests/debugger-integration-tests/src/main/java/datadog/smoketest/debugger/TestApplicationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TestApplicationHelper {
2020
private static final String INSTRUMENTATION_DONE_TASK_THREAD =
2121
"[dd-task-scheduler] DEBUG com.datadog.debugger.agent.DebuggerTransformer - Generating bytecode for class: %s";
2222
private static final String RENTRANSFORMATION_CLASS =
23-
"[dd-remote-config] INFO com.datadog.debugger.agent.ConfigurationUpdater - Re-transforming class: %s";
23+
"[dd-remote-config] DEBUG com.datadog.debugger.agent.ConfigurationUpdater - Re-transforming class: %s";
2424
private static final String RETRANSFORMATION_DONE =
2525
"com.datadog.debugger.agent.ConfigurationUpdater - Re-transformation done";
2626
private static final long SLEEP_MS = 100;

0 commit comments

Comments
 (0)