I'm having some trouble with the receipt of backtraces/stacktraces when handling panic!()
, and I suspect that it may have something to do with Tokio. Here's the setup I have:
// panic.rs
static INIT: Once = Once::new();
pub fn setup() {
INIT.call_once(|| {
let next = panic::take_hook();
panic::set_hook(Box::new(move |info| {
let backtrace = backtrace::Backtrace::new();
error!(message = "panic", "\n{:?}\n", backtrace);
next(info);
}));
});
}
// lib.rs
pub async fn start() {
let spawn_1 = tokio::spawn(async move {
my_function_panic(); // Call 1
});
let spawn_2 = tokio::spawn(async move {
tokio::time::sleep(Duration::from_secs(1)).await;
my_function_panic(); // Call 2
});
....
}
fn my_function_panic() {
panic!("panic on purpose")
}
My issue is that the stack trace only seems to indicate the start of the trace, thread 'tokio-runtime-worker' panicked at 'panic on purpose', hub/src/lib.rs:68:5
.
Here full logs:
I'm particularly interested in these lines:
services-hub-1 | 18: 0x55bbd66a34ef - hub::my_function_panic::hc38316ec909fd2ac
services-hub-1 | 19: 0x55bbd6650df4 - hub::start::{{closure}}::{{closure}}::hd8adc338b2bb8070
What I'm finding is that the line numbers are missing.
Here are the environmental variables I'm using at runtime:
RUST_LIB_BACKTRACE=1
RUST_BACKTRACE=1
RUST_BACKTRACE=full