Automatic Instrumentation
Auto-instrument your existing cron libraries with minimal code changes.
Automatically monitor your existing cron jobs with minimal code changes. Sentry can instrument popular Node.js cron libraries to send status updates automatically.
✅ Perfect for:
- Apps using
node-cron
,cron
, ornode-schedule
- Existing cron setups you don't want to modify heavily
- Teams wanting comprehensive monitoring with minimal effort
- Quick migration from other monitoring solutions
❌ Consider Manual Integration if:
- Using custom cron logic or other libraries
- Need fine-grained control over what gets monitored
- Want to customize error handling
- Using serverless functions or cloud-based scheduling
- Install and configure the Sentry SDK
- Ensure you're using a supported cron library
If you haven't already, install one of the supported libraries:
Copied
# Choose one:
npm install node-cron
npm install cron
npm install node-schedule
Copied
import * as Sentry from "@sentry/node";
import cron from "node-cron";
// Instrument the cron library
const cronWithCheckIn = Sentry.cron.instrumentNodeCron(cron);
// Use it exactly like regular node-cron
cronWithCheckIn.schedule(
"0 */2 * * *", // Every 2 hours
() => {
console.log("Processing data...");
// Your job logic here
},
{
name: "data-processor", // This becomes your monitor name in Sentry
timezone: "America/Los_Angeles",
},
);
Requirements: SDK version 7.92.0
or higher.
Copied
import * as Sentry from "@sentry/node";
import { CronJob } from "cron";
// Instrument the CronJob constructor
const CronJobWithCheckIn = Sentry.cron.instrumentCron(
CronJob,
"daily-report",
);
// Use the constructor
const job = new CronJobWithCheckIn("0 9 * * *", () => {
console.log("Generating daily report...");
// Your job logic here
});
job.start();
// Or use the from method
const job2 = CronJobWithCheckIn.from({
cronTime: "* * * * *",
onTick: () => {
console.log("You will see this message every minute");
},
});
Requirements: SDK version 7.92.0
or higher.
Copied
import * as Sentry from "@sentry/node";
import * as schedule from "node-schedule";
// Instrument the schedule export
const scheduleWithCheckIn = Sentry.cron.instrumentNodeSchedule(schedule);
// Use it like regular node-schedule
scheduleWithCheckIn.scheduleJob(
"backup-job", // Monitor name
"0 3 * * *", // Daily at 3 AM
() => {
console.log("Running backup...");
// Your job logic here
},
);
Requirements: SDK version 7.93.0
or higher. Note: Currently only supports cron strings as the second argument to scheduleJob
.
- Run your application and let the cron jobs execute
- Monitors will be automatically created in Sentry when jobs first run
- Check Alerts → Cron Monitors in Sentry to see your monitors
- View the monitor details to see check-in history and status
With automatic instrumentation, you get all these benefits without extra configuration:
- ✅ Automatic monitor creation - No need to create monitors in UI first
- ✅ Status tracking - Start, success, and failure states automatically tracked
- ✅ Runtime monitoring - Track how long jobs take to complete
- ✅ Error integration - Exceptions during jobs are captured and linked
- ✅ Smart defaults - Reasonable timeouts and margins based on your schedule
- Need custom error handling? See Manual Integration
- Managing many services? Consider Advanced Setup for programmatic management
- Want more control? Check out Manual Integration for fine-grained monitoring
- Having issues? Visit Troubleshooting
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").