Skip to content

Commit c0e47b1

Browse files
authored
chore(issues): Add logging to rule processing (#54109)
Reverting the revert of #53912 Add logging to the rule processor to investigate why the regression alerts may not be triggering (#52849).
1 parent 3b4fb38 commit c0e47b1

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

src/sentry/rules/processor.py

+55-2
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,55 @@ def apply_rule(self, rule: Rule, status: GroupRuleStatus) -> None:
169169
filter_match = rule.data.get("filter_match") or Rule.DEFAULT_FILTER_MATCH
170170
rule_condition_list = rule.data.get("conditions", ())
171171
frequency = rule.data.get("frequency") or Rule.DEFAULT_FREQUENCY
172-
172+
logging_details = {
173+
"rule_id": rule.id,
174+
"group_id": self.group.id,
175+
"event_id": self.event.event_id,
176+
"is_new": self.is_new,
177+
"is_regression": self.is_regression,
178+
"has_reappeared": self.has_reappeared,
179+
"new_group_environment": self.is_new_group_environment,
180+
}
181+
182+
self.logger.info(
183+
"apply_rule",
184+
extra={**logging_details},
185+
)
173186
try:
174187
environment = self.event.get_environment()
188+
self.logger.info(
189+
"apply_rule got environment",
190+
extra={**logging_details},
191+
)
175192
except Environment.DoesNotExist:
193+
self.logger.info(
194+
"apply_rule environment does not exist",
195+
extra={**logging_details},
196+
)
176197
return
177198

178199
if rule.environment_id is not None and environment.id != rule.environment_id:
200+
self.logger.info(
201+
"apply_rule environment does not match",
202+
extra={
203+
**logging_details,
204+
"rule_environment_id": rule.environment_id,
205+
"event_environment_id": environment.id,
206+
},
207+
)
179208
return
180209

181210
now = timezone.now()
182211
freq_offset = now - timedelta(minutes=frequency)
183212
if status.last_active and status.last_active > freq_offset:
213+
self.logger.info(
214+
"apply_rule skipping rule because of last_active",
215+
extra={
216+
**logging_details,
217+
"last_active": status.last_active,
218+
"freq_offset": freq_offset,
219+
},
220+
)
184221
return
185222

186223
state = self.get_state()
@@ -190,6 +227,11 @@ def apply_rule(self, rule: Rule, status: GroupRuleStatus) -> None:
190227
for rule_cond in rule_condition_list:
191228
if self.get_rule_type(rule_cond) == "condition/event":
192229
condition_list.append(rule_cond)
230+
if (
231+
rule_cond.get("id", None)
232+
== "sentry.rules.conditions.regression_event.RegressionEventCondition"
233+
):
234+
self.logger.info("apply_rule got regression_event", extra={**logging_details})
193235
else:
194236
filter_list.append(rule_cond)
195237

@@ -206,10 +248,17 @@ def apply_rule(self, rule: Rule, status: GroupRuleStatus) -> None:
206248
predicate_func = get_match_function(match)
207249
if predicate_func:
208250
if not predicate_func(predicate_iter):
251+
self.logger.info(
252+
"apply_rule invalid predicate_func",
253+
extra={**logging_details},
254+
)
209255
return
210256
else:
211257
self.logger.error(
212-
f"Unsupported {name}_match {match!r} for rule {rule.id}", filter_match, rule.id
258+
f"Unsupported {name}_match {match!r} for rule {rule.id}",
259+
filter_match,
260+
rule.id,
261+
extra={**logging_details},
213262
)
214263
return
215264

@@ -220,6 +269,10 @@ def apply_rule(self, rule: Rule, status: GroupRuleStatus) -> None:
220269
)
221270

222271
if not updated:
272+
self.logger.info(
273+
"apply_rule not updated",
274+
extra={**logging_details},
275+
)
223276
return
224277

225278
if randrange(10) == 0:

0 commit comments

Comments
 (0)