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

Only keep in stack trace referenced debug images #46494

Merged
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
22 changes: 20 additions & 2 deletions src/sentry/utils/sdk_crashes/event_stripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@ def strip_event_data(self, event: Event) -> Event:
new_event = dict(filter(self._filter_event, event.items()))
new_event["contexts"] = dict(filter(self._filter_contexts, new_event["contexts"].items()))

stripped_frames = []
frames = get_path(event, "exception", "values", -1, "stacktrace", "frames")
stripped_frames = self._strip_frames(frames)
new_event["exception"]["values"][0]["stacktrace"]["frames"] = stripped_frames

if frames is not None:
stripped_frames = self._strip_frames(frames)
new_event["exception"]["values"][0]["stacktrace"]["frames"] = stripped_frames

debug_meta_images = get_path(event, "debug_meta", "images")
if debug_meta_images is not None:
stripped_debug_meta_images = self._strip_debug_meta(debug_meta_images, stripped_frames)
new_event["debug_meta"]["images"] = stripped_debug_meta_images

return new_event

Expand All @@ -49,6 +57,16 @@ def _filter_contexts(self, pair):
return True
return False

def _strip_debug_meta(
self, debug_meta_images: Sequence[Mapping[str, Any]], frames: Sequence[Mapping[str, Any]]
) -> Sequence[Mapping[str, Any]]:

frame_image_addresses = {frame["image_addr"] for frame in frames}

return [
image for image in debug_meta_images if image["image_addr"] in frame_image_addresses
]

def _strip_frames(self, frames: Sequence[Mapping[str, Any]]) -> Sequence[Mapping[str, Any]]:
"""
Only keep SDK frames or non in app frames.
Expand Down
36 changes: 36 additions & 0 deletions tests/sentry/utils/sdk_crashes/test_event_stripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,39 @@ def test_strip_frames(function, in_app):
len([frame for frame in stripped_frames if frame["function"] == IN_APP_FRAME["function"]])
== 0
), "in_app frame should be removed"


def test_strip_event_data_strips_non_referenced_dsyms():
event_stripper = EventStripper(Mock())

stripped_event = event_stripper.strip_event_data(get_crash_event())

debug_meta_images = get_path(stripped_event, "debug_meta", "images")

image_addresses = set(map(lambda image: image["image_addr"], debug_meta_images))
expected_image_addresses = {"0x1025e8000", "0x102b8c000", "0x102f68000", "0x19c9eb000"}
assert image_addresses == expected_image_addresses


def test_strip_event_data_without_frames():
event_stripper = EventStripper(Mock())

crash_event = get_crash_event()
crash_event["exception"]["values"][0]["stacktrace"]["frames"] = None

stripped_event = event_stripper.strip_event_data(crash_event)

debug_meta_images = get_path(stripped_event, "debug_meta", "images")
assert len(debug_meta_images) == 0


def test_strip_event_data_without_debug_meta():
event_stripper = EventStripper(Mock())

crash_event = get_crash_event()
crash_event["debug_meta"]["images"] = None

stripped_event = event_stripper.strip_event_data(crash_event)

debug_meta_images = get_path(stripped_event, "debug_meta", "images")
assert debug_meta_images is None
56 changes: 49 additions & 7 deletions tests/sentry/utils/sdk_crashes/test_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def get_sentry_frame(function: str, in_app: bool = False) -> Mapping[str, Any]:
"function": function,
"package": "Sentry",
"in_app": in_app,
"image_addr": "0x102f68000",
}


Expand All @@ -31,37 +32,43 @@ def get_frames(function: str, sentry_frame_in_app: bool = False) -> Sequence[Map
"symbol": "$s8Sentry9LoginViewControllerC13viewDidAppearyySbF",
"package": "SentryApp",
"filename": "LoginViewController.swift",
"image_addr": "0x102b8c000",
},
IN_APP_FRAME,
{
"function": "-[UIViewController _setViewAppearState:isAnimating:]",
"symbol": "-[UIViewController _setViewAppearState:isAnimating:]",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
{
"function": "-[UIViewController __viewDidAppear:]",
"symbol": "-[UIViewController __viewDidAppear:]",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
{
"function": "-[UIViewController _endAppearanceTransition:]",
"symbol": "-[UIViewController _endAppearanceTransition:]",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
{
"function": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]",
"symbol": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
{
"function": "__49-[UINavigationController _startCustomTransition:]_block_invoke",
"symbol": "__49-[UINavigationController _startCustomTransition:]_block_invoke",
"package": "UIKitCore",
"in_app": False,
"image_addr": "0x19c9eb000",
},
]

Expand Down Expand Up @@ -139,16 +146,51 @@ def get_crash_event_with_frames(
"type": "os",
},
},
# Todo add referenced in stacktrace
"debug_meta": {
"images": [
{
"name": "CrashProbeiOS",
"image_vmaddr": "0x0000000100000000",
"image_addr": "0x0000000100088000",
"type": "apple",
"image_size": 65536,
"uuid": "2C656702-AA16-3E5F-94D9-D4430DA53398",
"code_file": "/private/var/containers/Bundle/Application/9EB557CD-D653-4F51-BFCE-AECE691D4347/SentryApp.app/iOS-SentryApp",
"debug_id": "97862189-a5be-3af8-bcaa-7066ae872592",
"arch": "arm64",
"image_addr": "0x1025e8000",
"image_size": 170224,
"image_vmaddr": "0x187011000",
"type": "macho",
},
{
"code_file": "/private/var/containers/Bundle/Application/9EB557CD-D653-4F51-BFCE-AECE691D4347/iOS-Swift.app/iOS-Swift",
"debug_id": "97862189-a5be-3af8-bcaa-7066ae872591",
"arch": "arm64",
"image_addr": "0x102b8c000",
"image_size": 180224,
"image_vmaddr": "0x100000000",
"type": "macho",
},
{
"code_file": "/private/var/containers/Bundle/Application/9EB557CD-D653-4F51-BFCE-AECE691D4347/iOS-Swift.app/Frameworks/Sentry.framework/Sentry",
"debug_id": "4726c693-2359-3e9a-bd3a-559760d87486",
"arch": "arm64",
"image_addr": "0x102f68000",
"image_size": 786432,
"type": "macho",
},
{
"code_file": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
"debug_id": "b0858d8e-7220-37bf-873f-ecc2b0a358c3",
"arch": "arm64e",
"image_addr": "0x19c9eb000",
"image_size": 25309184,
"image_vmaddr": "0x18907f000",
"type": "macho",
},
{
"code_file": "/System/Library/Frameworks/CFNetwork.framework/CFNetwork",
"debug_id": "b2273be9-538a-3f56-b9c7-801f39550f58",
"arch": "arm64e",
"image_addr": "0x19b98e000",
"image_size": 3977216,
"image_vmaddr": "0x188022000",
"in_app": False,
},
]
},
Expand Down