-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Sentry SDK Crash Detection POC #49928
Closed
Closed
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
8f39673
test: Fix test discovery by adding missing init.py
philipphofmann 48cd13a
backup
philipphofmann beb3c77
backup
philipphofmann 9cdf838
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann ef31472
Change frame order from newest to oldest
philipphofmann 3b6bf5c
Rename to Cocoa
philipphofmann 9cc03e6
Add events
philipphofmann fe89218
strip frames
philipphofmann db8f089
clarify test method names
philipphofmann 0592d1c
add more fields to event
philipphofmann 8eda480
use mock
philipphofmann 27482bd
Use mocks
philipphofmann 590718f
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann ece3894
givenCrashDetector
philipphofmann 53a4801
rename to event
philipphofmann 7f859e3
Make _is_cocoa_sdk_crash private
philipphofmann 83a578d
add event stripper
philipphofmann fc1d72e
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann be86e37
strip frames before calling report
philipphofmann d842a57
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann 4216b94
add base class
philipphofmann b9e95eb
split up into files
philipphofmann a793793
fix tests
philipphofmann 46dbf5d
move strip frames tests
philipphofmann 0e29e2e
Fix compile error in event manager
philipphofmann 8a36861
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann b0a6ac3
Only keep in stack trace referenced debug images (#46494)
philipphofmann c3ddb38
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann 3b8c023
Avoid infinite processing loop (#46578)
philipphofmann e4d3300
add __init__.py file
philipphofmann eea92f2
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann 30d10c6
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann ec5055f
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann 2958db6
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann 5744b75
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann 087e2c1
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann ed415e4
feat(sdk-crash-detection): Call code in post processing (#49170)
philipphofmann 95d93cc
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann 90b1967
feat(sdk-crash-detection): Add feature flag (#49528)
philipphofmann 082ddda
feat(sdk-crash-detection): Store event to dedicated project (#49593)
philipphofmann cf3d1fc
fix(sdk-crash-detection): Reverse frame order (#49746)
philipphofmann 9870f03
chore(sdk-crash-detection): Add to mypy.ini (#50284)
philipphofmann a2c982d
move fixture to fixtures namespace
philipphofmann af352dd
Remove empty inits
philipphofmann 629e2eb
snake_case not CamelCase
philipphofmann 35e2b0e
make allowed event keys a frozenset
philipphofmann 045a9f7
feat(sdk-crash-detection): Event data allowlist (#50400)
philipphofmann bf72f45
Merge branch 'master' into feat/sdk-crash-monitoring
philipphofmann e1785ff
remove duplicate test fixtures
philipphofmann c710f36
fix post process tests
philipphofmann ea6b6dc
fix type issues
philipphofmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
from typing import Any, Collection, Dict, Mapping, Sequence | ||
|
||
IN_APP_FRAME = { | ||
"function": "LoginViewController.viewDidAppear", | ||
"raw_function": "LoginViewController.viewDidAppear(Bool)", | ||
"symbol": "$s8Sentry9LoginViewControllerC13viewDidAppearyySbF", | ||
"package": "SentryApp", | ||
"filename": "LoginViewController.swift", | ||
"abs_path": "/Users/sentry/git/iOS/Sentry/LoggedOut/LoginViewController.swift", | ||
"lineno": 196, | ||
"in_app": True, | ||
"image_addr": "0x100260000", | ||
"instruction_addr": "0x102b16630", | ||
"symbol_addr": "0x100260000", | ||
} | ||
|
||
|
||
def get_sentry_frame(function: str, in_app: bool = False) -> Mapping[str, Any]: | ||
return { | ||
"function": function, | ||
"package": "Sentry", | ||
"in_app": in_app, | ||
"image_addr": "0x100304000", | ||
} | ||
|
||
|
||
def get_frames(function: str, sentry_frame_in_app: bool = False) -> Sequence[Mapping[str, Any]]: | ||
frames = [ | ||
get_sentry_frame(function, sentry_frame_in_app), | ||
{ | ||
"function": "LoginViewController.viewDidAppear", | ||
"symbol": "$s8Sentry9LoginViewControllerC13viewDidAppearyySbF", | ||
"package": "SentryApp", | ||
"in_app": True, | ||
"filename": "LoginViewController.swift", | ||
"image_addr": "0x100260000", | ||
}, | ||
IN_APP_FRAME, | ||
{ | ||
"function": "-[UIViewController _setViewAppearState:isAnimating:]", | ||
"symbol": "-[UIViewController _setViewAppearState:isAnimating:]", | ||
"package": "UIKitCore", | ||
"in_app": False, | ||
"image_addr": "0x1a4e8f000", | ||
}, | ||
{ | ||
"function": "-[UIViewController __viewDidAppear:]", | ||
"symbol": "-[UIViewController __viewDidAppear:]", | ||
"package": "UIKitCore", | ||
"in_app": False, | ||
"image_addr": "0x1a4e8f000", | ||
}, | ||
{ | ||
"function": "-[UIViewController _endAppearanceTransition:]", | ||
"symbol": "-[UIViewController _endAppearanceTransition:]", | ||
"package": "UIKitCore", | ||
"in_app": False, | ||
"image_addr": "0x1a4e8f000", | ||
}, | ||
{ | ||
"function": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]", | ||
"symbol": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]", | ||
"package": "UIKitCore", | ||
"in_app": False, | ||
"image_addr": "0x1a4e8f000", | ||
}, | ||
{ | ||
"function": "__49-[UINavigationController _startCustomTransition:]_block_invoke", | ||
"symbol": "__49-[UINavigationController _startCustomTransition:]_block_invoke", | ||
"package": "UIKitCore", | ||
"in_app": False, | ||
"image_addr": "0x1a4e8f000", | ||
}, | ||
] | ||
|
||
# The frames have to be ordered from caller to callee, or oldest to youngest. | ||
# The last frame is the one creating the exception. | ||
# As we usually look at stacktraces from youngest to oldest, we reverse the order. | ||
return frames[::-1] | ||
|
||
|
||
def get_crash_event(handled=False, function="-[Sentry]", **kwargs) -> Dict[str, Collection[str]]: | ||
return get_crash_event_with_frames(get_frames(function), handled=handled, **kwargs) | ||
|
||
|
||
def get_crash_event_with_frames( | ||
frames: Sequence[Mapping[str, Any]], handled=False, **kwargs | ||
) -> Dict[str, Collection[str]]: | ||
result = { | ||
"event_id": "80e3496eff734ab0ac993167aaa0d1cd", | ||
"release": "5.222.5", | ||
"type": "error", | ||
"level": "fatal", | ||
"platform": "cocoa", | ||
"tags": {"level": "fatal"}, | ||
"exception": { | ||
"values": [ | ||
{ | ||
"stacktrace": { | ||
"frames": frames, | ||
}, | ||
"type": "SIGABRT", | ||
"mechanism": {"handled": handled}, | ||
} | ||
] | ||
}, | ||
"breadcrumbs": { | ||
"values": [ | ||
{ | ||
"timestamp": 1675900265.0, | ||
"type": "debug", | ||
"category": "started", | ||
"level": "info", | ||
"message": "Breadcrumb Tracking", | ||
}, | ||
] | ||
}, | ||
"contexts": { | ||
"app": { | ||
"app_start_time": "2023-02-08T23:51:05Z", | ||
"device_app_hash": "8854fe9e3d4e4a66493baee798bfae0228efabf1", | ||
"build_type": "app store", | ||
"app_identifier": "com.some.company.io", | ||
"app_name": "SomeCompany", | ||
"app_version": "5.222.5", | ||
"app_build": "21036", | ||
"app_id": "397D4F75-6C01-32D1-BF46-62098979E470", | ||
"type": "app", | ||
}, | ||
"device": { | ||
"family": "iOS", | ||
"model": "iPhone14,8", | ||
"model_id": "D28AP", | ||
"arch": "arm64e", | ||
"memory_size": 5944508416, | ||
"free_memory": 102154240, | ||
"usable_memory": 4125687808, | ||
"storage_size": 127854202880, | ||
"boot_time": "2023-02-01T05:21:23Z", | ||
"timezone": "PST", | ||
"type": "device", | ||
}, | ||
"os": { | ||
"name": "iOS", | ||
"version": "16.3", | ||
"build": "20D47", | ||
"kernel_version": "Darwin Kernel Version 22.3.0: Wed Jan 4 21:25:19 PST 2023; root:xnu-8792.82.2~1/RELEASE_ARM64_T8110", | ||
"rooted": False, | ||
"type": "os", | ||
}, | ||
}, | ||
"debug_meta": { | ||
"images": [ | ||
{ | ||
"code_file": "/private/var/containers/Bundle/Application/895DA2DE-5FE3-44A0-8C0F-900519EA5516/iOS-Swift.app/iOS-Swift", | ||
"debug_id": "aa8a3697-c88a-36f9-a687-3d3596568c8d", | ||
"arch": "arm64", | ||
"image_addr": "0x100260000", | ||
"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": "e2623c4d-79c5-3cdf-90ab-2cf44e026bdd", | ||
"arch": "arm64", | ||
"image_addr": "0x100304000", | ||
"image_size": 802816, | ||
"type": "macho", | ||
}, | ||
{ | ||
"code_file": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore", | ||
"debug_id": "b0858d8e-7220-37bf-873f-ecc2b0a358c3", | ||
"arch": "arm64e", | ||
"image_addr": "0x1a4e8f000", | ||
"image_size": 25309184, | ||
"image_vmaddr": "0x188ff7000", | ||
"type": "macho", | ||
}, | ||
{ | ||
"code_file": "/System/Library/Frameworks/CFNetwork.framework/CFNetwork", | ||
"debug_id": "b2273be9-538a-3f56-b9c7-801f39550f58", | ||
"arch": "arm64e", | ||
"image_addr": "0x1a3e32000", | ||
"image_size": 3977216, | ||
"image_vmaddr": "0x187f9a000", | ||
"in_app": False, | ||
"type": "macho", | ||
}, | ||
] | ||
}, | ||
"environment": "test-app", | ||
"sdk": { | ||
"name": "sentry.cocoa", | ||
"version": "8.1.0", | ||
"integrations": [ | ||
"Crash", | ||
"PerformanceTracking", | ||
"MetricKit", | ||
"WatchdogTerminationTracking", | ||
"ViewHierarchy", | ||
"NetworkTracking", | ||
"ANRTracking", | ||
"AutoBreadcrumbTracking", | ||
"FramesTracking", | ||
"AppStartTracking", | ||
"Screenshot", | ||
"FileIOTracking", | ||
"UIEventTracking", | ||
"AutoSessionTracking", | ||
"CoreDataTracking", | ||
"PreWarmedAppStartTracing", | ||
], | ||
}, | ||
"threads": { | ||
"values": [ | ||
{ | ||
"id": 0, | ||
"stacktrace": { | ||
"frames": [ | ||
{ | ||
"function": "<redacted>", | ||
"in_app": False, | ||
"data": {"symbolicator_status": "unknown_image"}, | ||
"image_addr": "0x0", | ||
"instruction_addr": "0x1129be52e", | ||
"symbol_addr": "0x0", | ||
}, | ||
{ | ||
"function": "<redacted>", | ||
"in_app": False, | ||
"data": {"symbolicator_status": "unknown_image"}, | ||
"image_addr": "0x0", | ||
"instruction_addr": "0x104405f21", | ||
"symbol_addr": "0x0", | ||
}, | ||
], | ||
}, | ||
"raw_stacktrace": { | ||
"frames": [ | ||
{ | ||
"function": "<redacted>", | ||
"in_app": False, | ||
"image_addr": "0x0", | ||
"instruction_addr": "0x1129be52e", | ||
"symbol_addr": "0x0", | ||
}, | ||
{ | ||
"function": "<redacted>", | ||
"in_app": False, | ||
"image_addr": "0x0", | ||
"instruction_addr": "0x104405f21", | ||
"symbol_addr": "0x0", | ||
}, | ||
], | ||
}, | ||
"crashed": True, | ||
} | ||
] | ||
}, | ||
"user": { | ||
"id": "803F5C87-0F8B-41C7-8499-27BD71A92738", | ||
"ip_address": "192.168.0.1", | ||
"geo": {"country_code": "US", "region": "United States"}, | ||
}, | ||
"logger": "my.logger.name", | ||
} | ||
result.update(kwargs) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,7 @@ | |
default_manager.add("organizations:set-grouping-config", OrganizationFeature, FeatureHandlerStrategy.INTERNAL) | ||
default_manager.add("organizations:slack-escape-messages", OrganizationFeature, FeatureHandlerStrategy.INTERNAL) | ||
default_manager.add("organizations:slack-overage-notifications", OrganizationFeature, FeatureHandlerStrategy.REMOTE) | ||
default_manager.add("organizations:sdk-crash-detection", OrganizationFeature, FeatureHandlerStrategy.INTERNAL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code was reviewed in #49528 |
||
default_manager.add("organizations:starfish-view", OrganizationFeature, FeatureHandlerStrategy.REMOTE) | ||
default_manager.add("organizations:starfish-test-endpoint", OrganizationFeature, FeatureHandlerStrategy.REMOTE) | ||
default_manager.add("organizations:streamline-targeting-context", OrganizationFeature, FeatureHandlerStrategy.REMOTE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1056,6 +1056,30 @@ def fire_error_processed(job: PostProcessJob): | |
) | ||
|
||
|
||
def sdk_crash_monitoring(job: PostProcessJob): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code was reviewed in #49170 |
||
from sentry.utils.sdk_crashes.sdk_crash_detection import sdk_crash_detection | ||
|
||
if job["is_reprocessed"]: | ||
return | ||
|
||
event = job["event"] | ||
|
||
if not features.has("organizations:sdk-crash-detection", event.project.organization): | ||
return | ||
|
||
if settings.SDK_CRASH_DETECTION_PROJECT_ID is None: | ||
logger.warning( | ||
"SDK crash detection is enabled but SDK_CRASH_DETECTION_PROJECT_ID is not set." | ||
) | ||
return None | ||
|
||
with metrics.timer("post_process.sdk_crash_monitoring.duration"): | ||
with sentry_sdk.start_span(op="tasks.post_process_group.sdk_crash_monitoring"): | ||
sdk_crash_detection.detect_sdk_crash( | ||
event=event, event_project_id=settings.SDK_CRASH_DETECTION_PROJECT_ID | ||
) | ||
|
||
|
||
def plugin_post_process_group(plugin_slug, event, **kwargs): | ||
""" | ||
Fires post processing hooks for a group. | ||
|
@@ -1091,6 +1115,7 @@ def plugin_post_process_group(plugin_slug, event, **kwargs): | |
process_similarity, | ||
update_existing_attachments, | ||
fire_error_processed, | ||
sdk_crash_monitoring, | ||
], | ||
GroupCategory.PERFORMANCE: [ | ||
process_snoozes, | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Any, Mapping, Sequence | ||
|
||
from sentry.utils.glob import glob_match | ||
from sentry.utils.sdk_crashes.sdk_crash_detector import SDKCrashDetector | ||
|
||
|
||
class CocoaSDKCrashDetector(SDKCrashDetector): | ||
def is_sdk_crash(self, frames: Sequence[Mapping[str, Any]]) -> bool: | ||
if not frames: | ||
return False | ||
|
||
# The frames are ordered from caller to callee, or oldest to youngest. | ||
# The last frame is the one creating the exception. | ||
# Therefore, we must iterate in reverse order. | ||
for frame in reversed(frames): | ||
if self.is_sdk_frame(frame): | ||
return True | ||
|
||
if frame.get("in_app") is True: | ||
return False | ||
|
||
return False | ||
|
||
def is_sdk_frame(self, frame: Mapping[str, Any]) -> bool: | ||
function = frame.get("function") | ||
|
||
if function is not None: | ||
# [SentrySDK crash] is a testing function causing a crash. | ||
# Therefore, we don't want to mark it a as a SDK crash. | ||
if "SentrySDK crash" in function: | ||
return False | ||
|
||
function_matchers = ["*sentrycrash*", "**[[]Sentry*"] | ||
for matcher in function_matchers: | ||
if glob_match(frame.get("function"), matcher, ignorecase=True): | ||
return True | ||
|
||
filename = frame.get("filename") | ||
if filename is not None: | ||
filenameMatchers = ["Sentry**"] | ||
for matcher in filenameMatchers: | ||
if glob_match(filename, matcher, ignorecase=True): | ||
return True | ||
|
||
return False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code was already reviewed in #49528