Skip to content

feat(cloudflare): Add opt-in cron monitoring for Cron Triggers - #25014

Merged
wedamija merged 17 commits into
developfrom
danf/cloudflare-cron-monitors
Oct 9, 2026
Merged

wedamija merged 17 commits into
developfrom
danf/cloudflare-cron-monitors

Conversation

@wedamija

@wedamija wedamija commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Description

Adds an opt-in cronTriggersIntegration that sends check-ins for Cron Triggers, with the schedule from controller.cron, so Sentry creates the monitor on the first run:

const jobs = { '30 9 * * MON-FRI': { slug: 'daily-report', run: dailyReport } };

export default Sentry.withSentry(
  env => ({
    dsn: env.SENTRY_DSN,
    integrations: [Sentry.cronTriggersIntegration({ slug: cron => jobs[cron]?.slug })],
  }),
  { async scheduled(controller, env) { await jobs[controller.cron]?.run(env); } },
);

It's opt-in because monitors are billed. slug can also return monitor settings, or undefined to 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 wrangler config.

Testing

Unit tests for the integration and the schedule conversion.

Docs: getsentry/sentry-docs#19783

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>
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 29.72 kB +0.41% +119 B 🔺
@sentry/browser - with treeshaking flags 27.86 kB +0.39% +107 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 27.75 kB +0.38% +103 B 🔺
@sentry/browser (incl. Tracing) 51.75 kB +0.46% +233 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 51.75 kB +0.46% +233 B 🔺
@sentry/browser (incl. Tracing, Profiling) 54.73 kB +0.42% +225 B 🔺
@sentry/browser (incl. Tracing, Replay) 91.44 kB +0.24% +211 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.34 kB +0.21% +161 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 96.14 kB +0.23% +215 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 109.15 kB +0.24% +261 B 🔺
@sentry/browser (incl. Feedback) 47.24 kB +0.26% +122 B 🔺
@sentry/browser (incl. sendFeedback) 34.77 kB +0.34% +117 B 🔺
@sentry/browser (incl. FeedbackAsync) 39.85 kB +0.26% +100 B 🔺
@sentry/browser (incl. Metrics) 30.72 kB +0.37% +112 B 🔺
@sentry/browser (incl. Logs) 31.01 kB +0.39% +119 B 🔺
@sentry/browser (incl. Metrics & Logs) 31.67 kB +0.38% +117 B 🔺
@sentry/react 31.54 kB +0.35% +107 B 🔺
@sentry/react (incl. Tracing) 54.07 kB +0.44% +236 B 🔺
@sentry/vue 37.75 kB +0.55% +204 B 🔺
@sentry/vue (incl. Tracing) 54.67 kB +0.51% +276 B 🔺
@sentry/svelte 29.74 kB +0.39% +114 B 🔺
@sentry/remix (Remix 3 client bundle) 56.76 kB +0.39% +215 B 🔺
CDN Bundle 31.43 kB +0.31% +96 B 🔺
CDN Bundle (incl. Tracing) 52.28 kB +0.41% +210 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.64 kB +0.24% +79 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 54.23 kB +0.38% +203 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.53 kB +0.21% +153 B 🔺
CDN Bundle (incl. Tracing, Replay) 89.91 kB +0.2% +174 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.86 kB +0.19% +169 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 96.06 kB +0.17% +160 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.05 kB +0.19% +178 B 🔺
CDN Bundle - uncompressed 92.72 kB +0.28% +253 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 155.25 kB +0.32% +482 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.25 kB +0.22% +212 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 161.21 kB +0.3% +482 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.22 kB +0.11% +238 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 275.35 kB +0.17% +457 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 281.29 kB +0.17% +457 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.05 kB +0.16% +457 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 294.98 kB +0.16% +457 B 🔺
@sentry/nextjs (client) 56.45 kB +0.46% +256 B 🔺
@sentry/sveltekit (client) 52.14 kB +0.45% +233 B 🔺
@sentry/core/server 40.85 kB +0.49% +198 B 🔺
@sentry/core/browser 13.71 kB +1.48% +199 B 🔺
@sentry/node 145.87 kB +0.15% +209 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.33 kB +0.14% +109 B 🔺
@sentry/node - without tracing 93.66 kB +0.22% +202 B 🔺
@sentry/node - without channel injection 124.01 kB +0.17% +202 B 🔺
@sentry/aws-serverless 101.88 kB +0.19% +192 B 🔺
@sentry/cloudflare (withSentry) - minified 210 kB +0.47% +972 B 🔺
@sentry/cloudflare (withSentry) 520.64 kB +0.55% +2.84 kB 🔺

View base workflow run

wedamija and others added 4 commits October 2, 2026 13:27
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>
@wedamija
wedamija marked this pull request as ready for review October 2, 2026 23:21
@wedamija
wedamija requested a review from a team as a code owner October 2, 2026 23:21
@wedamija
wedamija requested review from a team, andreiborza and isaacs and removed request for a team October 2, 2026 23:21

@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 eb22bd1. Configure here.

Comment thread packages/cloudflare/src/instrumentations/worker/instrumentScheduled.ts Outdated
Comment thread packages/cloudflare/src/integrations/cronTriggers.ts
wedamija and others added 2 commits October 2, 2026 17:41
…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>
@andreiborza
andreiborza requested a review from JPeer264 October 5, 2026 10:48
@andreiborza andreiborza added external PR from an external contributor and removed external PR from an external contributor labels Oct 5, 2026
wedamija and others added 2 commits October 5, 2026 12:18
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>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

👋 @isaacs, @andreiborza, @getsentry/team-javascript-sdks — Please review this PR when you get a chance!

@andreiborza andreiborza 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.

Hi @wedamija, thanks for adding this. Overall LGTM, just one ask regarding the slug option.

Also waiting for an approval from @JPeer264 who is in charge of the CF sdk.

* 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;

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.

m: Can we call it monitorSlug instead, to be in line with the other monitors in core? e.g.

monitorSlug: CheckIn['monitorSlug'],

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.

That is a good idea. I'll take over this PR as Dan might be out this week.

@JPeer264

JPeer264 commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

If that is ok I'll turn a little the jobs constant example. Since we have no idea how users are defining there scheduled function and the docs usually show this with multiple crons, we can use the same structure, but make them named instead. With that it is closer to the CF docs and users are as flexible as before (I'm just not a big fan of recommending an untyped run method in an untyped object).

The picture shows what I mean. The switch/case is the same as in the CF docs, and the run is now gone from the constant, which makes it typed via the scheduled function like before (that is the updated docs):

Screenshot 2026-10-07 at 18 13 10

I added couple of things, but didn't change the main logic, that was fine

@JPeer264
JPeer264 requested a review from andreiborza October 7, 2026 15:58
@JPeer264

JPeer264 commented Oct 7, 2026

Copy link
Copy Markdown
Member

I'll match the docs as well

Comment thread packages/cloudflare/src/integrations/cronTriggers.ts Outdated
@wedamija
wedamija merged commit 84f8010 into develop Oct 9, 2026
1029 of 1036 checks passed
@wedamija
wedamija deleted the danf/cloudflare-cron-monitors branch October 9, 2026 18:05
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.

3 participants