@@ -119,7 +119,7 @@ def _webhook_event_data(
119
119
@instrumented_task (name = "sentry.sentry_apps.tasks.sentry_apps.send_alert_webhook" , ** TASK_OPTIONS )
120
120
@retry_decorator
121
121
def send_alert_webhook (
122
- rule_label : str ,
122
+ rule : str ,
123
123
sentry_app_id : int ,
124
124
instance_id : str ,
125
125
group_id : int ,
@@ -128,72 +128,79 @@ def send_alert_webhook(
128
128
additional_payload : Mapping [str , Any ] | None = None ,
129
129
** kwargs : Any ,
130
130
):
131
- with SentryAppInteractionEvent (
132
- operation_type = SentryAppInteractionType .PREPARE_WEBHOOK ,
133
- event_type = SentryAppEventType .EVENT_ALERT_TRIGGERED ,
134
- ).capture () as lifecycle :
135
- group = Group .objects .get_from_cache (id = group_id )
136
- assert group , "Group must exist to get related attributes"
137
- project = Project .objects .get_from_cache (id = group .project_id )
138
- organization = Organization .objects .get_from_cache (id = project .organization_id )
139
- extra : dict [str , int | str ] = {
140
- "sentry_app_id" : sentry_app_id ,
141
- "project_id" : project .id ,
142
- "organization_slug" : organization .slug ,
143
- "rule" : rule_label ,
144
- }
145
- lifecycle .add_extras (extra )
146
-
147
- sentry_app = app_service .get_sentry_app_by_id (id = sentry_app_id )
148
- if sentry_app is None :
149
- raise SentryAppSentryError (message = SentryAppWebhookFailureReason .MISSING_SENTRY_APP )
150
-
151
- installations = app_service .get_many (
152
- filter = dict (
153
- organization_id = organization .id ,
154
- app_ids = [sentry_app .id ],
155
- status = SentryAppInstallationStatus .INSTALLED ,
156
- )
157
- )
158
- if not installations :
159
- raise SentryAppSentryError (message = SentryAppWebhookFailureReason .MISSING_INSTALLATION )
160
- (install ,) = installations
131
+ group = Group .objects .get_from_cache (id = group_id )
132
+ assert group , "Group must exist to get related attributes"
133
+ project = Project .objects .get_from_cache (id = group .project_id )
134
+ organization = Organization .objects .get_from_cache (id = project .organization_id )
135
+ extra = {
136
+ "sentry_app_id" : sentry_app_id ,
137
+ "project_slug" : project .slug ,
138
+ "organization_slug" : organization .slug ,
139
+ "rule" : rule ,
140
+ }
141
+
142
+ sentry_app = app_service .get_sentry_app_by_id (id = sentry_app_id )
143
+ if sentry_app is None :
144
+ logger .info ("event_alert_webhook.missing_sentry_app" , extra = extra )
145
+ return
161
146
162
- nodedata = nodestore .backend .get (
163
- BaseEvent .generate_node_id (project_id = project .id , event_id = instance_id )
147
+ installations = app_service .get_many (
148
+ filter = dict (
149
+ organization_id = organization .id ,
150
+ app_ids = [sentry_app .id ],
151
+ status = SentryAppInstallationStatus .INSTALLED ,
164
152
)
153
+ )
154
+ if not installations :
155
+ logger .info ("event_alert_webhook.missing_installation" , extra = extra )
156
+ return
157
+ (install ,) = installations
165
158
166
- if not nodedata :
167
- raise SentryAppSentryError (message = SentryAppWebhookFailureReason .MISSING_EVENT )
159
+ nodedata = nodestore .backend .get (
160
+ BaseEvent .generate_node_id (project_id = project .id , event_id = instance_id )
161
+ )
168
162
169
- occurrence = None
170
- if occurrence_id :
171
- occurrence = IssueOccurrence .fetch (occurrence_id , project_id = project .id )
163
+ if not nodedata :
164
+ extra = {
165
+ "event_id" : instance_id ,
166
+ "occurrence_id" : occurrence_id ,
167
+ "rule" : rule ,
168
+ "sentry_app" : sentry_app .slug ,
169
+ "group_id" : group_id ,
170
+ }
171
+ logger .info ("send_alert_event.missing_event" , extra = extra )
172
+ return
172
173
173
- if not occurrence :
174
- raise SentryAppSentryError (
175
- message = SentryAppWebhookFailureReason .MISSING_ISSUE_OCCURRENCE
176
- )
174
+ occurrence = None
175
+ if occurrence_id :
176
+ occurrence = IssueOccurrence .fetch (occurrence_id , project_id = project .id )
177
177
178
- group_event = GroupEvent (
179
- project_id = project .id ,
180
- event_id = instance_id ,
181
- group = group ,
182
- data = nodedata ,
183
- occurrence = occurrence ,
184
- )
178
+ if not occurrence :
179
+ logger .info (
180
+ "send_alert_event.missing_occurrence" ,
181
+ extra = {"occurrence_id" : occurrence_id , "project_id" : project .id },
182
+ )
183
+ return
184
+
185
+ group_event = GroupEvent (
186
+ project_id = project .id ,
187
+ event_id = instance_id ,
188
+ group = group ,
189
+ data = nodedata ,
190
+ occurrence = occurrence ,
191
+ )
185
192
186
- event_context = _webhook_event_data (group_event , group .id , project .id )
193
+ event_context = _webhook_event_data (group_event , group .id , project .id )
187
194
188
- data = {"event" : event_context , "triggered_rule" : rule_label }
195
+ data = {"event" : event_context , "triggered_rule" : rule }
189
196
190
- # Attach extra payload to the webhook
191
- if additional_payload_key and additional_payload :
192
- data [additional_payload_key ] = additional_payload
197
+ # Attach extra payload to the webhook
198
+ if additional_payload_key and additional_payload :
199
+ data [additional_payload_key ] = additional_payload
193
200
194
- request_data = AppPlatformEvent (
195
- resource = "event_alert" , action = "triggered" , install = install , data = data
196
- )
201
+ request_data = AppPlatformEvent (
202
+ resource = "event_alert" , action = "triggered" , install = install , data = data
203
+ )
197
204
198
205
send_and_save_webhook_request (sentry_app , request_data )
199
206
@@ -203,7 +210,7 @@ def send_alert_webhook(
203
210
"alert_rule_ui_component_webhook.sent" ,
204
211
organization_id = organization .id ,
205
212
sentry_app_id = sentry_app_id ,
206
- event = SentryAppEventType . EVENT_ALERT_TRIGGERED ,
213
+ event = f" { request_data . resource } . { request_data . action } " ,
207
214
)
208
215
209
216
@@ -491,10 +498,6 @@ def send_resource_change_webhook(
491
498
def notify_sentry_app (event : GroupEvent , futures : Sequence [RuleFuture ]):
492
499
for f in futures :
493
500
if not f .kwargs .get ("sentry_app" ):
494
- logger .error (
495
- "notify_sentry_app.future_missing_sentry_app" ,
496
- extra = {"event" : event .as_dict (), "future" : f , "event_id" : event .event_id },
497
- )
498
501
continue
499
502
500
503
extra_kwargs : dict [str , Any ] = {
@@ -516,7 +519,7 @@ def notify_sentry_app(event: GroupEvent, futures: Sequence[RuleFuture]):
516
519
instance_id = event .event_id ,
517
520
group_id = event .group_id ,
518
521
occurrence_id = event .occurrence_id if hasattr (event , "occurrence_id" ) else None ,
519
- rule_label = f .rule .label ,
522
+ rule = f .rule .label ,
520
523
sentry_app_id = f .kwargs ["sentry_app" ].id ,
521
524
** extra_kwargs ,
522
525
)
0 commit comments