fix: collapse redundant stack trace lines in error logs - #1506
fix: collapse redundant stack trace lines in error logs#1506aksingh737 wants to merge 2 commits into
Conversation
We get a lot of repeated log lines. This code change changes it so that the repeated lines are shows as a count. For example instead of seeing something like x x x ... we see x repeated n times
alexeyqu
left a comment
There was a problem hiding this comment.
I understand the approach, but there are some caveats.
This PR reimplements Guava's Throwables.getStackTraceAsString(e) with a custom formatter. For a replacement like that to be safe, it needs to cover the same ground as what it's replacing:
- Suppressed exceptions are silently dropped.
ExceptionUtils.getStackTraceAsStringonly walkst.getCause(), nevert.getSuppressed(). Guava's version delegates toThrowable.printStackTrace(), which printsSuppressed: ...sections (e.g. from try-with-resources). Was dropping that intentional, or an oversight? - A couple of call sites still use the old path, e.g.
StackdriverMonitor.java:65andGoogleCloudIdempotentImportExecutor.java:91inextensions/cloud/portability-cloud-google/. Left as-is, we now have two divergent stack-trace formatters in the codebase, and this is a standing risk for future drift (both in the open-source DTP and in modules that can be added via@Inject). - No tests on
ExceptionUtilsitself -- nothing exercises the actual collapsing behavior (repeated frames, nested causes) to confirm the output is correct.
Given that, what about keeping Guava's Throwables.getStackTraceAsString(e) as-is and adding a small post-processing step that operates on the resulting string to collapse duplicate lines?
That way we inherit correct cause/suppressed/cycle handling for free from the JDK and Guava, and only own the one genuinely new piece of logic (collapsing consecutive repeats) -- which is also easy to unit test in isolation and drop into all the call sites uniformly. I think that'd be more durable long-term.
Let's discuss.
|
Those are great catches and suggestions. In regards to your question whether this was intentional or oversight - most of them were from oversight instead of being intentional. I will refactor the code to do the below
Please let me know if that sounds good and I will update the code accordingly. |
|
Sounds good @aksingh737. One more thing worth checking: If My gut feeling is |
fix: collapse redundant stack trace lines in error logs
We get a lot of repeated log lines. This code change changes it so that the repeated lines are shows as a count.
For example instead of seeing something like
x
x
x
...
we see
x
repeated n times