Skip to content
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

fix(js): Recognize more abs_paths as in-app #1505

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion crates/symbolicator-js/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,17 @@ pub fn fixup_webpack_filename(filename: &str) -> String {
}
}

/// Returns whether the given abs_path and filename should be considered in-app.
///
/// This function was originally a simplified (but semantically faithful) version of
/// <https://github.com/getsentry/sentry/blob/69ee8d0fcbff3494f2d2a6fb9fb59195fc49b575/src/sentry/lang/javascript/processor.py#L1573-L1603>.
/// For a version that preserves the original exactly (modulo Python -> Rust translation), see
/// `is_in_app_faithful`.
pub fn is_in_app(abs_path: &str, filename: &str) -> Option<bool> {
if abs_path.starts_with("webpack:") {
Some(filename.starts_with("./") && !filename.contains("/node_modules/"))
// This diverges from the original logic. Previously we would only consider
// a filename starting with `./` as in-app, but that seems to be overly strict.
Some(!filename.starts_with("~/") && !filename.contains("/node_modules/"))
loewenheim marked this conversation as resolved.
Show resolved Hide resolved
} else if abs_path.starts_with("app:") {
Some(!NODE_MODULES_RE.is_match(filename))
} else if abs_path.contains("/node_modules/") {
Expand Down Expand Up @@ -713,6 +721,20 @@ mod tests {
assert_eq!(is_in_app(abs_path, filename), Some(true));
assert_eq!(is_in_app_faithful(abs_path, filename), Some(true));

let abs_path = "webpack:///foo/bar/src/App.jsx";
let filename = "foo/bar/src/App.jsx";

// Here we have a discrepancy because the behavior of `is_in_app`
// longer aligns with that of the original Python version.
assert_eq!(is_in_app(abs_path, filename), Some(true));
assert_eq!(is_in_app_faithful(abs_path, filename), Some(false));

let abs_path = "webpack:///./foo/bar/App.tsx";
let filename = "./foo/bar/src/App.jsx";

assert_eq!(is_in_app(abs_path, filename), Some(true));
assert_eq!(is_in_app_faithful(abs_path, filename), Some(true));

let abs_path = "webpack:///./node_modules/@sentry/browser/esm/helpers.js";
let filename = "./node_modules/@sentry/browser/esm/helpers.js";

Expand Down
Loading