Skip to content

feat: add alert commands #578

@betegon

Description

@betegon

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)
  • actionMatchall 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)
  • dataseterrors, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions