Skip to content

feat(alert): add alert issues and metrics list commands#579

Draft
betegon wants to merge 10 commits intomainfrom
feat/alert-list-commands
Draft

feat(alert): add alert issues and metrics list commands#579
betegon wants to merge 10 commits intomainfrom
feat/alert-list-commands

Conversation

@betegon
Copy link
Copy Markdown
Member

@betegon betegon commented Mar 26, 2026

Adds sentry alert issues list and sentry alert metrics list.

What this adds

sentry alert issues list lists issue alert rules (the per-project rules that fire when error events match conditions). Supports the same target resolution as sentry issue list:

  • auto-detect from DSN / config (monorepos get all detected projects)
  • org/project — explicit single project
  • org/ — all projects in an org
  • bare slug — cross-org project search

Pagination uses a compound cursor (pipe-separated per-project cursors) so -c next / -c prev works correctly across multi-project results. Uses the same two-phase budget redistribution as issue list: Phase 1 distributes ceil(limit/N) per project, Phase 2 redistributes surplus to projects that still have pages.

sentry alert metrics list lists metric alert rules (org-scoped threshold alerts). Simpler: single org, standard cursor pagination.

Both commands support --json, --limit, --web, and -c next/prev.

Shared infrastructure

While adding the alert list, pulled duplicated code out of issue/list.ts into shared lib modules so both commands use the same implementation rather than copy-pasting:

  • lib/db/pagination.ts: encodeCompoundCursor, decodeCompoundCursor, buildMultiTargetContextKey
  • lib/resolve-target.ts: resolveTargetsFromParsedArg — canonical multi-target resolution for all four modes, with enrichProjectIds and checkIssueShortId options for command-specific behaviour

issue/list.ts drops ~260 lines of local duplicates.

Test plan

# issue alert rules
sentry alert issues list                          # auto-detect
sentry alert issues list my-org/my-project        # explicit
sentry alert issues list my-org/                  # all projects in org
sentry alert issues list my-project               # cross-org search
sentry alert issues list my-org/ -c next          # compound cursor pagination
sentry alert issues list my-org/ --json           # JSON envelope

# metric alert rules
sentry alert metrics list my-org/
sentry alert metrics list --json
sentry alert metrics list -c next

# issue list regression (shared infra)
sentry issue list                                 # still works, no regressions
sentry issue list my-org/ -c next

betegon added 2 commits March 26, 2026 20:51
Adds two new list commands under `sentry alert`:
- `sentry alert issues list` — list issue alert rules for one or more projects,
  with full multi-target resolution (DSN auto-detect, org-all, project-search,
  explicit org/project), compound cursor pagination, Phase 1 + Phase 2 budget
  redistribution, and graceful partial failure handling
- `sentry alert metrics list` — list metric alert rules for an org

Both commands support --json, --limit, --web, and -c next/prev pagination.
…ed lib

Moves duplicated code from issue/list.ts and alert/issues/list.ts into
shared modules so both commands use the same implementation:

- lib/db/pagination.ts: exports CURSOR_SEP, encodeCompoundCursor,
  decodeCompoundCursor, buildMultiTargetContextKey
- lib/resolve-target.ts: exports resolveTargetsFromParsedArg — handles all
  four target modes (auto-detect, explicit, org-all, project-search) with
  options for enrichProjectIds and checkIssueShortId (issue-list-specific)

issue/list.ts drops ~260 lines of local duplicates; alert/issues/list.ts
never needs to define them in the first place.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Dashboard

  • Add pagination and glob filtering to dashboard list by BYK in #560
  • Add a full chart rendering engine for sentry dashboard view that transforms widget data into rich terminal visualizations. by BYK in #555

Init

  • Surface server-provided detail in spinner messages by MathurAditya724 in #588
  • Propagate sentry-trace headers to wizard API calls by betegon in #567
  • Treat bare slug as new project name when not found by BYK in #554

Other

  • (alert) Add alert issues and metrics list commands by betegon in #579
  • (formatters) Colorize SQL in DB span descriptions by BYK in #546
  • (output) Add Zod schema registration to OutputConfig for self-documenting JSON fields by BYK in #582
  • (telemetry) Report unknown commands to Sentry by BYK in #563
  • Expose CLI as a programmatic library by BYK in #565
  • Bidirectional cursor pagination (-c next / -c prev) by BYK in #564
  • Add sentry sourcemap inject and sentry sourcemap upload commands by BYK in #547
  • Native debug ID injection and sourcemap upload by BYK in #543

Bug Fixes 🐛

Dashboard

  • Fix table widget rendering and timeseries bar chart width by BYK in #584
  • Validate display types against all datasets by betegon in #577
  • Auto-clamp widget limit instead of erroring by BYK in #573
  • Default issue dataset table columns to ["issue"] by betegon in #570
  • Scale timeseries bar width to fill chart area by BYK in #562
  • Resolve dashboard by ID/slug in addition to title by BYK in #559

Event

  • Detect SHORT-ID/EVENT-ID format in event view by BYK in #574
  • Auto-fallback to org-wide search when event 404s in project by BYK in #575

Other

  • (api) Show meaningful message for network errors instead of '0 Unknown' by BYK in #572
  • (auth) Skip stale cached user info for env var tokens in auth status by BYK in #589
  • (event-view) Auto-redirect issue short IDs in two-arg form (CLI-MP) by BYK in #558
  • (help) Show help when user passes help as positional arg by BYK in #561
  • (issue) Auto-redirect bare org slug to org-all mode in issue list by BYK in #576
  • (log) Use 30d default period and show newest logs first by sergical in #568
  • Reject @-selectors in parseOrgProjectArg with helpful redirect by BYK in #557

Documentation 📚

  • Add missing command pages for trace, span, sourcemap, repo, trial, schema by sergical in #569

Internal Changes 🔧

Coverage

  • Use informational-patch input instead of sed hack by BYK in #544
  • Make checks informational on release branches by BYK in #541

Event

  • Replace "latest" magic string with @latest sentinel constant by BYK in #583
  • Deduplicate span tree building into shared helper by BYK in #581

Other

  • (api) Collapse stats on issue detail endpoints to save 100-300ms by BYK in #551
  • (ci) Upgrade GitHub Actions to Node 24 runtime by BYK in #542
  • (db) DRY up database layer with shared helpers and lint enforcement by BYK in #550
  • (docs) Polish sidebar, header, focus, and code block UX by sergical in #580
  • (issue-list) Use collapse parameter to skip unused Snuba queries by BYK in #545
  • Regenerate skill files and command docs by github-actions[bot] in 0276f760
  • Regenerate skill files and command docs by github-actions[bot] in efa746d2
  • Bump Bun from 1.3.9 to 1.3.11 by BYK in #552
  • Regenerate skill files by github-actions[bot] in ec1ffe28

Other

  • release: 0.21.0 by betegon in 6c89fa24

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/pr-preview/pr-579/

Built to branch gh-pages at 2026-03-26 20:31 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

Codecov Results 📊

126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 75.66%. Project has 1366 uncovered lines.
❌ Project coverage is 95.18%. Comparing base (base) to head (head).

Files with missing lines (4)
File Patch % Lines
resolve-target.ts 56.82% ⚠️ 57 Missing
alerts.ts 11.54% ⚠️ 23 Missing
sentry-urls.ts 8.33% ⚠️ 11 Missing
pagination.ts 96.97% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.46%    95.18%    -0.28%
==========================================
  Files          194       200        +6
  Lines        28040     28316      +276
  Branches         0         0         —
==========================================
+ Hits         26766     26950      +184
- Misses        1274      1366       +92
- Partials         0         0         —

Generated by Codecov Action

betegon and others added 7 commits March 26, 2026 21:30
…List

Both alert/issues/list and alert/metrics/list were implementing their own
4-mode target dispatch and compound cursor machinery from scratch, bypassing
the shared dispatchOrgScopedList infrastructure every other list command uses.

Replace with the standard pattern:
- dispatchOrgScopedList with ListCommandMeta + 4 mode handler overrides
- Simple parallel fetch-all for auto-detect/explicit/project-search modes
  (no compound cursor — alert rule lists are small datasets)
- Single-cursor pagination for org-all mode (metrics: listMetricAlertsPaginated
  with cursor; issues: resolveTargetsFromParsedArg for project list + fetch all)

Removes ~320 lines of custom dispatch and compound cursor logic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ucture

- Use jsonTransformListResult (shared) instead of custom JSON transforms
- Separate raw rules into items (for JSON) and displayRows (for human output)
- Add --query/-q flag for client-side name filtering on both alert commands
- Restore api-client.ts alerts export to original shape

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ssue list

Full structural alignment with sentry issue list:
- FetchResult success/failure wrapping per target
- fetchWithBudget with two-phase surplus redistribution
- Compound cursor pagination (encodeCompoundCursor/decodeCompoundCursor)
- buildProjectAliasMap with buildOrgAwareAliases + setProjectAliases
- trimWithProjectGuarantee for per-project representation
- One handleResolvedTargets for all 4 modes (alert issues have no org-level API)
- allowCursorInModes for all modes including org-all
- parseCursorFlag explicitly in cursor flag definition
- logger.warn for partial failures
- IssueAlertListResult with title/footerMode/moreHint/footer
- jsonTransformListResult (shared JSON transform)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…issue list

Full structural alignment with sentry issue list and alert issues list:
- FetchResult success/failure wrapping per org with withAuthGuard
- fetchWithBudget with two-phase surplus redistribution (per-org)
- Compound cursor pagination across multiple orgs (auto-detect/explicit/project-search)
- trimWithOrgGuarantee for per-org representation
- handleResolvedOrgs for multi-org modes; handleOrgAllMetricAlerts for single-org cursor
- allowCursorInModes for auto-detect/explicit/project-search
- parseCursorFlag explicitly in cursor flag definition
- logger.warn for partial org failures
- MetricAlertListResult with title/footerMode/moreHint/footer
- jsonTransformListResult (shared JSON transform)
- buildMultiOrgContextKey isolates cursors per unique org set + query

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…list

Removes the separate handleOrgAllMetricAlerts handler and routes all 4
modes (including org-all) through handleResolvedOrgs. org-all resolves
all projects in the specified org, deduplicates to unique orgs (just the
one), then uses fetchWithBudget with compound cursor — same path as
auto-detect/explicit/project-search. This makes the structure identical
to alert issues list and supports multi-org results from DSN detection
consistently across all modes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extract FetchResult<T>, trimWithGroupGuarantee<T>, buildProjectAliasMap<T>,
and buildMultiOrgContextKey into lib/ so all three list commands (issue,
alert issues, alert metrics) share the same implementations. Each command
retains a thin domain-specific wrapper where needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
For metric alerts (org-scoped), explicit and org-all modes already provide
the org slug in the parsed arg. Routing them through resolveTargetsFromParsedArg
caused an unnecessary listProjects API call just to re-derive the org slug.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant