DATE:
AUTHOR:
Sentry
SDKs Crons Node

Node.js cron and node-cron auto-instrumentation

DATE:
AUTHOR: Sentry

Sentry’s JavaScript SDK now auto-instruments cron monitors for the cron and node-cron libraries.

Sentry Crons allows you to monitor the uptime and performance of any scheduled, recurring job. Once implemented, it allows you to get alerts and metrics to help you solve errors, detect timeouts, and prevent disruptions to your service.

For cron:

import * as Sentry from '@sentry/node';
import { CronJob } from 'cron';

const CronJobWithCheckIn = Sentry.cron.instrumentCron(CronJob, 'my-cron-job');

// use the constructor
const job = new CronJobWithCheckIn('* * * * *', () => {
  console.log('You will see this message every minute');
});

// or from
const job = CronJobWithCheckIn.from({
  cronTime: '* * * * *',
  onTick: () => {
    console.log('You will see this message every minute');
  },
});

For node-cron:

import * as Sentry from '@sentry/node';
import cron from 'node-cron';

const cronWithCheckIn = Sentry.cron.instrumentNodeCron(cron);

cronWithCheckIn.schedule(
  '* * * * *',
  () => {
    console.log('running a task every minute');
  },
  { name: 'my-cron-job' },
);



This feature requires SDK version 7.92.0. For more information see the docs.

Powered by LaunchNotes