Skip to content

Commit

Permalink
feat(sdk-crash-detection): Add feature flag (#49528)
Browse files Browse the repository at this point in the history
Add a feature flag for SDK Crash Detection #44342.

Co-authored-by: Joris Bayer <joris.bayer@sentry.io>
  • Loading branch information
philipphofmann and jjbayer authored Jun 5, 2023
1 parent 95d93cc commit 90b1967
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,8 @@ def SOCIAL_AUTH_DEFAULT_USERNAME():
"organizations:slack-escape-messages": False,
# If true, allow to create/use org auth tokens
"organizations:org-auth-tokens": False,
# Enable detecting SDK crashes during event processing
"organizations:sdk-crash-detection": False,
# Adds additional filters and a new section to issue alert rules.
"projects:alert-filters": True,
# Enable functionality to specify custom inbound filters on events.
Expand Down
1 change: 1 addition & 0 deletions src/sentry/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,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)
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)
Expand Down
3 changes: 3 additions & 0 deletions src/sentry/tasks/post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,9 @@ def sdk_crash_monitoring(job: PostProcessJob):

event = job["event"]

if not features.has("organizations:sdk-crash-detection", event.project.organization):
return

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)
Expand Down
10 changes: 1 addition & 9 deletions src/sentry/utils/sdk_crashes/event_stripper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def strip_event_data(event: Event, sdk_crash_detector: SDKCrashDetector) -> Event:
new_event_data = dict(filter(_filter_event, event.data.items()))
new_event_data = {key: value for key, value in event.data.items() if key in ALLOWED_EVENT_KEYS}
new_event_data["contexts"] = dict(filter(_filter_contexts, new_event_data["contexts"].items()))

stripped_frames = []
Expand All @@ -38,14 +38,6 @@ def strip_event_data(event: Event, sdk_crash_detector: SDKCrashDetector) -> Even
return event


def _filter_event(pair):
key, _ = pair
if key in ALLOWED_EVENT_KEYS:
return True

return False


def _filter_contexts(pair):
key, _ = pair
if key in {"os", "device"}:
Expand Down
21 changes: 20 additions & 1 deletion tests/sentry/tasks/test_post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,8 +1483,9 @@ def test_forecast_in_activity(self, mock_is_escalating):
).exists()


@patch("sentry.utils.sdk_crashes.sdk_crash_detection.sdk_crash_detection.sdk_crash_reporter")
class SDKCrashMonitoringTestMixin(BasePostProgressGroupMixin):
@with_feature("organizations:sdk-crash-detection")
@patch("sentry.utils.sdk_crashes.sdk_crash_detection.sdk_crash_detection.sdk_crash_reporter")
def test_sdk_crash_monitoring_is_called_with_event(self, mock_sdk_crash_reporter):
event = self.create_event(
data=get_crash_event(),
Expand All @@ -1500,6 +1501,24 @@ def test_sdk_crash_monitoring_is_called_with_event(self, mock_sdk_crash_reporter

mock_sdk_crash_reporter.report.assert_called_once()

@patch("sentry.utils.sdk_crashes.sdk_crash_detection.sdk_crash_detection")
def test_sdk_crash_monitoring_is_not_called_with_disabled_feature(
self, mock_sdk_crash_detection
):
event = self.create_event(
data=get_crash_event(),
project_id=self.project.id,
)

self.call_post_process_group(
is_new=True,
is_regression=False,
is_new_group_environment=True,
event=event,
)

mock_sdk_crash_detection.detect_sdk_crash.assert_not_called()


@region_silo_test
class PostProcessGroupErrorTest(
Expand Down
4 changes: 2 additions & 2 deletions tests/sentry/utils/sdk_crashes/test_sdk_crash_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def create_event(self, data, project_id, assert_no_errors=True):
pass

def execute_test(self, event_data, should_be_reported, mock_sdk_crash_reporter):

event = self.create_event(
data=event_data,
project_id=self.project.id,
Expand All @@ -38,10 +39,9 @@ def execute_test(self, event_data, should_be_reported, mock_sdk_crash_reporter):
mock_sdk_crash_reporter.report.assert_not_called()


@patch("sentry.utils.sdk_crashes.sdk_crash_detection.sdk_crash_detection.sdk_crash_reporter")
class PerformanceEventTestMixin(BaseSDKCrashDetectionMixin, PerfIssueTransactionTestMixin):
@patch("sentry.utils.sdk_crashes.sdk_crash_detection.sdk_crash_detection.sdk_crash_reporter")
def test_performance_event_not_detected(self, mock_sdk_crash_reporter):

fingerprint = "some_group"
fingerprint = f"{PerformanceNPlusOneGroupType.type_id}-{fingerprint}"
event = self.store_transaction(
Expand Down

0 comments on commit 90b1967

Please sign in to comment.