Skip to content

Commit

Permalink
Use backtrace_ext for filtering backtrace noise (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai authored Apr 11, 2023
1 parent 9e4c362 commit 0284936
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions shotover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typetag.workspace = true
thiserror = "1.0"
anyhow.workspace = true
backtrace = "0.3.66"
backtrace-ext = "0.2"

# Parsers
cql3-parser = "0.3.2"
Expand Down
34 changes: 3 additions & 31 deletions shotover/src/tracing_panic_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use backtrace::{Backtrace, BacktraceFmt, BacktraceFrame, BytesOrWideString, PrintFmt};
use backtrace::{Backtrace, BacktraceFmt, BytesOrWideString, PrintFmt};
use std::fmt;

pub fn setup() {
Expand Down Expand Up @@ -49,37 +49,9 @@ impl fmt::Display for BacktraceFormatter {

let mut f = BacktraceFmt::new(f, PrintFmt::Short, &mut print_path);
f.add_context()?;
let mut include_frames = false;
for frame in self.0.frames() {
if frame_is_named(
frame,
"std::sys_common::backtrace::__rust_begin_short_backtrace",
) {
break;
}

if include_frames {
f.frame().backtrace_frame(frame)?;
}

if frame_is_named(
frame,
"std::sys_common::backtrace::__rust_end_short_backtrace",
) {
include_frames = true;
}
for (frame, _) in backtrace_ext::short_frames_strict(&self.0) {
f.frame().backtrace_frame(frame)?;
}
f.finish()
}
}

fn frame_is_named(frame: &BacktraceFrame, name: &str) -> bool {
for symbol in frame.symbols() {
if let Some(full_name) = symbol.name() {
if format!("{}", full_name).starts_with(name) {
return true;
}
}
}
false
}

0 comments on commit 0284936

Please sign in to comment.