Add full CRUD CLI commands for managing alert rules. Alerts in Sentry come in two distinct types with different APIs and scopes.
Issue Alerts
Trigger notifications when error events match conditions.
Commands: sentry alert issues list|view|create|edit|delete
Scope: per-project — /projects/{org}/{project}/rules/
Key fields for create:
name (required)
conditions[] — at least one (required)
actions[] — at least one (required)
actionMatch — all or any (required)
frequency — minutes between checks (default 30)
environment, filters[], filterMatch, owner (optional)
edit: all fields optional; merges over existing (only provided flags change).
delete: requires --yes flag (destructive, affects production alerting).
Validation: ≥1 condition and ≥1 action, enum check for actionMatch/filterMatch, owner must be valid team/user.
Metric Alerts
Trigger notifications when a metric query crosses a threshold.
Commands: sentry alert metrics list|view|create|edit|delete
Scope: org-wide — /organizations/{org}/alert-rules/
Key fields for create:
name (required)
query — filter query string (required)
aggregate — e.g. count(), p95(transaction.duration) (required)
dataset — errors, transactions, sessions, etc. (required)
timeWindow — minutes (required)
triggers[] — at least one with alertThreshold and actions[] (required)
projects[], environment, owner (optional)
edit: merge-based, only provided flags change.
delete: requires --yes flag.
Validation: enum check for dataset and timeWindow, ≥1 trigger with ≥1 action, valid aggregate function.
Implementation Notes
- Follow existing patterns:
buildListCommand for list, buildCommand for view/create/edit/delete
- Use
resolveOrg + resolveProject from lib/resolve-target.ts
- Alert identified by numeric ID or name (fuzzy match, like dashboard)
- Validate enums + required fields before API call to surface errors early
edit: fetch existing rule → merge provided flags → PUT (same merge pattern as widget edit)
delete: safety gate with --yes flag (like project delete, since alerts affect production)
- Output: human table + JSON transform,
--web flag to open in browser
src/commands/alert/ → issues/ and metrics/ subroutes
src/lib/api/alerts.ts for all API calls
Add full CRUD CLI commands for managing alert rules. Alerts in Sentry come in two distinct types with different APIs and scopes.
Issue Alerts
Trigger notifications when error events match conditions.
Commands:
sentry alert issues list|view|create|edit|deleteScope: per-project —
/projects/{org}/{project}/rules/Key fields for
create:name(required)conditions[]— at least one (required)actions[]— at least one (required)actionMatch—allorany(required)frequency— minutes between checks (default 30)environment,filters[],filterMatch,owner(optional)edit: all fields optional; merges over existing (only provided flags change).delete: requires--yesflag (destructive, affects production alerting).Validation: ≥1 condition and ≥1 action, enum check for
actionMatch/filterMatch, owner must be valid team/user.Metric Alerts
Trigger notifications when a metric query crosses a threshold.
Commands:
sentry alert metrics list|view|create|edit|deleteScope: org-wide —
/organizations/{org}/alert-rules/Key fields for
create:name(required)query— filter query string (required)aggregate— e.g.count(),p95(transaction.duration)(required)dataset—errors,transactions,sessions, etc. (required)timeWindow— minutes (required)triggers[]— at least one withalertThresholdandactions[](required)projects[],environment,owner(optional)edit: merge-based, only provided flags change.delete: requires--yesflag.Validation: enum check for
datasetandtimeWindow, ≥1 trigger with ≥1 action, valid aggregate function.Implementation Notes
buildListCommandfor list,buildCommandfor view/create/edit/deleteresolveOrg+resolveProjectfromlib/resolve-target.tsedit: fetch existing rule → merge provided flags → PUT (same merge pattern as widget edit)delete: safety gate with--yesflag (like project delete, since alerts affect production)--webflag to open in browsersrc/commands/alert/→issues/andmetrics/subroutessrc/lib/api/alerts.tsfor all API calls