Skip to content

Commit df0491c

Browse files
authored
ref(backtrace): add entries and extra logic for in-app detection (#756)
* ref(backtrace): add entries and extra logic for in-app detection
1 parent e9661c7 commit df0491c

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

sentry-backtrace/src/process.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::borrow::Cow;
33
use backtrace::Backtrace;
44
use sentry_core::ClientOptions;
55

6-
use crate::trim::{is_sys_function, trim_stacktrace};
6+
use crate::trim::{is_well_known_not_in_app, trim_stacktrace};
77
use crate::utils::{
88
demangle_symbol, filename, function_starts_with, parse_crate_name, strip_symbol,
99
};
@@ -72,7 +72,7 @@ pub fn process_event_stacktrace(stacktrace: &mut Stacktrace, options: &ClientOpt
7272
continue;
7373
}
7474

75-
if is_sys_function(func_name) {
75+
if is_well_known_not_in_app(func_name) {
7676
frame.in_app = Some(false);
7777
}
7878
}

sentry-backtrace/src/trim.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use sentry_core::protocol::{Frame, Stacktrace};
22

33
use crate::utils::function_starts_with;
44

5-
const WELL_KNOWN_SYS_MODULES: &[&str] = &[
5+
const WELL_KNOWN_NOT_IN_APP: &[&str] = &[
6+
// standard library and sentry crates
67
"std::",
78
"core::",
89
"alloc::",
@@ -13,11 +14,14 @@ const WELL_KNOWN_SYS_MODULES: &[&str] = &[
1314
// these are not modules but things like __rust_maybe_catch_panic
1415
"__rust_",
1516
"___rust_",
17+
"rust_begin_unwind",
1618
// these are well-known library frames
1719
"anyhow::",
1820
"log::",
1921
"tokio::",
2022
"tracing_core::",
23+
"futures_core::",
24+
"futures_util::",
2125
];
2226

2327
const WELL_KNOWN_BORDER_FRAMES: &[&str] = &[
@@ -39,7 +43,7 @@ where
3943
.iter()
4044
.rev()
4145
.position(|frame| match frame.function {
42-
Some(ref func) => is_well_known(func) || f(frame, stacktrace),
46+
Some(ref func) => is_well_known_border_frame(func) || f(frame, stacktrace),
4347
None => false,
4448
});
4549

@@ -49,15 +53,15 @@ where
4953
}
5054
}
5155

52-
/// Checks if a function is considered to be not in-app
53-
pub fn is_sys_function(func: &str) -> bool {
54-
WELL_KNOWN_SYS_MODULES
56+
/// Checks if a function is from a module that shall be considered not in-app by default
57+
pub fn is_well_known_not_in_app(func: &str) -> bool {
58+
WELL_KNOWN_NOT_IN_APP
5559
.iter()
5660
.any(|m| function_starts_with(func, m))
5761
}
5862

59-
/// Checks if a function is a well-known system function
60-
fn is_well_known(func: &str) -> bool {
63+
/// Checks if a function is a well-known border frame
64+
fn is_well_known_border_frame(func: &str) -> bool {
6165
WELL_KNOWN_BORDER_FRAMES
6266
.iter()
6367
.any(|m| function_starts_with(func, m))

sentry-backtrace/src/utils.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ pub fn demangle_symbol(s: &str) -> String {
9797
///
9898
/// In trait implementations, the original type name is wrapped in "_< ... >" and colons are
9999
/// replaced with dots. This function accounts for differences while checking.
100+
/// The `<F as ` pattern is a special case that can often be observed in frames involving futures-rs traits.
100101
pub fn function_starts_with(mut func_name: &str, mut pattern: &str) -> bool {
101102
if pattern.starts_with('<') {
102103
while pattern.starts_with('<') {
103104
pattern = &pattern[1..];
104105

105-
if func_name.starts_with('<') {
106+
if func_name.starts_with("<F as ") {
107+
func_name = &func_name[6..];
108+
} else if func_name.starts_with('<') {
106109
func_name = &func_name[1..];
107110
} else if func_name.starts_with("_<") {
108111
func_name = &func_name[2..];
@@ -111,7 +114,10 @@ pub fn function_starts_with(mut func_name: &str, mut pattern: &str) -> bool {
111114
}
112115
}
113116
} else {
114-
func_name = func_name.trim_start_matches('<').trim_start_matches("_<");
117+
func_name = func_name
118+
.trim_start_matches("<F as ")
119+
.trim_start_matches('<')
120+
.trim_start_matches("_<");
115121
}
116122

117123
if !func_name.is_char_boundary(pattern.len()) {

0 commit comments

Comments
 (0)