Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,14 @@ private void serializeStackTraceElement(StackTraceElement stacktrace) {
jw.writeByte(OBJECT_START);
writeField("filename", stacktrace.getFileName());
writeField("function", stacktrace.getMethodName());
writeField("library_frame", isLibraryFrame(stacktrace.getClassName()));
String className = stacktrace.getClassName();
writeField("library_frame", isLibraryFrame(className));
writeField("lineno", stacktrace.getLineNumber());
serializeStackFrameModule(stacktrace.getClassName());
int lastDotIndex = className.lastIndexOf('.');
if (lastDotIndex > 0) {
writeField("abs_path", className.substring(0, lastDotIndex).replace('.', '/') + "/" + stacktrace.getFileName());
Copy link
Contributor

Choose a reason for hiding this comment

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

This allocates two String objects (substring() and replace()) for each stack frame of each span. Can we use a char-copy to a StringBuilder that includes the char replacement as well?
If so, can it also be used for handling inner classes, lambdas and the like or that using getFileName() will always be safer?

}
serializeStackFrameModule(className);
jw.writeByte(OBJECT_END);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void testErrorSerialization() throws IOException {
assertThat(stackTraceElement.get("library_frame")).isNotNull();
assertThat(stackTraceElement.get("lineno")).isNotNull();
assertThat(stackTraceElement.get("module")).isNotNull();
assertThat(stackTraceElement.get("abs_path").textValue()).isEqualTo(stackTraceElement.get("module").textValue().replace('.', '/') + "/" + stackTraceElement.get("filename").textValue());
assertThat(exception.get("type").textValue()).isEqualTo(Exception.class.getName());
assertThat(errorTree.get("transaction").get("sampled").booleanValue()).isTrue();
assertThat(errorTree.get("transaction").get("type").textValue()).isEqualTo("test-type");
Expand Down