Skip to content

Comments

Add symbol based backtrace filtering#131

Open
MilesConn wants to merge 2 commits intorootcause-rs:mainfrom
MilesConn:miles/add-symbol-based-backtrace-filtering
Open

Add symbol based backtrace filtering#131
MilesConn wants to merge 2 commits intorootcause-rs:mainfrom
MilesConn:miles/add-symbol-based-backtrace-filtering

Conversation

@MilesConn
Copy link

I was really excited to use rootcause but I was working on a project where crates were vendored with a build system that wasn't cargo and I had other non rust code in my backtraces. It seemed that I couldn't get backtrace filtering to work for either of those things.

I changed the backtrace filtering logic to now filter based on demangled symbol name instead of paths. This allows filtering to work with vendored crates or other scenarios where the crates aren't located in .registry.

As a fallback, I also added a new skipped_path_patterns field that allows filtering based on path as well.

Testing

In a demo project I had given this full backtrace

 ● A
 ├ src/main.rs:71
 ╰ Backtrace
   │ trace                - /Users/***/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/backtrace-0.3.76/src/backtrace/libunwind.rs:117
   │ trace_unsynchronized - /Users/***/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/backtrace-0.3.76/src/backtrace/mod.rs:66
   │ trace                - /Users/***/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/backtrace-0.3.76/src/backtrace/mod.rs:53
   │ capture              - /Users/***/Projects/rootcause/rootcause-backtrace/src/lib.rs:763
   │ on_sendsync_creation - /Users/***/Projects/rootcause/rootcause-backtrace/src/lib.rs:686
   │ on_sendsync_creation - /Users/***/Projects/rootcause/src/hooks/report_creation.rs:289
   │ call                 - /Users/***/Projects/rootcause/src/hooks/report_creation.rs:506
   │ use_hooks            - /Users/***/Projects/rootcause/src/hooks/mod.rs:872
   │ run_creation_hooks_sendsync
   │    - /Users/***/Projects/rootcause/src/hooks/report_creation.rs:517
   │ run_creation_hooks   - /Users/***/Projects/rootcause/src/markers.rs:659
   │ from_parts           - /Users/***/Projects/rootcause/src/report/owned.rs:313
   │ new_custom           - /Users/***/Projects/rootcause/src/report/owned.rs:283
   │ new                  - /Users/***/Projects/rootcause/src/report/owned.rs:255
   │ from                 - /Users/***/Projects/rootcause/src/report/owned.rs:1753
   │ from_residual        - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:2184
   │ foo                  - /Users/***/Projects/playground/src/main.rs:71
   │ main                 - /Users/***/Projects/playground/src/main.rs:195
   │ call_once            - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250
   │ rust_begin_short_backtrace
   │    - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:158
   │ {{closure}}          - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:206
   │ call_once            - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/core/src/ops/function.rs:287
   │ do_call              - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:590
   │ catch_unwind         - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:553
   │ catch_unwind         - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panic.rs:359
   │ {{closure}}          - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/rt.rs:175
   │ do_call              - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:590
   │ catch_unwind         - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panicking.rs:553
   │ catch_unwind         - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/panic.rs:359
   │ lang_start_internal  - /rustc/ded5c06cf21d2b93bffd5d884aa6e96934ee4234/library/std/src/rt.rs:171
   │ lang_start           - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:205
   ╰─

with this filter

BacktraceFilter {
                skipped_initial_crates: &["backtrace"],
                skipped_middle_crates: &["rootcause", "rootcause-backtrace"],
                skipped_final_crates: &[],
                max_entry_count: usize::MAX,
                show_full_path: true,
                skipped_path_patterns: &["rustc"],
            },

I now get

 ● A
 ├ src/main.rs:71
 ╰ Backtrace
   │ capture       - /Users/***/Projects/rootcause/rootcause-backtrace/src/lib.rs:763
   │ ... omitted 10 frame(s) from crate 'rootcause' ...
   │ from_residual - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:2184
   │ foo           - /Users/***/Projects/playground/src/main.rs:71
   │ main          - /Users/***/Projects/playground/src/main.rs:195
   │ call_once     - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250
   │ rust_begin_short_backtrace
   │    - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:158
   │ {{closure}}   - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:206
   │ lang_start    - /Users/***/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs:205
   │ note: 23 frame(s) omitted. For a complete backtrace, set RUST_BACKTRACE=full.
   ╰─

I also made another small change that RUST_BACKTRACE=full now ignores all filtering. Anyways, open to feedback and thanks for the project!

… This

allows crate filtering to work for vendored crates or for build systems that are
not cargo.

Additionally, this adds a `skipped_path_patterns` options to `BackTraceFilter`
that allows filtering of non rust dependencies like glibc, or test harnesses
like gsuite. Note, this last change requires a semver bump.
@TethysSvensson
Copy link
Contributor

Can you be a bit more specific about what didn't work for you, what you tried (and failed) to do and how this fixes it?

As far as I remember from the last time I looked at this code, it's hard to get consistent results using only the symbol names, specially when using debug = "line-tables".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants