-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat(monitor): add cron monitor check-ins (monitor run / list) #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f1f4fe
feat(monitor): add cron monitor check-ins (monitor run / list)
BYK 6aec66a
chore: regenerate docs
github-actions[bot] d3b2032
fix: address Warden review findings
BYK 146b8d5
fix: address second-round review findings
BYK d306c26
fix: clear timeout timer in sendCheckInSafely to prevent process hang
BYK c7388ef
fix: address self-review findings
BYK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
|
|
||
|
|
||
| ## Examples | ||
|
|
||
| ```bash | ||
| # Wrap a command with cron monitor check-ins (DSN-based) | ||
| SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0 \ | ||
| sentry monitor run nightly-job -- python manage.py cron | ||
|
|
||
| # The -- separator is optional when the command has no flags | ||
| sentry monitor run nightly-job npm run task | ||
|
|
||
| # Create/update the monitor on the first check-in via --schedule (crontab) | ||
| sentry monitor run nightly-job -s "0 0 * * *" --max-runtime 30 --timezone UTC -- ./backup.sh | ||
|
|
||
| # List cron monitors in an org | ||
| sentry monitor list my-org/ | ||
|
|
||
| # Paginate through monitors | ||
| sentry monitor list my-org/ -c next | ||
|
|
||
| # Output as JSON | ||
| sentry monitor list --json | ||
| ``` | ||
|
|
||
| ## Check-in lifecycle | ||
|
|
||
| `monitor run` sends an `in_progress` check-in when the wrapped command starts, | ||
| then an `ok` or `error` check-in (with duration) when it finishes, based on the | ||
| exit code. The wrapped command inherits stdio, has `SIGINT`/`SIGTERM` | ||
| forwarded, receives the `SENTRY_MONITOR_SLUG` environment variable, and its | ||
| exit code is preserved. Check-in delivery failures are non-fatal — the wrapped | ||
| command still runs and exits with its own code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
plugins/sentry-cli/skills/sentry-cli/references/monitor.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| --- | ||
| name: sentry-cli-monitor | ||
| version: 0.36.0-dev.0 | ||
| description: Work with Sentry cron monitors | ||
| requires: | ||
| bins: ["sentry"] | ||
| auth: true | ||
| --- | ||
|
|
||
| # Monitor Commands | ||
|
|
||
| Work with Sentry cron monitors | ||
|
|
||
| ### `sentry monitor run <monitor-slug command...>` | ||
|
|
||
| Wrap a command with cron monitor check-ins | ||
|
|
||
| **Flags:** | ||
| - `--dsn <value> - DSN to send check-ins to (overrides SENTRY_DSN env var)` | ||
| - `-e, --environment <value> - Environment of the monitor - (default: "production")` | ||
| - `-s, --schedule <value> - Upsert the monitor with this crontab schedule (e.g. '0 * * * *')` | ||
| - `--check-in-margin <value> - Minutes after the expected check-in before it is missed (requires --schedule)` | ||
| - `--max-runtime <value> - Minutes a check-in may run before timing out (requires --schedule)` | ||
| - `--timezone <value> - Timezone of the schedule, tz database string (requires --schedule)` | ||
| - `--failure-issue-threshold <value> - Consecutive failures before an issue is created (requires --schedule)` | ||
| - `--recovery-threshold <value> - Consecutive successes before an issue is resolved (requires --schedule)` | ||
|
|
||
| ### `sentry monitor list <org/project>` | ||
|
|
||
| List cron monitors | ||
|
|
||
| **Flags:** | ||
| - `-n, --limit <value> - Maximum number of monitors to list - (default: "25")` | ||
| - `-f, --fresh - Bypass cache, re-detect projects, and fetch fresh data` | ||
| - `-c, --cursor <value> - Navigate pages: "next", "prev", "first" (or raw cursor string)` | ||
|
|
||
| **JSON Fields** (use `--json --fields` to select specific fields): | ||
|
|
||
| | Field | Type | Description | | ||
| |-------|------|-------------| | ||
| | `id` | string | Monitor ID | | ||
| | `slug` | string | Monitor slug | | ||
| | `name` | string | Monitor name | | ||
| | `status` | string | Monitor status (e.g. active, disabled) | | ||
| | `isMuted` | boolean | Whether the monitor is muted | | ||
| | `config` | object | Schedule configuration | | ||
| | `dateCreated` | string | Creation date (ISO 8601) | | ||
| | `project` | object | Owning project | | ||
|
|
||
| **Examples:** | ||
|
|
||
| ```bash | ||
| # Wrap a command with cron monitor check-ins (DSN-based) | ||
| SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0 \ | ||
| sentry monitor run nightly-job -- python manage.py cron | ||
|
|
||
| # The -- separator is optional when the command has no flags | ||
| sentry monitor run nightly-job npm run task | ||
|
|
||
| # Create/update the monitor on the first check-in via --schedule (crontab) | ||
| sentry monitor run nightly-job -s "0 0 * * *" --max-runtime 30 --timezone UTC -- ./backup.sh | ||
|
|
||
| # List cron monitors in an org | ||
| sentry monitor list my-org/ | ||
|
|
||
| # Paginate through monitors | ||
| sentry monitor list my-org/ -c next | ||
|
|
||
| # Output as JSON | ||
| sentry monitor list --json | ||
| ``` | ||
|
|
||
| All commands also support `--json`, `--fields`, `--help`, `--log-level`, and `--verbose` flags. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { buildRouteMap } from "../../lib/route-map.js"; | ||
| import { listCommand } from "./list.js"; | ||
| import { runCommand } from "./run.js"; | ||
|
|
||
| export const monitorRoute = buildRouteMap({ | ||
| routes: { | ||
|
Check warning on line 6 in src/commands/monitor/index.ts
|
||
| run: runCommand, | ||
| list: listCommand, | ||
| }, | ||
| defaultCommand: "list", | ||
| docs: { | ||
| brief: "Work with Sentry cron monitors", | ||
| fullDescription: | ||
| "Run commands with cron monitor check-ins and list configured monitors.\n\n" + | ||
| " sentry monitor run <slug> -- <command> # wrap a command with check-ins\n" + | ||
| " sentry monitor list # list configured monitors\n\n" + | ||
| "Alias: `sentry monitors` → `sentry monitor list`", | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /** | ||
| * sentry monitor list | ||
| * | ||
| * List cron monitors in an organization, with flexible targeting and cursor | ||
| * pagination. | ||
| * | ||
| * Supports: | ||
| * - Auto-detection from DSN/config | ||
| * - Org-scoped listing with cursor pagination (e.g., sentry/) | ||
| * - Project-scoped targeting (e.g., sentry/cli) — monitors are org-scoped, so | ||
| * this lists the org's monitors | ||
| * - Cross-org project search (e.g., sentry) | ||
| */ | ||
|
|
||
| import { listMonitors, listMonitorsPaginated } from "../../lib/api-client.js"; | ||
| import { escapeMarkdownCell } from "../../lib/formatters/markdown.js"; | ||
| import { type Column, formatTable } from "../../lib/formatters/table.js"; | ||
| import { | ||
| buildOrgListCommand, | ||
| type OrgListCommandDocs, | ||
| } from "../../lib/list-command.js"; | ||
| import type { OrgListConfig } from "../../lib/org-list.js"; | ||
| import { type SentryMonitor, SentryMonitorSchema } from "../../types/index.js"; | ||
|
|
||
| /** Command key for pagination cursor storage */ | ||
| export const PAGINATION_KEY = "monitor-list"; | ||
|
|
||
| /** Monitor with its organization context for display */ | ||
| type MonitorWithOrg = SentryMonitor & { orgSlug?: string }; | ||
|
|
||
| /** | ||
| * Render a monitor's schedule for display. | ||
| * | ||
| * Crontab schedules show the raw expression (e.g. `"0 * * * *"`). | ||
| * Interval schedules show `"every <value> <unit>"` (e.g. `"every 1 hour"`). | ||
| * Returns an empty string when no schedule is configured. | ||
| */ | ||
| function formatSchedule(monitor: MonitorWithOrg): string { | ||
| const config = monitor.config; | ||
| if (!config?.schedule) { | ||
| return ""; | ||
| } | ||
| if (Array.isArray(config.schedule)) { | ||
| return `every ${config.schedule[0]} ${config.schedule[1]}`; | ||
| } | ||
| return config.schedule; | ||
| } | ||
|
|
||
| /** Column definitions for the monitor table. */ | ||
| const MONITOR_COLUMNS: Column<MonitorWithOrg>[] = [ | ||
| { header: "ID", value: (m) => m.id }, | ||
| { header: "SLUG", value: (m) => m.slug }, | ||
| { header: "NAME", value: (m) => escapeMarkdownCell(m.name) }, | ||
| { header: "STATUS", value: (m) => m.status }, | ||
| { header: "SCHEDULE", value: (m) => escapeMarkdownCell(formatSchedule(m)) }, | ||
| ]; | ||
|
|
||
| /** Shared config that plugs into the org-list framework. */ | ||
| const monitorListConfig: OrgListConfig<SentryMonitor, MonitorWithOrg> = { | ||
| paginationKey: PAGINATION_KEY, | ||
| entityName: "monitor", | ||
| entityPlural: "monitors", | ||
| commandPrefix: "sentry monitor list", | ||
| listForOrg: (org) => listMonitors(org), | ||
| listPaginated: (org, opts) => listMonitorsPaginated(org, opts), | ||
| withOrg: (monitor, orgSlug) => ({ ...monitor, orgSlug }), | ||
| displayTable: (monitors: MonitorWithOrg[]) => | ||
| formatTable(monitors, MONITOR_COLUMNS), | ||
| schema: SentryMonitorSchema, | ||
| }; | ||
|
|
||
| const docs: OrgListCommandDocs = { | ||
| brief: "List cron monitors", | ||
| fullDescription: | ||
| "List cron monitors in an organization.\n\n" + | ||
| "Target specification:\n" + | ||
| " sentry monitor list # auto-detect from DSN or config\n" + | ||
| " sentry monitor list <org>/ # list all monitors in org (paginated)\n" + | ||
| " sentry monitor list <org>/<proj> # list monitors in org (project context)\n" + | ||
| " sentry monitor list <org> # list monitors in org\n\n" + | ||
| "Pagination:\n" + | ||
| " sentry monitor list <org>/ -c next # fetch next page\n" + | ||
| " sentry monitor list <org>/ -c prev # fetch previous page\n\n" + | ||
| "Examples:\n" + | ||
| " sentry monitor list # auto-detect or list all\n" + | ||
| " sentry monitor list my-org/ # list monitors in my-org (paginated)\n" + | ||
| " sentry monitor list --limit 10\n" + | ||
| " sentry monitor list --json\n\n" + | ||
| "Alias: `sentry monitors` → `sentry monitor list`", | ||
| }; | ||
|
|
||
| export const listCommand = buildOrgListCommand( | ||
| monitorListConfig, | ||
| docs, | ||
| "monitor" | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.