Skip to content

Commit

Permalink
feat(sdk-crash-detection): Set in app for SDK frames (#52083)
Browse files Browse the repository at this point in the history
Set in_app to true only for SDK frames and to false for all others.

Closes #51024
  • Loading branch information
philipphofmann authored Jul 3, 2023
1 parent 842495d commit 2c768b6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/sentry/utils/sdk_crashes/event_stripper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum, auto
from typing import Any, Dict, Mapping, Optional, Sequence
from typing import Any, Dict, Mapping, MutableMapping, Optional, Sequence

from sentry.db.models import NodeData
from sentry.utils.safe import get_path
Expand Down Expand Up @@ -98,11 +98,11 @@ def strip_event_data(
if (new_event_data is None) or (new_event_data == {}):
return {}

stripped_frames: Sequence[Mapping[str, Any]] = []
frames = get_path(new_event_data, "exception", "values", -1, "stacktrace", "frames")

if frames is not None:
stripped_frames = _strip_frames(frames, sdk_crash_detector)

new_event_data["exception"]["values"][0]["stacktrace"]["frames"] = stripped_frames

return new_event_data
Expand Down Expand Up @@ -144,7 +144,7 @@ def _strip_event_data_with_allowlist(


def _strip_frames(
frames: Sequence[Mapping[str, Any]], sdk_crash_detector: SDKCrashDetector
frames: Sequence[MutableMapping[str, Any]], sdk_crash_detector: SDKCrashDetector
) -> Sequence[Mapping[str, Any]]:
"""
Only keep SDK frames or Apple system libraries.
Expand All @@ -162,8 +162,15 @@ def is_system_library(frame: Mapping[str, Any]) -> bool:

return False

def strip_frame(frame: MutableMapping[str, Any]) -> MutableMapping[str, Any]:
if sdk_crash_detector.is_sdk_frame(frame):
frame["in_app"] = True
else:
frame["in_app"] = False
return frame

return [
frame
strip_frame(frame)
for frame in frames
if sdk_crash_detector.is_sdk_frame(frame) or is_system_library(frame)
]
36 changes: 35 additions & 1 deletion tests/sentry/utils/sdk_crashes/test_event_stripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,40 @@ def test_strip_event_data_keeps_exception_mechanism(self):
},
}

def test_set_in_app_only_for_sdk_frames(self):
frames = get_frames("SentryCrashMonitor_CPPException.cpp", sentry_frame_in_app=False)

system_frame_in_app = [
{
"abs_path": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
"in_app": True,
}
]

event_data = get_crash_event_with_frames(system_frame_in_app + list(frames))

event = self.create_event(
data=event_data,
project_id=self.project.id,
)

stripped_event_data = strip_event_data(event.data, CocoaSDKCrashDetector())

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

for stripped_frame in stripped_frames[0::-1]:
assert stripped_frame["in_app"] is False

cocoa_sdk_frame = stripped_frames[-1]
assert cocoa_sdk_frame == {
"function": "SentryCrashMonitor_CPPException.cpp",
"package": "/private/var/containers/Bundle/Application/59E988EF-46DB-4C75-8E08-10C27DC3E90E/iOS-Swift.app/Frameworks/Sentry.framework/Sentry",
"in_app": True,
"image_addr": "0x100304000",
}

def test_strip_event_data_keeps_exception_stacktrace(self):
event = self.create_event(
data=get_crash_event(),
Expand Down Expand Up @@ -229,7 +263,7 @@ def test_strip_frames(self):
assert cocoa_sdk_frame == {
"function": "SentryCrashMonitor_CPPException.cpp",
"package": "/private/var/containers/Bundle/Application/59E988EF-46DB-4C75-8E08-10C27DC3E90E/iOS-Swift.app/Frameworks/Sentry.framework/Sentry",
"in_app": False,
"in_app": True,
"image_addr": "0x100304000",
}

Expand Down

0 comments on commit 2c768b6

Please sign in to comment.