Skip to content

Add support to collapse JavaStackTrace into a single event#39

Merged
bgaudin-lc merged 2 commits into
mainfrom
BRONTO-2005
Oct 1, 2025
Merged

Add support to collapse JavaStackTrace into a single event#39
bgaudin-lc merged 2 commits into
mainfrom
BRONTO-2005

Conversation

@bgaudin-lc

@bgaudin-lc bgaudin-lc commented Sep 30, 2025

Copy link
Copy Markdown
Contributor

This change introduces an aggregator that collapse Java stack traces split over multiple line into a single one. It is a best effort, assuming that the events of the split stack trace will be provided (e.g. by Cloudwatch) consecutively.

This change also automates the running of this project unit tests.

Tested in a dev environment:
Screenshot 2025-09-30 at 16 18 45

Comment thread tests/test_parser.py Outdated
def test_java_stacktrace():
parser = ParserFactory.get_parser(CLOUDWATCH_LOG_TYPE, None)
parsed = parser.parse(JAVA_STACK_TRACE)
assert True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

do we need to assert anything else?

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.

Good spot. I didn't realise that Claude Code changed tests there. I didn't ask it to! I'll fix it up.

""" Inspired from https://www.elastic.co/docs/reference/beats/filebeat/multiline-examples#_java_stack_traces """

def __init__(self):
self.lines = Queue(maxsize=2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this seems small? im presuming this is the number of lines in the stacktrace?

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.

I need to rename or introduce an intermediary class as I agree that the current implementation doesn't help understand the intent.

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.

I changed the Aggregator class API. We can probably do better still but at least it should be clearer now. The bottom line is that we keep a line in the aggregator that is not ready to be consumed until we know that the aggregation is completed. In general, the aggregation for a line is complete if we the next doesn't look like a stacktrace one. We also need to complete the aggregation for the last line encountered, as there is no next one in that case.

Comment thread log_forwarder/exporter.py Outdated
self.batch.reset()
self.aggregator.add_line(None) # poison pill
_line = self.aggregator.get_line()
if _line is not None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if _line is not None:
if _line:

@bgaudin-lc
bgaudin-lc merged commit 3e8a601 into main Oct 1, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants