-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(webhooks): Route sentry app actions through send_alert_webhook_v2 in new path #115975
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| from sentry.eventstore.models import GroupEvent | ||
| from sentry.models.options.project_option import ProjectOption | ||
| from sentry.models.rule import Rule | ||
| from sentry.sentry_apps.services.app import app_service | ||
| from sentry.sentry_apps.tasks.sentry_apps import send_alert_webhook_v2 | ||
| from sentry.workflow_engine.models import AlertRuleWorkflow, Workflow | ||
| from sentry.workflow_engine.types import ActionInvocation | ||
|
|
||
|
|
@@ -83,6 +85,33 @@ def build_legacy_webhook_payload(invocation: ActionInvocation) -> LegacyWebhookP | |
| return data | ||
|
|
||
|
|
||
| def send_sentry_app_webhook_for_invocation(invocation: ActionInvocation) -> None: | ||
| event = invocation.event_data.event | ||
| assert isinstance(event, GroupEvent) | ||
|
Member
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. Does this assertion exist in the old code? If not, do we have a strong guarantee that this will always be true? Also would help to add a message in the assertion of why we expect this to be the case.
Contributor
Author
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. yes this would be guarded in the old code by the same NOA utils. We also have the guard in the action code but for typing (since we're giving ActionInvocation) we need to add the check
Member
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. Got it. You may want to consider having the webhook handler |
||
| sentry_app_slug = invocation.action.config.get("target_identifier") | ||
| if not sentry_app_slug: | ||
| logger.warning("webhook_action_handler.missing_target_identifier") | ||
| return | ||
|
|
||
| sentry_app = app_service.get_sentry_app_by_slug(slug=sentry_app_slug) | ||
| if sentry_app is None: | ||
| logger.warning( | ||
| "webhook_action_handler.sentry_app_not_found", | ||
| extra={"sentry_app_slug": sentry_app_slug}, | ||
| ) | ||
| return | ||
|
|
||
| rule_label = _get_triggering_rule_name(invocation) | ||
|
|
||
| send_alert_webhook_v2.delay( | ||
| rule_label=rule_label, | ||
| sentry_app_id=sentry_app.id, | ||
| instance_id=event.event_id, | ||
| group_id=event.group_id, | ||
| occurrence_id=getattr(event, "occurrence_id", None), | ||
| ) | ||
|
|
||
|
|
||
| def send_legacy_webhooks_for_invocation(invocation: ActionInvocation) -> None: | ||
| # Delayed import to avoid circular dependency (tasks imports LegacyWebhookPayload from here) | ||
| from sentry.sentry_apps.services.legacy_webhook.tasks import send_legacy_webhook_task | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.