Skip to content

feat(sdk-crash): Keep sdk frame path for native #68685

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

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions fixtures/sdk_crash_detection/crash_event_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@


def get_frames(
sdk_frame_function: str, system_frame_package: str
sdk_frame_function: str,
sdk_frame_package: str,
system_frame_package: str,
) -> Sequence[MutableMapping[str, str]]:
frames = [
{
Expand All @@ -24,7 +26,7 @@ def get_frames(
{
"function": sdk_frame_function,
"symbol": sdk_frame_function,
"package": "E:\\Sentry\\Sentaurs\\Game\\Sentaurs.exe",
"package": sdk_frame_package,
},
{
"function": "boost::serialization::singleton<T>::singleton<T>",
Expand All @@ -37,11 +39,12 @@ def get_frames(

def get_crash_event(
sdk_frame_function="sentry_value_to_msgpack",
sdk_frame_package="E:\\Sentry\\Sentaurs\\Game\\Sentaurs.exe",
system_frame_package="C:\\Windows\\System32\\DriverStore\\FileRepository\\u0398226.inf_amd64_c5d9587384e4b5ff\\B398182\\amdxx64.dll",
**kwargs,
) -> dict[str, object]:
return get_crash_event_with_frames(
get_frames(sdk_frame_function, system_frame_package),
get_frames(sdk_frame_function, sdk_frame_package, system_frame_package),
**kwargs,
)

Expand Down
10 changes: 6 additions & 4 deletions src/sentry/utils/sdk_crashes/sdk_crash_detection_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ def build_sdk_crash_detection_configs() -> Sequence[SDKCrashDetectionConfig]:
r"sentry__*", # module level interface
r"Java_io_sentry_android_ndk_*", # JNI interface
},
# The native SDK usually has the same path as the application binary.
# Therefore, we can't rely on it. We set a fixed path of Sentry for
# the SDK frames are so it's not empty.
path_patterns=set(),
path_replacer=FixedPathReplacer(path="sentry"),
path_replacer=KeepAfterPatternMatchPathReplacer(
patterns={
r"sentry_.*",
},
fallback_path="sentry",
),
),
sdk_crash_ignore_functions_matchers=set(),
)
Expand Down
56 changes: 56 additions & 0 deletions tests/sentry/utils/sdk_crashes/test_sdk_crash_detection_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,62 @@ def test_sdk_crash_is_reported_with_native_paths(
assert mock_sdk_crash_reporter.report.call_count == 0


@pytest.mark.parametrize(
["sdk_frame_function", "sdk_frame_package", "expected_sdk_frame_package"],
[
(
"sentry_sync",
"C:\\GitLab-Runner\\builds\\WEFASW\\0\\3rdParty\\Sentry\\upstream\\src\\sentry_sync.h",
"sentry_sync.h",
),
(
"sentry_value_to_msgpack",
"sentry._sentry.h",
"sentry",
),
(
"sentry_value_to_msgpack",
"some_weird_path/sentry__.h",
"sentry__.h",
),
],
)
@decorators
def test_sdk_crash_sentry_native_keeps_sentry_package_paths(
mock_sdk_crash_reporter,
mock_random,
store_event,
configs,
sdk_frame_function,
sdk_frame_package,
expected_sdk_frame_package,
):
event = store_event(
data=get_crash_event(
sdk_frame_function=sdk_frame_function, sdk_frame_package=sdk_frame_package
)
)

configs[1].organization_allowlist = [event.project.organization_id]

sdk_crash_detection.detect_sdk_crash(event=event, configs=configs)

assert mock_sdk_crash_reporter.report.call_count == 1
reported_event_data = mock_sdk_crash_reporter.report.call_args.args[0]

stripped_frames = get_path(
reported_event_data, "exception", "values", -1, "stacktrace", "frames"
)

assert len(stripped_frames) == 4

sdk_frame = stripped_frames[2]
assert sdk_frame["function"] == sdk_frame_function
assert sdk_frame["symbol"] == sdk_frame_function
assert sdk_frame["package"] == expected_sdk_frame_package
assert sdk_frame["in_app"] is True


@decorators
def test_beta_sdk_version_detected(mock_sdk_crash_reporter, mock_random, store_event, configs):
event_data = get_crash_event()
Expand Down
Loading