Skip to content
Closed
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 @@ -160,6 +160,13 @@ private void processSnapshotsAndSetTags(
int[] mapping = createThrowableMapping(currentEx, t);
StackTraceElement[] innerTrace = currentEx.getStackTrace();
int currentIdx = innerTrace.length - snapshot.getStack().size();

if (currentIdx < 0) {
// This means the innerTrace was truncated by the underlying environment.
// This is known to happen in AWS Lambda, but may also happen elsewhere.
currentIdx = i;
}

if (!sanityCheckSnapshotAssignment(snapshot, innerTrace, currentIdx)) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,44 @@ public void filteringOutErrors() {
verify(manager, times(0)).isAlreadyInstrumented(any());
}

@Test
public void lambdaTruncatedInnerTraceFallback() {
RuntimeException exception =
new RuntimeException("lambda") {
// mock the stacktrace to simulate a truncated one
@Override
public StackTraceElement[] getStackTrace() {
return new StackTraceElement[] {
new StackTraceElement("Main", "handleRequest", "Main.java", 11),
new StackTraceElement(
"jdk.internal.reflect.DirectMethodHandleAccessor",
"invoke",
"Unknown Source",
-1),
new StackTraceElement("java.lang.reflect.Method", "invoke", "Unknown Source", -1)
};
}
};
String fingerprint = Fingerprinter.fingerprint(exception, classNameFiltering);
AgentSpan span = mock(AgentSpan.class);
doAnswer(this::recordTags).when(span).setTag(anyString(), anyString());
when(span.getTag(anyString())).thenAnswer(inv -> spanTags.get(inv.getArgument(0)));
when(span.getTags()).thenReturn(spanTags);
exceptionDebugger.handleException(exception, span);
assertWithTimeout(
() -> exceptionDebugger.getExceptionProbeManager().isAlreadyInstrumented(fingerprint),
Duration.ofSeconds(30));
generateSnapshots(exception);
ExceptionProbeManager.ThrowableState state =
exceptionDebugger.getExceptionProbeManager().getStateByThrowable(exception);
List<Snapshot> snapshots = state.getSnapshots();
// This should hit the `currentIdx < 0` branch and fallback to i=0
exceptionDebugger.handleException(exception, span);
String tagName = String.format(SNAPSHOT_ID_TAG_FMT, 0);
assertTrue(spanTags.containsKey(tagName));
assertEquals(snapshots.get(0).getId(), spanTags.get(tagName));
}

private Object recordTags(InvocationOnMock invocationOnMock) {
Object[] args = invocationOnMock.getArguments();
String key = (String) args[0];
Expand Down
Loading