Log panics through tracing so they reach the rolling log file#241
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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-panicdependency tobeacon-api. - Install a panic hook after
setup_tracing()that emits panics astracingERRORevents while chaining the default panic hook. - Update
Cargo.lockto 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 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 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 | ||
| })); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
tracingat 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