-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Exception debugging instrumentation async #6829
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ public static Throwable getInnerMostThrowable(Throwable t) { | |
|
||
public static StackTraceElement[] flattenStackTrace(Throwable t) { | ||
List<StackTraceElement> result = new ArrayList<>(); | ||
result.add(null); // add a stack frame representing the exception message | ||
// result.add(null); // add a stack frame representing the exception message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right! |
||
result.addAll(Arrays.asList(t.getStackTrace())); | ||
if (t.getCause() != null) { | ||
internalFlattenStackTrace(t.getCause(), t.getStackTrace(), result); | ||
|
@@ -90,13 +90,9 @@ private static void internalFlattenStackTrace( | |
m--; | ||
n--; | ||
} | ||
elements.add(null); // add a stack frame representing the exception message | ||
for (int i = 0; i <= m; i++) { | ||
elements.add(trace[i]); | ||
} | ||
if (trace.length - 1 - m > 0) { | ||
elements.add(null); // add a stack frame representing number of common frames ("... n more") | ||
} | ||
if (t.getCause() != null) { | ||
internalFlattenStackTrace(t.getCause(), trace, elements); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import com.datadog.debugger.probe.ExceptionProbe; | ||
import com.datadog.debugger.util.ClassNameFiltering; | ||
import java.time.Duration; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import org.junit.jupiter.api.Test; | ||
|
@@ -18,7 +19,7 @@ public void instrumentStackTrace() { | |
RuntimeException exception = new RuntimeException("test"); | ||
String fingerprint = Fingerprinter.fingerprint(exception, classNameFiltering); | ||
exceptionProbeManager.createProbesForException(fingerprint, exception.getStackTrace()); | ||
assertTrue(exceptionProbeManager.isAlreadyInstrumented(fingerprint)); | ||
assertFalse(exceptionProbeManager.getProbes().isEmpty()); | ||
} | ||
|
||
@Test | ||
|
@@ -28,7 +29,7 @@ void instrumentSingleFrame() { | |
ExceptionProbeManager exceptionProbeManager = new ExceptionProbeManager(classNameFiltering); | ||
|
||
String fingerprint = Fingerprinter.fingerprint(exception, classNameFiltering); | ||
assertEquals("aa4a4dd768f6ef0fcc2b39a3bdedcbe44baff2e9dd0a779228db7bd8bf58", fingerprint); | ||
assertEquals("ca4d9f3a1033d7262a89855f4b5cbdc225ed63c592c6cdf83fc5a88589e5fb", fingerprint); | ||
exceptionProbeManager.createProbesForException(fingerprint, exception.getStackTrace()); | ||
assertEquals(1, exceptionProbeManager.getProbes().size()); | ||
ExceptionProbe exceptionProbe = exceptionProbeManager.getProbes().iterator().next(); | ||
|
@@ -52,4 +53,19 @@ void filterAllFrames() { | |
exceptionProbeManager.createProbesForException("", exception.getStackTrace()); | ||
assertEquals(0, exceptionProbeManager.getProbes().size()); | ||
} | ||
|
||
static void waitForInstrumentation( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like a great utility function to have assertWithTimeout(()->exceptionProbeManager.isAlreadyInstrumented(fingerprint), Duration.OfSeconds(30)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
ExceptionProbeManager exceptionProbeManager, String fingerprint) { | ||
Duration timeout = Duration.ofSeconds(30); | ||
Duration sleepTime = Duration.ofMillis(10); | ||
long count = timeout.toMillis() / sleepTime.toMillis(); | ||
while (count-- > 0 && !exceptionProbeManager.isAlreadyInstrumented(fingerprint)) { | ||
try { | ||
Thread.sleep(sleepTime.toMillis()); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
assertTrue(exceptionProbeManager.isAlreadyInstrumented(fingerprint)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add check:
if (exceptionProbeManager.isAlreadyInstrumented(fingerprint)) {
to avoid race condition?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm no because
IsAlreadyInstrumented
rely on the fact we add the fingerprint which is now done after applying the config...