-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ref(backtrace): add entries and extra logic for in-app detection #756
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,8 @@ use sentry_core::protocol::{Frame, Stacktrace}; | |
|
||
use crate::utils::function_starts_with; | ||
|
||
const WELL_KNOWN_SYS_MODULES: &[&str] = &[ | ||
const WELL_KNOWN_NOT_IN_APP: &[&str] = &[ | ||
// standard library and sentry crates | ||
"std::", | ||
"core::", | ||
"alloc::", | ||
|
@@ -13,11 +14,14 @@ const WELL_KNOWN_SYS_MODULES: &[&str] = &[ | |
// these are not modules but things like __rust_maybe_catch_panic | ||
"__rust_", | ||
"___rust_", | ||
"rust_begin_unwind", | ||
// these are well-known library frames | ||
"anyhow::", | ||
"log::", | ||
"tokio::", | ||
"tracing_core::", | ||
"futures_core::", | ||
"futures_util::", | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not add too specific stuff but this seems common enough to be here |
||
]; | ||
|
||
const WELL_KNOWN_BORDER_FRAMES: &[&str] = &[ | ||
|
@@ -39,7 +43,7 @@ where | |
.iter() | ||
.rev() | ||
.position(|frame| match frame.function { | ||
Some(ref func) => is_well_known(func) || f(frame, stacktrace), | ||
Some(ref func) => is_well_known_border_frame(func) || f(frame, stacktrace), | ||
None => false, | ||
}); | ||
|
||
|
@@ -49,15 +53,15 @@ where | |
} | ||
} | ||
|
||
/// Checks if a function is considered to be not in-app | ||
pub fn is_sys_function(func: &str) -> bool { | ||
WELL_KNOWN_SYS_MODULES | ||
/// Checks if a function is from a module that shall be considered not in-app by default | ||
pub fn is_well_known_not_in_app(func: &str) -> bool { | ||
WELL_KNOWN_NOT_IN_APP | ||
.iter() | ||
.any(|m| function_starts_with(func, m)) | ||
} | ||
|
||
/// Checks if a function is a well-known system function | ||
fn is_well_known(func: &str) -> bool { | ||
/// Checks if a function is a well-known border frame | ||
fn is_well_known_border_frame(func: &str) -> bool { | ||
WELL_KNOWN_BORDER_FRAMES | ||
.iter() | ||
.any(|m| function_starts_with(func, m)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,12 +97,15 @@ pub fn demangle_symbol(s: &str) -> String { | |
/// | ||
/// In trait implementations, the original type name is wrapped in "_< ... >" and colons are | ||
/// replaced with dots. This function accounts for differences while checking. | ||
/// The `<F as ` pattern is a special case that can often be observed in frames involving futures-rs traits. | ||
pub fn function_starts_with(mut func_name: &str, mut pattern: &str) -> bool { | ||
if pattern.starts_with('<') { | ||
while pattern.starts_with('<') { | ||
pattern = &pattern[1..]; | ||
|
||
if func_name.starts_with('<') { | ||
if func_name.starts_with("<F as ") { | ||
func_name = &func_name[6..]; | ||
} else if func_name.starts_with('<') { | ||
func_name = &func_name[1..]; | ||
} else if func_name.starts_with("_<") { | ||
func_name = &func_name[2..]; | ||
|
@@ -111,7 +114,10 @@ pub fn function_starts_with(mut func_name: &str, mut pattern: &str) -> bool { | |
} | ||
} | ||
} else { | ||
func_name = func_name.trim_start_matches('<').trim_start_matches("_<"); | ||
func_name = func_name | ||
.trim_start_matches("<F as ") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specific case that can be commonly observed in raw frames related to |
||
.trim_start_matches('<') | ||
.trim_start_matches("_<"); | ||
} | ||
|
||
if !func_name.is_char_boundary(pattern.len()) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is always the top frame for panics and ends up in the high level issue description, I would rather have the first in-app frame there
Unless it's intended that we have
rust_begin_unwind
there?