Skip to content

Commit 1e8d9e7

Browse files
chore(sentry apps): Add SLO for updating servicehooks (#94489)
1 parent db804f3 commit 1e8d9e7

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/sentry/sentry_apps/tasks/sentry_apps.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,16 @@ def send_webhooks(installation: RpcSentryAppInstallation, event: str, **kwargs:
789789
def create_or_update_service_hooks_for_sentry_app(
790790
sentry_app_id: int, webhook_url: str, events: list[str], **kwargs: dict
791791
) -> None:
792-
installations = SentryAppInstallation.objects.filter(sentry_app_id=sentry_app_id)
793-
for installation in installations:
794-
create_or_update_service_hooks_for_installation(
795-
installation=installation,
796-
events=events,
797-
webhook_url=webhook_url,
798-
)
792+
with SentryAppInteractionEvent(
793+
operation_type=SentryAppInteractionType.MANAGEMENT,
794+
event_type=SentryAppEventType.WEBHOOK_UPDATE,
795+
).capture() as lifecycle:
796+
lifecycle.add_extras({"sentry_app_id": sentry_app_id, "events": events})
797+
installations = SentryAppInstallation.objects.filter(sentry_app_id=sentry_app_id)
798+
799+
for installation in installations:
800+
create_or_update_service_hooks_for_installation(
801+
installation=installation,
802+
events=events,
803+
webhook_url=webhook_url,
804+
)

tests/sentry/sentry_apps/test_sentry_app_updater.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def test_doesnt_update_status_if_not_superuser(self):
213213
self.updater.run(self.user)
214214
assert self.sentry_app.status == SentryAppStatus.UNPUBLISHED
215215

216-
def test_create_service_hook_on_update(self):
216+
@patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
217+
def test_create_service_hook_on_update(self, mock_record):
217218
self.create_project(organization=self.org)
218219
internal_app = self.create_internal_integration(
219220
name="Internal", organization=self.org, webhook_url=None, scopes=("event:read",)
@@ -229,6 +230,17 @@ def test_create_service_hook_on_update(self):
229230
assert service_hook.url == "https://sentry.io/hook"
230231
assert service_hook.events == expand_events(["issue"])
231232

233+
# SLO assertions
234+
assert_success_metric(mock_record=mock_record)
235+
236+
# APP_CREATE (success) -> WEBHOOK_UPDATE (success)
237+
assert_count_of_metric(
238+
mock_record=mock_record, outcome=EventLifecycleOutcome.STARTED, outcome_count=2
239+
)
240+
assert_count_of_metric(
241+
mock_record=mock_record, outcome=EventLifecycleOutcome.SUCCESS, outcome_count=2
242+
)
243+
232244
def test_delete_service_hook_on_update(self):
233245
self.create_project(organization=self.org)
234246
internal_app = self.create_internal_integration(

0 commit comments

Comments
 (0)