Skip to content

feat(nestjs): Derive SentryCron monitor config from @Cron - #25013

Open
wedamija wants to merge 7 commits into
developfrom
danf/nestjs-cron-config
Open

wedamija wants to merge 7 commits into
developfrom
danf/nestjs-cron-config

Conversation

@wedamija

@wedamija wedamija commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Description

@SentryCron now sends the schedule and time zone of the method's @Cron() decorator with its check-ins, so Sentry creates the monitor on the first run:

@Cron('0 30 9 * * 1-5', { timeZone: 'Europe/Vienna' })
@SentryCron('daily-report', { checkinMargin: 2 })
async dailyReport() {}

This is on by default; pass fromCronDecorator: false to send no config. Schedules Sentry would read differently from how @nestjs/schedule runs them (sub-minute, numeric months, some day-field combinations, fixed UTC offsets) send no config, because a wrong schedule causes false missed check-in alerts. Without a timeZone, the server's local time zone is sent. A config with an explicit schedule is used as is. Monitors created this way are billed, and the schedule and time zone are overwritten from @Cron() on each check-in.

Motivation

Check-ins for monitors that don't exist are dropped, so users have to create each monitor by hand, even though the schedule is already in their code.

Testing

Unit tests for the conversion and decorator order, plus an e2e test in nestjs-basic that checks the config sent with the check-in.

Docs: getsentry/sentry-docs#19782

@wedamija
wedamija marked this pull request as ready for review October 2, 2026 22:28
@wedamija
wedamija requested a review from a team as a code owner October 2, 2026 22:28
@wedamija
wedamija requested review from chargome and nicohrubec and removed request for a team October 2, 2026 22:28
wedamija and others added 6 commits October 5, 2026 12:55
When `@SentryCron` is used without a monitor config, read the schedule and
time zone from the `@Cron()` decorator of `@nestjs/schedule` on the same
method. Check-ins then carry a monitor config, so Sentry creates the monitor
on the first run instead of dropping the check-ins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only read the `@Cron()` schedule when `@SentryCron` gets
`{ fromCronDecorator: true }`, so existing usage keeps sending check-ins
without a monitor config. Other monitor settings passed alongside the flag
are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`@SentryCron` now sends the schedule of the method's `@Cron()` decorator
unless it gets a monitor config with a schedule. Other monitor settings can
still be passed and are merged in, and `fromCronDecorator: false` turns this
off. When `@Cron()` has no `timeZone`, the job runs in the server's local
time zone, so that zone is sent instead of leaving Sentry to assume UTC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`@Cron()` presets are now sent: the ones Sentry accepts as is, and
`@midnight`, `@minutely`, `@weekdays` and `@weekends` as crontabs. When no
schedule can be derived but monitor settings were passed, a debug warning
says no monitor config is sent. The settings type now rejects `schedule`
and `timezone`, and a full monitor config rejects `fromCronDecorator`, so
mixed objects no longer drop fields silently.

Adds an E2E case for a disabled `@Cron()` job triggered through an endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Skip numeric months (cron 2.x counts from 0), day-of-month/day-of-week
combinations Sentry would AND, and time zones Sentry rejects. Clarify the
warning when fromCronDecorator is false.

Co-Authored-By: Claude <noreply@anthropic.com>
Allow month steps like */3 (CronExpression.EVERY_QUARTER), still skipping
month numbers. Drop the @midnight and @annually presets, which cron rejects.
Skip full day ranges like 1-31 when the other day field is set, and send
the canonical time zone name.

Co-Authored-By: Claude <noreply@anthropic.com>
@wedamija
wedamija force-pushed the danf/nestjs-cron-config branch from 5d88d04 to 8cd5e98 Compare October 5, 2026 19:57

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8cd5e98. Configure here.

Comment thread packages/nestjs/src/decorators.ts
Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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