Skip to content

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

Open
wedamija wants to merge 9 commits into
developfrom
danf/cloudflare-cron-monitors
Open

wedamija wants to merge 9 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 📦

Path Size % Change Change
@sentry/browser 29.6 kB - -
@sentry/browser - with treeshaking flags 27.75 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.65 kB - -
@sentry/browser (incl. Tracing) 51.52 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.52 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.5 kB - -
@sentry/browser (incl. Tracing, Replay) 91.14 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.12 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.83 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.83 kB - -
@sentry/browser (incl. Feedback) 47.12 kB - -
@sentry/browser (incl. sendFeedback) 34.65 kB - -
@sentry/browser (incl. FeedbackAsync) 39.76 kB - -
@sentry/browser (incl. Metrics) 30.61 kB - -
@sentry/browser (incl. Logs) 30.89 kB - -
@sentry/browser (incl. Metrics & Logs) 31.55 kB - -
@sentry/react 31.43 kB - -
@sentry/react (incl. Tracing) 53.84 kB +0.01% +2 B 🔺
@sentry/vue 37.55 kB - -
@sentry/vue (incl. Tracing) 54.4 kB - -
@sentry/svelte 29.63 kB - -
@sentry/remix (Remix 3 client bundle) 55.85 kB - -
CDN Bundle 31.33 kB - -
CDN Bundle (incl. Tracing) 52.07 kB - -
CDN Bundle (incl. Logs, Metrics) 33.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.03 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.3 kB - -
CDN Bundle (incl. Tracing, Replay) 89.67 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.62 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 95.83 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.8 kB - -
CDN Bundle - uncompressed 92.46 kB - -
CDN Bundle (incl. Tracing) - uncompressed 154.77 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.04 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 160.72 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 228.66 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 274.58 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 280.52 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 288.28 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 294.21 kB - -
@sentry/nextjs (client) 56.19 kB - -
@sentry/sveltekit (client) 51.9 kB - -
@sentry/core/server 40.52 kB - -
@sentry/core/browser 13.51 kB - -
@sentry/node 145.02 kB +0.01% +5 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.23 kB +0.01% +2 B 🔺
@sentry/node - without tracing 93.46 kB +0.01% +2 B 🔺
@sentry/node - without channel injection 123.17 kB +0.01% +5 B 🔺
@sentry/aws-serverless 101.69 kB +0.01% +2 B 🔺
@sentry/cloudflare (withSentry) - minified 209.31 kB +0.13% +267 B 🔺
@sentry/cloudflare (withSentry) 518.36 kB +0.12% +609 B 🔺

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>

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