Repository: getsentry/sentry

Issue:
SDK Crash Detection: Set in app
Set all in app for all frames to `false` except for the SDK frames after stripping the event data. 

https://github.com/getsentry/sentry/blob/95086b406dec79e6bcef45f299a3e92f727da2c0/src/sentry/utils/sdk_crashes/sdk_crash_detection.py#L58


Discussion:

Resolving patch:
diff --git a/src/sentry/utils/sdk_crashes/event_stripper.py b/src/sentry/utils/sdk_crashes/event_stripper.py
--- a/src/sentry/utils/sdk_crashes/event_stripper.py
+++ b/src/sentry/utils/sdk_crashes/event_stripper.py
@@ -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
@@ -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
@@ -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.
@@ -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)
     ]


Test patch:
diff --git a/tests/sentry/utils/sdk_crashes/test_event_stripper.py b/tests/sentry/utils/sdk_crashes/test_event_stripper.py
--- a/tests/sentry/utils/sdk_crashes/test_event_stripper.py
+++ b/tests/sentry/utils/sdk_crashes/test_event_stripper.py
@@ -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(),
@@ -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",
         }