Skip to content

Preserve exception tracebacks in Beeper JSON logs - #66

Merged
iFixRobots merged 2 commits into
beeperfrom
iFixRobots/preserve-json-exception-tracebacks
Oct 1, 2026
Merged

iFixRobots merged 2 commits into
beeperfrom
iFixRobots/preserve-json-exception-tracebacks

Conversation

@iFixRobots

@iFixRobots iFixRobots commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

I noticed that BeeperTerseJsonFormatter drops the useful part of an exception. Callers pass exc_info=(type, value, traceback), but the shared JSON formatter only emits exc_type and exc_value. A KeyError therefore tells us which key was missing without showing the file, function, or line that tried to read it.

This adds an exc_traceback field to the Beeper formatter using Python's existing formatException. The original fields and request metadata stay intact, and traceback newlines are JSON-escaped so each record remains one physical log line. Ordinary records are unchanged. The upstream JSON formatters and the GCP formatter are left alone.

I exercised the actual formatter with an ordinary record, a chained KeyError/RuntimeError, and exc_info=True without an active exception. The chained traceback survived JSON decoding, all three records remained single-line JSON, and local-variable values were not captured. The existing Trial formatter suite could not start locally because Twisted is not installed.

The first CI image build failed before building Python: the workflow used the branch name verbatim as a Docker tag, and / is not valid in a tag. I also normalized branch-name slashes to - in that step; release-version tags are unchanged.

@iFixRobots
iFixRobots requested a review from Fizzadar September 28, 2026 22:41
@iFixRobots
iFixRobots marked this pull request as ready for review September 29, 2026 01:25
@indent

indent Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
PR Summary

Beeper's JSON log formatter previously kept only the exception type and message, so logged errors lost their file/line context. This PR adds the formatted traceback to those records and fixes CI image builds for branch names containing /.

  • BeeperTerseJsonFormatter adds an exc_traceback field (from Formatter.formatException, chained exceptions included) whenever a record carries a real exception. exc_type, exc_value, and extras are unchanged. Records stay single-line JSON.
  • Upstream JsonFormatter/TerseJsonFormatter and GcpJsonFormatter are untouched.
  • beeper-ci.yaml replaces / with - in branch-derived Docker tags. Release tags on beeper are unchanged.

Issues

1 potential issue found:

  • No test in tests/logging/test_terse_json.py covers BeeperTerseJsonFormatter or the new exc_traceback field, so a later upstream merge could drop Beeper tracebacks without anyone noticing. Add a small exception test next to the existing JsonFormatter one.

↑ Select any checkbox above to have Indent auto-fix the issue

"time": round(record.created, 2),
}
if record.exc_info and record.exc_info[0]:
event["exc_traceback"] = self.formatException(record.exc_info)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪️ Nit · No test for the new exc_traceback field

JsonFormatter and GcpJsonFormatter both have exception tests (test_with_exception, test_gcp_json_with_exception), but nothing tests BeeperTerseJsonFormatter. I ran the formatter by hand and it works: chained traceback present, one line per record, nothing emitted for exc_info=True with no active exception. A test would keep that behavior from regressing when upstream changes to JsonFormatter._format get merged in.

@iFixRobots
iFixRobots merged commit da000cc into beeper Oct 1, 2026
7 checks passed
@iFixRobots
iFixRobots deleted the iFixRobots/preserve-json-exception-tracebacks branch October 1, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants