Skip to content

Log panics through tracing so they reach the rolling log file#241

Merged
robinskil merged 1 commit into
mainfrom
claude/vigilant-sinoussi-adb2dd
Jun 11, 2026
Merged

Log panics through tracing so they reach the rolling log file#241
robinskil merged 1 commit into
mainfrom
claude/vigilant-sinoussi-adb2dd

Conversation

@robinskil

Copy link
Copy Markdown
Collaborator

Rust's default panic hook writes only to stderr, so panics never reached the rolling file appender (logs/beacon.log.*), making post-mortem debugging from log files impossible.

Install a panic hook in async_main() (right after setup_tracing) that routes panics through tracing at ERROR level via the tracing-panic crate, while chaining the default hook to preserve stderr output. Panics now appear in both stdout and the rolling log file with message, location, and (when RUST_BACKTRACE is set) a backtrace.

Closes #239

Rust's default panic hook writes only to stderr, so panics never reached
the rolling file appender (logs/beacon.log.*), making post-mortem
debugging from log files impossible.

Install a panic hook in async_main() (right after setup_tracing) that
routes panics through `tracing` at ERROR level via the tracing-panic
crate, while chaining the default hook to preserve stderr output. Panics
now appear in both stdout and the rolling log file with message,
location, and (when RUST_BACKTRACE is set) a backtrace.

Closes #239
@robinskil robinskil self-assigned this Jun 11, 2026
Copilot AI review requested due to automatic review settings June 11, 2026 10:37
@robinskil robinskil added the bug Something isn't working label Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves operational observability of the beacon-api binary by installing a custom panic hook that routes panics through tracing, allowing panic messages/backtraces to land in the existing rolling file appender (logs/beacon.log.*) in addition to the default stderr output.

Changes:

  • Add tracing-panic dependency to beacon-api.
  • Install a panic hook after setup_tracing() that emits panics as tracing ERROR events while chaining the default panic hook.
  • Update Cargo.lock to include the new crate.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
Cargo.lock Adds the tracing-panic crate to the lockfile.
beacon-api/src/main.rs Installs a panic hook that logs panics through tracing and preserves default stderr behavior.
beacon-api/Cargo.toml Adds the tracing-panic dependency for the API binary.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread beacon-api/src/main.rs
Comment on lines 39 to 43
/// Initializes shared services and starts all configured API transports.
async fn async_main() -> anyhow::Result<()> {
setup_tracing();
install_panic_hook();

Comment thread beacon-api/src/main.rs
Comment on lines +88 to +92
let default_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |info| {
tracing_panic::panic_hook(info); // ERROR event -> stdout + rolling log file
default_hook(info); // preserve default stderr output
}));
@robinskil robinskil merged commit 17feb09 into main Jun 11, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panics not logged

2 participants