Skip to content

Commit

Permalink
ref(alerts): Add query_type to analytics tracking code
Browse files Browse the repository at this point in the history
  • Loading branch information
priscilawebdev committed Oct 17, 2024
1 parent fcece96 commit 235d5c1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/sentry/analytics/events/alert_created.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AlertCreatedEvent(analytics.Event):
analytics.Attribute("alert_rule_ui_component", required=False),
analytics.Attribute("duplicate_rule", required=False),
analytics.Attribute("wizard_v3", required=False),
analytics.Attribute("query_type", required=False),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def create_metric_alert(
is_api_token=request.auth is not None,
duplicate_rule=duplicate_rule,
wizard_v3=wizard_v3,
query_type=data.get("queryType", None),
)
return Response(serialize(alert_rule, request.user), status=status.HTTP_201_CREATED)

Expand Down
2 changes: 2 additions & 0 deletions src/sentry/receivers/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def record_alert_rule_created(
alert_rule_ui_component=None,
duplicate_rule=None,
wizard_v3=None,
query_type=None,
**kwargs,
):
# NOTE: This intentionally does not fire for the default issue alert rule
Expand Down Expand Up @@ -334,6 +335,7 @@ def record_alert_rule_created(
alert_rule_ui_component=alert_rule_ui_component,
duplicate_rule=duplicate_rule,
wizard_v3=wizard_v3,
query_type=query_type,
)


Expand Down
2 changes: 1 addition & 1 deletion src/sentry/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _log_robust_failure(self, receiver: object, err: Exception) -> None:
inbound_filter_toggled = BetterSignal() # ["project"]
sso_enabled = BetterSignal() # ["organization_id", "user_id", "provider"]
data_scrubber_enabled = BetterSignal() # ["organization"]
# ["project", "rule", "user", "rule_type", "is_api_token", "duplicate_rule", "wizard_v3"]
# ["project", "rule", "user", "rule_type", "is_api_token", "duplicate_rule", "wizard_v3", "query_type"]
alert_rule_created = BetterSignal()
alert_rule_edited = BetterSignal() # ["project", "rule", "user", "rule_type", "is_api_token"]
repo_linked = BetterSignal() # ["repo", "user"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,19 @@ def test_post_rule_over_256_char_name(self):
)
assert resp.data["name"][0] == "Ensure this field has no more than 256 characters."

@patch("sentry.analytics.record")
def test_performance_alert(self, record_analytics):
valid_alert_rule = {
**self.alert_rule_dict,
"queryType": 1,
"dataset": "transactions",
"eventTypes": ["transaction"],
}
with self.feature(["organizations:incidents", "organizations:performance-view"]):
resp = self.get_response(self.organization.slug, **valid_alert_rule)
assert resp.status_code == 201
assert self.analytics_called_with_args(record_analytics, "alert.created", query_type=1)


@freeze_time()
class AlertRuleCreateEndpointTestCrashRateAlert(AlertRuleIndexBase):
Expand Down

0 comments on commit 235d5c1

Please sign in to comment.