Repository navigation
feat(cloudflare): Add opt-in cron monitoring for Cron Triggers - #25014
Conversation
Add a `monitorCronTriggers` option. When set, each Cron Trigger run of the `scheduled` handler sends in-progress and ok/error check-ins whose monitor config carries the trigger's cron expression, so Sentry creates the monitor on the first run. The slug is derived from the cron expression, or picked by a user function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
size-limit report 📦
|
Cloudflare numbers weekdays from 1 = Sunday, while Sentry uses 0 = Sunday, so the weekday field is now converted to names (or a 0-based number for `nL`) before it is sent. Expressions that can't be converted are sent without a schedule. Derived slugs now write `,`, `-` and `/` as distinct tokens and append a hash when the expression has other characters or the slug is too long. A throwing `monitorCronTriggers` function and runs without a cron expression send no check-ins instead of affecting the handler, and the function can return other monitor settings along with the slug. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tion
Replaces the `monitorCronTriggers` option with an opt-in
`cronTriggersIntegration({ slug })`, so the schedule conversion and slug
code is tree-shaken for Workers that don't use it. The scheduled handler
only looks the integration up by name. Also drops `nL` and `n#k` weekday
conversion (sent without a schedule) and simplifies the slug hash.
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
*/n gives the same days in both numberings and keeps Sentry's AND rule for the day fields. Sentry rejects W and ? in the day of month, so send no schedule. Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit eb22bd1. Configure here.
…dler Start the check-in before the handler's try block and guard the final check-in, so a failing check-in never skips the job, fails a successful run, or is captured as the handler's exception. Co-Authored-By: Claude <noreply@anthropic.com>
On Cloudflare 1 = Sunday, so `1-5` runs Sunday to Thursday. Day names are unambiguous. Co-Authored-By: Claude <noreply@anthropic.com>
Cloudflare doesn't document how day of month and day of week combine, so only send a schedule when one of them is *. The warning now also says the other monitor settings aren't sent. Co-Authored-By: Claude <noreply@anthropic.com>
|
👋 @isaacs, @andreiborza, @getsentry/team-javascript-sdks — Please review this PR when you get a chance! |
| * and other monitor settings, such as `checkinMargin` or `maxRuntime`. Returning `undefined` | ||
| * sends no check-ins for that trigger, and so does a function that throws. | ||
| */ | ||
| slug?: (cron: string) => string | CronTriggerMonitorSettings | undefined; |
There was a problem hiding this comment.
m: Can we call it monitorSlug instead, to be in line with the other monitors in core? e.g.
There was a problem hiding this comment.
That is a good idea. I'll take over this PR as Dan might be out this week.
…tead of mock.calls
…duled handler runs
…ersIntegration example
|
If that is ok I'll turn a little the The picture shows what I mean. The
I added couple of things, but didn't change the main logic, that was fine |
|
I'll match the docs as well |


Description
Adds an opt-in
cronTriggersIntegrationthat sends check-ins for Cron Triggers, with the schedule fromcontroller.cron, so Sentry creates the monitor on the first run:It's opt-in because monitors are billed.
slugcan also return monitor settings, orundefinedto skip a trigger; without it the slug is derived from the expression. Schedules Sentry would read differently from Cloudflare (L/#/W/?, or both day fields set) are sent without a monitor config, because a wrong schedule causes false missed check-in alerts. Weekday numbers are sent as names, since Cloudflare counts from 1 = Sunday.Tree-shaken when not imported: +267 B on
@sentry/cloudflare (withSentry) - minified.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
wranglerconfig.Testing
Unit tests for the integration and the schedule conversion.
Docs: getsentry/sentry-docs#19783