Skip to content

Commit

Permalink
feat(crons): Document Node Schedule support (#8851)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored Jan 10, 2024
1 parent 07c53ea commit 736039b
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/includes/javascript-crons-automatic-crons-instrumentation.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
If you're using the [`cron`](https://www.npmjs.com/package/cron) or [`node-cron`](https://www.npmjs.com/package/node-cron) libraries to run your periodic tasks, you can use our instrumentation functions in the `Sentry.cron` export to monitor your cron jobs.

Requires SDK version `7.92.0` or higher.
If you're using the [`cron`](https://www.npmjs.com/package/cron), [`node-cron`](https://www.npmjs.com/package/node-cron) or [`node-schedule`](https://www.npmjs.com/package/node-schedule) libraries to run your periodic tasks, you can use our instrumentation functions in the `Sentry.cron` export to monitor your cron jobs.

### Cron

Use `Sentry.cron.instrumentCron` to instrument the `CronJob` constructor or `CronJob.from` method. Pass the name of the cron monitor as a second argument to the function.
Requires SDK version `7.92.0` or higher.

Use `Sentry.cron.instrumentCron` to instrument the `CronJob` constructor or `CronJob.from` method in the [`cron`](https://www.npmjs.com/package/cron) library. Pass the name of the cron monitor as a second argument to the function.

```JavaScript
import { CronJob } from "cron";
Expand All @@ -27,7 +27,9 @@ const job = CronJobWithCheckIn.from({

### Node Cron

Use `Sentry.cron.instrumentNodeCron` to instrument the `cron` export from the `node-cron` library. This returns an object with the same API as the original `cron` export, but with the `schedule` method instrumented. You can pass the name of the cron monitor and an optional time zone as part of the third options argument to the function.
Requires SDK version `7.92.0` or higher.

Use `Sentry.cron.instrumentNodeCron` to instrument the `cron` export from the [`node-cron`](https://www.npmjs.com/package/node-cron) library. This returns an object with the same API as the original `cron` export, but with the `schedule` method instrumented. You can pass the name of the cron monitor and an optional time zone as part of the third options argument to the function.

```JavaScript
import cron from "node-cron";
Expand All @@ -42,3 +44,23 @@ cronWithCheckIn.schedule(
{ name: "my-cron-job" }
);
```

### Node Schedule

Requires SDK version `7.93.0` or higher.

Use `Sentry.cron.instrumentNodeSchedule` to instrument the `schedule` export from the [`node-schedule`](https://www.npmjs.com/package/node-schedule) library. This returns an object with the same API as the original `schedule` export, but with the `scheduleJob` method instrumented. You can pass the name of the cron job as the first argument to the function. Currently this only supports cronstring as the second argument to `scheduleJob`.

```JavaScript
import * as schedule from "node-schedule";

const scheduleWithCheckIn = Sentry.cron.instrumentNodeSchedule(schedule);

scheduleWithCheckIn.scheduleJob(
"my-cron-job",
"* * * * *",
() => {
console.log("running a task every minute");
}
);
```

1 comment on commit 736039b

@vercel
Copy link

@vercel vercel bot commented on 736039b Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sentry-docs – ./

docs.sentry.io
sentry-docs.sentry.dev
sentry-docs-git-master.sentry.dev

Please sign in to comment.