Skip to content

Commit 92f6b9e

Browse files
authored
Add new debug logs when no probe for exception (#7786)
Add statistics about skipped frames (native or third-party) and the full stacktrace folded in order to troubleshoot
1 parent 1508cef commit 92f6b9e

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,18 @@ public void handleException(Throwable t, AgentSpan span) {
8989
processSnapshotsAndSetTags(t, span, state, innerMostException, fingerprint);
9090
exceptionProbeManager.updateLastCapture(fingerprint);
9191
} else {
92-
if (exceptionProbeManager.createProbesForException(innerMostException.getStackTrace())) {
92+
ExceptionProbeManager.CreationResult creationResult =
93+
exceptionProbeManager.createProbesForException(innerMostException.getStackTrace());
94+
if (creationResult.probesCreated > 0) {
9395
AgentTaskScheduler.INSTANCE.execute(() -> applyExceptionConfiguration(fingerprint));
9496
} else {
95-
LOGGER.debug("No probe created for exception: {}", innerMostException.toString());
97+
if (LOGGER.isDebugEnabled()) {
98+
LOGGER.debug(
99+
"No probe created, nativeFrames={}, thirdPartyFrames={} for exception: {}",
100+
creationResult.nativeFrames,
101+
creationResult.thirdPartyFrames,
102+
ExceptionHelper.foldExceptionStackTrace(innerMostException));
103+
}
96104
}
97105
}
98106
}

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/ExceptionProbeManager.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,33 @@ public ClassNameFiltering getClassNameFiltering() {
6767
return classNameFiltering;
6868
}
6969

70-
public boolean createProbesForException(StackTraceElement[] stackTraceElements) {
71-
boolean created = false;
72-
int maxFrames = maxCapturedFrames;
70+
static class CreationResult {
71+
final int probesCreated;
72+
final int thirdPartyFrames;
73+
final int nativeFrames;
74+
75+
public CreationResult(int probesCreated, int thirdPartyFrames, int nativeFrames) {
76+
this.probesCreated = probesCreated;
77+
this.thirdPartyFrames = thirdPartyFrames;
78+
this.nativeFrames = nativeFrames;
79+
}
80+
}
81+
82+
public CreationResult createProbesForException(StackTraceElement[] stackTraceElements) {
83+
int instrumentedFrames = 0;
84+
int nativeFrames = 0;
85+
int thirdPartyFrames = 0;
7386
for (StackTraceElement stackTraceElement : stackTraceElements) {
74-
if (maxFrames <= 0) {
87+
if (instrumentedFrames >= maxCapturedFrames) {
7588
break;
7689
}
7790
if (stackTraceElement.isNativeMethod() || stackTraceElement.getLineNumber() < 0) {
7891
// Skip native methods and lines without line numbers
79-
// TODO log?
92+
nativeFrames++;
8093
continue;
8194
}
8295
if (classNameFiltering.isExcluded(stackTraceElement.getClassName())) {
96+
thirdPartyFrames++;
8397
continue;
8498
}
8599
Where where =
@@ -89,11 +103,10 @@ public boolean createProbesForException(StackTraceElement[] stackTraceElements)
89103
null,
90104
String.valueOf(stackTraceElement.getLineNumber()));
91105
ExceptionProbe probe = createMethodProbe(this, where);
92-
created = true;
93106
probes.putIfAbsent(probe.getId(), probe);
94-
maxFrames--;
107+
instrumentedFrames++;
95108
}
96-
return created;
109+
return new CreationResult(instrumentedFrames, thirdPartyFrames, nativeFrames);
97110
}
98111

99112
void addFingerprint(String fingerprint) {

0 commit comments

Comments
 (0)