Skip to content

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

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

wedamija wants to merge 11 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
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: 3730ab6 (PR test merge using develop at b722d3c)

Against: b722d3c (develop) · base run #64034

✅ 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.5 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.4 kB - -
@sentry/browser (incl. Tracing) 52.66 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.66 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.59 kB - -
@sentry/browser (incl. Tracing, Replay) 92.89 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.5 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.63 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.6 kB - -
@sentry/browser (incl. Feedback) 47.95 kB - -
@sentry/browser (incl. sendFeedback) 35.47 kB - -
@sentry/browser (incl. FeedbackAsync) 40.57 kB - -
@sentry/browser (incl. Metrics) 31.4 kB - -
@sentry/browser (incl. Logs) 31.68 kB - -
@sentry/browser (incl. Metrics & Logs) 32.36 kB - -
@sentry/react 32.2 kB - -
@sentry/react (incl. Tracing) 54.94 kB - -
@sentry/vue 38.67 kB - -
@sentry/vue (incl. Tracing) 55.55 kB - -
@sentry/svelte 30.42 kB - -
@sentry/remix (Remix 3 client bundle) 57.71 kB - -
CDN Bundle 32.11 kB - -
CDN Bundle (incl. Tracing) 53.14 kB - -
CDN Bundle (incl. Logs, Metrics) 34.31 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.76 kB - -
CDN Bundle (incl. Tracing, Replay) 91.3 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.26 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.44 kB - -
CDN Bundle - uncompressed 94.47 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.46 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.02 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.43 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.57 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.15 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.1 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.79 kB - -
@sentry/nextjs (client) 57.79 kB - -
@sentry/sveltekit (client) 53.11 kB - -
@sentry/core/server 44.34 kB - -
@sentry/core/browser 13.95 kB - -
@sentry/node 155.09 kB +0.01% +15 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.67 kB - -
@sentry/node - without tracing 95.85 kB +0.03% +25 B 🔺
@sentry/node - without channel injection 135.73 kB +0.02% +22 B 🔺
@sentry/aws-serverless 104.01 kB +0.03% +25 B 🔺
@sentry/cloudflare (withSentry) - minified 198.09 kB - -
@sentry/cloudflare (withSentry) 492.11 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 218.68 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 :)

return monitorConfig;
}

const { fromCronDecorator = true, ...monitorSettings } = monitorConfig || {};

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.

When this lands, every current @SentryCron user who passes no schedule starts to upsert monitors on the next deploy. That has three effects:

  1. Monitors that did not exist get created, and they are billed.
  2. Monitors that users created by hand get their schedule and time zone overwritten on each check-in. If a user picked a different time zone in the UI on purpose (for example, the one they think in), the SDK now silently replaces it.
  3. If the org is over its monitor quota, creation can fail, and the check-ins are dropped as before. That is not worse, but users get no signal.

The PR description says this, but users of the SDK are more likely to notice a changelog entry. This repo writes the changelog at release time, so this is mainly a request to make sure the release notes put it under "Important Changes".

Can you confirm that default-on is the intended product choice?

If so, then this is what this is doing, so great! Let's just add a clear note for the release changelog that names the billing effect and the fromCronDecorator: false opt-out.

@wedamija wedamija Oct 29, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah default-on is intended. Generally, we expect that people want to just use their cron's built in schedule, and that it's most likely a misconfiguration if they didn't do so.

}

// Without a `timeZone`, `cron` uses the server's time zone, but Sentry would assume UTC.
const timezone = toSentryTimeZone(typeof timeZone === 'string' && timeZone ? timeZone : getLocalTimeZone());

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.

Without timeZone on @Cron(), this'll send the host's local time zone. That matches what cron does on that host, so each single check-in is correct.

But a monitor config is shared by all environments that use the same slug. If one host runs in UTC (eg, a container) and another in America/New_York (a developer laptop, a staging box, etc), each check-in overwrites the monitor's time zone. The monitor then expects runs at the wrong hour, and Sentry can report missed check-ins for runs that happened on time.

Before this PR, the user had to pick one time zone by hand, so that failure mode did not exist.

Suggestion: probably just need to document that jobs without an explicit timeZone take the host's time zone (if it's not already in the linked docs PR), and that hosts with different zones must set timeZone on @Cron(). I can't think of a correct automatic fix, because the job really does run in the host's zone.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, updated the docs pr getsentry/sentry-docs#19782

Comment thread packages/nestjs/src/decorators.ts Outdated
Comment thread packages/nestjs/src/decorators.ts Outdated
Comment thread packages/nestjs/src/decorators.ts
…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

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 2 not successful, 65 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Failing after 1m Details
❌ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry (latest) Test (optional) Failing after 3m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E angular (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E angular (canary) Test (optional) Successful in 54s Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (canary, turbopack) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E nuxt-4 (canary) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-standalone (canary, turbopack) Test (optional) Successful in 48s Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 48s Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 53s Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 56s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (canary, webpack) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E nuxt-4-static (canary) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions-send-to-sentry (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-3 (canary) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 25s Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E node-flue-send-to-sentry (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E vue-3 (canary) Test (optional) Successful in 1m Details

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.

2 participants