Skip to content

chore(sentry apps): add SLO context manager for send alert event (issue alerts) #86356

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

Merged
merged 40 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8299673
inital commit
Christinarlong Feb 28, 2025
b5e833b
add context manager for event webhooks
Christinarlong Feb 28, 2025
f3dde2d
add context manager for event webhooks
Christinarlong Feb 28, 2025
757890f
typing
Christinarlong Feb 28, 2025
e9dacdf
record halts in sending webhook
Christinarlong Feb 28, 2025
a26919d
update tests
Christinarlong Feb 28, 2025
fe4de7f
update tests
Christinarlong Mar 3, 2025
3804a47
create helper for asserting count
Christinarlong Mar 3, 2025
48a67f5
add testing for send webhook
Christinarlong Mar 4, 2025
56d5e90
fix and add tests for event webhook SLOs
Christinarlong Mar 4, 2025
2614eb5
add test for lifecycle halt for published apps
Christinarlong Mar 4, 2025
5188300
Merge branch 'master' into crl/sa-slos-context-manager
Christinarlong Mar 4, 2025
c518499
add context manager to alert prep task
Christinarlong Mar 4, 2025
b68ade6
add context manager send alert webhook
Christinarlong Mar 4, 2025
72419db
fix typing
Christinarlong Mar 5, 2025
c261e25
pr fixes for tasks
Christinarlong Mar 5, 2025
ce6b02f
fix tests via pr comments
Christinarlong Mar 5, 2025
887b1a3
add assertionerror
Christinarlong Mar 5, 2025
91693e7
typing
Christinarlong Mar 5, 2025
0e2c40a
Merge branch 'crl/sa-slos-context-manager' into crl/slo-send-alert-we…
Christinarlong Mar 5, 2025
46f0cee
pr schtuff
Christinarlong Mar 5, 2025
997e954
pr schtuff
Christinarlong Mar 5, 2025
85f7132
shift up event naming to before lifecycle
Christinarlong Mar 6, 2025
1ea4fab
Update src/sentry/sentry_apps/metrics.py
Christinarlong Mar 6, 2025
1d0988a
Merge branch 'crl/sa-slos-context-manager' into crl/slo-send-alert-we…
Christinarlong Mar 6, 2025
cafe800
update tests and remove extra params
Christinarlong Mar 6, 2025
0a6c67b
remove extra context since sentry error will automagically catch
Christinarlong Mar 6, 2025
d6dbd01
add ignore and capture
Christinarlong Mar 6, 2025
33d5da0
add tests for retry decorator
Christinarlong Mar 6, 2025
eb8ced0
add testing that we call retry
Christinarlong Mar 6, 2025
f1ebf57
Merge branch 'crl/add-ignore-and-retry' into crl/sa-slos-context-manager
Christinarlong Mar 7, 2025
c23e962
remove try catches since the retry decorator willl handle for us, als…
Christinarlong Mar 7, 2025
b68a033
Merge branch 'master' into crl/sa-slos-context-manager
Christinarlong Mar 7, 2025
83e94bd
do event checking with cast
Christinarlong Mar 7, 2025
3229f2a
Merge branch 'crl/sa-slos-context-manager' into crl/slo-send-alert-we…
Christinarlong Mar 7, 2025
9dca10e
cast the event alert trifggerdd
Christinarlong Mar 7, 2025
3c16f86
Merge branch 'master' into crl/installation-webhook-slo
Christinarlong Mar 10, 2025
ad51113
Merge branch 'master' into crl/slo-send-alert-webhook
Christinarlong Mar 10, 2025
416e7ca
pr fixes
Christinarlong Mar 11, 2025
f439a44
fix tests
Christinarlong Mar 14, 2025
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
Prev Previous commit
Next Next commit
do event checking with cast
  • Loading branch information
Christinarlong committed Mar 7, 2025
commit 83e94bd7d7ceba1f11bf6fa013036f529b1f9a43
22 changes: 12 additions & 10 deletions src/sentry/sentry_apps/tasks/sentry_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
SentryAppInteractionType,
SentryAppWebhookFailureReason,
)
from sentry.sentry_apps.models.sentry_app import VALID_EVENTS, SentryApp
from sentry.sentry_apps.models.sentry_app import SentryApp
from sentry.sentry_apps.models.sentry_app_installation import SentryAppInstallation
from sentry.sentry_apps.models.servicehook import ServiceHook, ServiceHookProject
from sentry.sentry_apps.services.app.model import RpcSentryAppInstallation
Expand Down Expand Up @@ -234,15 +234,15 @@ def _process_resource_change(
# Looks up the human name for the model. Defaults to the model name.
name = RESOURCE_RENAMES.get(model.__name__, model.__name__.lower())

event = f"{name}.{action}"
if event not in VALID_EVENTS:
try:
event = SentryAppEventType(f"{name}.{action}")
except ValueError as e:
raise SentryAppSentryError(
message=f"{SentryAppWebhookFailureReason.INVALID_EVENT}",
)
) from e

with SentryAppInteractionEvent(
operation_type=SentryAppInteractionType.PREPARE_WEBHOOK,
event_type=SentryAppEventType(event),
operation_type=SentryAppInteractionType.PREPARE_WEBHOOK, event_type=event
).capture():
project_id: int | None = kwargs.get("project_id", None)
group_id: int | None = kwargs.get("group_id", None)
Expand Down Expand Up @@ -300,7 +300,7 @@ def _process_resource_change(

# Trigger a new task for each webhook
send_resource_change_webhook.delay(
installation_id=installation.id, event=event, data=data
installation_id=installation.id, event=str(event), data=data
)


Expand Down Expand Up @@ -514,13 +514,15 @@ def notify_sentry_app(event: GroupEvent, futures: Sequence[RuleFuture]):


def send_webhooks(installation: RpcSentryAppInstallation, event: str, **kwargs: Any) -> None:
if event not in VALID_EVENTS:
try:
event = SentryAppEventType(event)
except ValueError as e:
raise SentryAppSentryError(
message=f"{SentryAppWebhookFailureReason.INVALID_EVENT}",
)
) from e

with SentryAppInteractionEvent(
operation_type=SentryAppInteractionType.SEND_WEBHOOK, event_type=SentryAppEventType(event)
operation_type=SentryAppInteractionType.SEND_WEBHOOK, event_type=event
).capture():
servicehook: ServiceHook
try:
Expand Down
17 changes: 14 additions & 3 deletions src/sentry/utils/sentry_apps/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
from sentry.integrations.notify_disable import notify_disable
from sentry.integrations.request_buffer import IntegrationRequestBuffer
from sentry.models.organization import Organization
from sentry.sentry_apps.metrics import SentryAppEventType, SentryAppWebhookHaltReason
from sentry.sentry_apps.metrics import (
SentryAppEventType,
SentryAppWebhookFailureReason,
SentryAppWebhookHaltReason,
)
from sentry.sentry_apps.models.sentry_app import SentryApp, track_response_code
from sentry.sentry_apps.utils.errors import SentryAppSentryError
from sentry.shared_integrations.exceptions import ApiHostError, ApiTimeoutError, ClientError
from sentry.utils.audit import create_system_audit_entry
from sentry.utils.sentry_apps import SentryAppWebhookRequestsBuffer
Expand Down Expand Up @@ -129,9 +134,15 @@ def send_and_save_webhook_request(
"""
from sentry.sentry_apps.metrics import SentryAppInteractionEvent, SentryAppInteractionType

event = f"{app_platform_event.resource}.{app_platform_event.action}"
try:
event = SentryAppEventType(f"{app_platform_event.resource}.{app_platform_event.action}")
except ValueError as e:
raise SentryAppSentryError(
message=f"{SentryAppWebhookFailureReason.INVALID_EVENT}",
) from e

with SentryAppInteractionEvent(
operation_type=SentryAppInteractionType.SEND_WEBHOOK, event_type=SentryAppEventType(event)
operation_type=SentryAppInteractionType.SEND_WEBHOOK, event_type=event
).capture() as lifecycle:
buffer = SentryAppWebhookRequestsBuffer(sentry_app)

Expand Down
Loading