Skip to content

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

Merged
isaacs merged 12 commits into
developfrom
danf/nestjs-cron-config
Oct 29, 2026
Merged

isaacs merged 12 commits into
developfrom
danf/nestjs-cron-config

Conversation

@wedamija

@wedamija wedamija commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Part of a series adding automatic Crons monitoring for the most-used job schedulers in each SDK. Check-ins for a monitor that doesn't exist yet are dropped, so today each monitor has to be created by hand with its schedule copied from the code. Sending the job's schedule as the monitor config lets Sentry create the monitor and keep it in sync.

@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. It's on by default; pass fromCronDecorator: false to send no config. A config with its own schedule is used as is. Monitors created this way are billed, and their schedule and time zone are overwritten from @Cron() on each check-in.

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

Without a timeZone, the server's local time zone is sent. Schedules Sentry would read differently from @nestjs/schedule (sub-minute, numeric months, some day-field combinations, fixed UTC offsets) check in without a config.

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 Resolved
Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

👋 @chargome, @nicohrubec — Please review this PR when you get a chance!

2 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

👋 @chargome, @nicohrubec — Please review this PR when you get a chance!

@github-actions

Copy link
Copy Markdown
Contributor

👋 @chargome, @nicohrubec — Please review this PR when you get a chance!

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

👋 @chargome, @nicohrubec — Please review this PR when you get a chance!

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

👋 @chargome, @nicohrubec — Please review this PR when you get a chance!

@linear-code

linear-code Bot commented Oct 25, 2026

Copy link
Copy Markdown

JS-3999

@wedamija
wedamija requested review from a team as code owners October 28, 2026 19:48
@wedamija
wedamija requested review from logaretm and msonnb and removed request for a team October 28, 2026 19:48
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: b167dcc (PR test merge using develop at 30cfb4c)

Against: 30cfb4c (develop) · base run #64245

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.39 kB - -
@sentry/browser - with treeshaking flags 28.53 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.42 kB - -
@sentry/browser (incl. Tracing) 52.71 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.69 kB - -
@sentry/browser (incl. Tracing, Replay) 93.01 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.76 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.75 kB - -
@sentry/browser (incl. Feedback) 47.97 kB - -
@sentry/browser (incl. sendFeedback) 35.49 kB - -
@sentry/browser (incl. FeedbackAsync) 40.6 kB - -
@sentry/browser (incl. Metrics) 31.42 kB - -
@sentry/browser (incl. Logs) 31.72 kB - -
@sentry/browser (incl. Metrics & Logs) 32.44 kB - -
@sentry/react 32.27 kB - -
@sentry/react (incl. Tracing) 55.07 kB - -
@sentry/vue 38.66 kB - -
@sentry/vue (incl. Tracing) 55.73 kB - -
@sentry/svelte 30.42 kB - -
@sentry/remix (Remix 3 client bundle) 57.8 kB - -
CDN Bundle 32.18 kB - -
CDN Bundle (incl. Tracing) 53.23 kB - -
CDN Bundle (incl. Logs, Metrics) 34.45 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.18 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.86 kB - -
CDN Bundle (incl. Tracing, Replay) 91.44 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.38 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.56 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.55 kB - -
CDN Bundle - uncompressed 94.62 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.6 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.09 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.33 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.65 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.29 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.99 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.7 kB - -
@sentry/nextjs (client) 57.89 kB - -
@sentry/sveltekit (client) 53.22 kB - -
@sentry/core/server 44.24 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 154.92 kB +0.02% +16 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.95 kB - -
@sentry/node - without tracing 96.14 kB +0.03% +24 B 🔺
@sentry/node - without channel injection 135.33 kB +0.02% +15 B 🔺
@sentry/aws-serverless 104.32 kB +0.03% +23 B 🔺
@sentry/cloudflare (withSentry) - minified 197.92 kB - -
@sentry/cloudflare (withSentry) 491.93 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 218.35 kB - -

View base workflow run

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few things below I'd like to confirm and/or fix before landing, but this looks good. Does what it says on the tin :)

Comment thread packages/nestjs/src/decorators.ts Resolved
Comment thread packages/nestjs/src/decorators.ts Resolved
Comment thread packages/nestjs/src/decorators.ts Resolved
Comment thread packages/nestjs/src/decorators.ts Resolved
Comment thread packages/nestjs/src/decorators.ts Resolved
…s on @nestjs/schedule 4+

A day field that covers every day (like sun-sat or 0,1,2,3,4,5,6) is ignored by cron but ORed by Sentry,
so those schedules are now found by counting the expanded values. Numeric months are sent when the
@Cron() instrumentation saw @nestjs/schedule 4 or later, where cron counts months from 1.
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

All optional checks were successful. 1 successful. See the run.

Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 35s Details

@isaacs
isaacs self-requested a review October 29, 2026 19:37

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All my concerns addressed. Looks good to me!

@isaacs
isaacs enabled auto-merge (squash) October 29, 2026 19:40
@isaacs
isaacs merged commit cbab405 into develop Oct 29, 2026
58 checks passed
@isaacs
isaacs deleted the danf/nestjs-cron-config branch October 29, 2026 19:48
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.

2 participants