Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
unit test
  • Loading branch information
nhulston committed May 19, 2025
commit a60af39e5967d8bd23c3be8ce4e1a0e0ee4a8589
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,39 @@ public void filteringOutErrors() {
verify(manager, times(0)).isAlreadyInstrumented(any());
}

@Test
public void lambdaTruncatedInnerTraceFallback() {
RuntimeException exception = new RuntimeException("lambda");
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();
StackTraceElement ste = exception.getStackTrace()[0];
CapturedStackFrame dummyFrame = CapturedStackFrame.from(ste);
for (Snapshot snap : snapshots) {
snap.getStack().add(0, dummyFrame);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we mock instead the exception that is provided to handleException instead to return a truncated stack like what it is done by AWS lambda?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LMK what you think -- i ended up having to mock the snapshot, probe, exception state, and exception probe manager

Copy link
Copy Markdown
Member

@jpbempel jpbempel May 20, 2025

Choose a reason for hiding this comment

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

i ended up having to mock the snapshot, probe, exception state, and exception probe manager

I am not sure it is necessary to do all of that, collecting real exception in snapshot is what happen anyway.
What matters is the truncated stacktrace for main exception


// 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