Skip to content

feat(crons): Document withMonitor API for JS SDK #8347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/includes/javascript-crons-checkins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const checkInId = Sentry.captureCheckIn({

// 🟢 Notify Sentry your job has completed successfully:
Sentry.captureCheckIn({
// Make sure this variable is named `checkInId`
checkInId,
monitorSlug: "<monitor-slug>",
status: "ok",
Expand All @@ -22,6 +23,7 @@ If your job execution fails, you can notify Sentry about the failure:
```javascript
// 🔴 Notify Sentry your job has failed:
Sentry.captureCheckIn({
// Make sure this variable is named `checkInId`
checkInId,
monitorSlug: "<monitor-slug>",
status: "error",
Expand Down
11 changes: 11 additions & 0 deletions src/includes/javascript-crons-job-monitoring.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Use the `Sentry.withMonitor()` API to monitor a callback and notify you if your periodic task is missed (or doesn't start when expected), if it fails due to a problem in the runtime (such as an error), or if it fails by exceeding its maximum runtime.

`Sentry.withMonitor()` requires SDK version `7.76.0`.

```javascript
Sentry.withMonitor("<monitor-slug>", () => {
// Execute your scheduled task here...
});
```

If you are using an SDK version prior to `7.76.0`, you can use the `Sentry.captureCheckIn()` API documented below.
9 changes: 9 additions & 0 deletions src/platform-includes/crons/setup/javascript.astro.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Cron monitoring is only supported in Astro server-side

## Job Monitoring (Recommended)

<Include name="javascript-crons-job-monitoring.mdx" />

## Check-Ins

<Include name="javascript-crons-checkins.mdx" />
7 changes: 7 additions & 0 deletions src/platform-includes/crons/setup/javascript.bun.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Job Monitoring (Recommended)

<Include name="javascript-crons-job-monitoring.mdx" />

## Check-Ins

<Include name="javascript-crons-checkins.mdx" />
3 changes: 0 additions & 3 deletions src/platform-includes/crons/setup/javascript.mdx

This file was deleted.

6 changes: 6 additions & 0 deletions src/platform-includes/crons/setup/javascript.nextjs.mdx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Cron monitoring is only supported in Server and Edge runtimes for Next.js

## Automatic Check-Ins (Vercel Only)

If you are hosting your Next.js application on Vercel and you are using [Vercel's Cron Jobs feature](https://vercel.com/docs/cron-jobs), the Next.js SDK will automatically create Check-Ins for you. Instrumented cron jobs are decided at runtime by examining the `crons` field in your `vercel.json` file.

To opt out of this behaviour, set the `automaticVercelMonitors` option to `false` in your Sentry settings in `next.config.js`. See <PlatformLink to="/manual-setup/#opt-out-of-auto-instrumentation-of-vercel-cron-jobs">Manual Setup</PlatformLink> for more details.

## Job Monitoring

<Include name="javascript-crons-job-monitoring.mdx" />

## Check-Ins

<Include name="javascript-crons-checkins.mdx" />
9 changes: 9 additions & 0 deletions src/platform-includes/crons/setup/javascript.remix.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Cron monitoring is only supported in Remix server-side

## Job Monitoring (Recommended)

<Include name="javascript-crons-job-monitoring.mdx" />

## Check-Ins

<Include name="javascript-crons-checkins.mdx" />
9 changes: 9 additions & 0 deletions src/platform-includes/crons/setup/javascript.sveltekit.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Cron monitoring is only supported in SvelteKit server-side

## Job Monitoring (Recommended)

<Include name="javascript-crons-job-monitoring.mdx" />

## Check-Ins

<Include name="javascript-crons-checkins.mdx" />
6 changes: 5 additions & 1 deletion src/platform-includes/crons/setup/node.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Check-Ins (Recommended)
## Job Monitoring (Recommended)

<Include name="javascript-crons-job-monitoring.mdx" />

## Check-Ins

<Include name="javascript-crons-checkins.mdx" />
6 changes: 4 additions & 2 deletions src/platforms/common/crons/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ supported:
- javascript.nextjs
- javascript.sveltekit
- javascript.remix
- javascript.astro
- javascript.bun
- go
- ruby
description: "Learn how to enable Cron Monitoring in your app"
Expand All @@ -18,7 +20,7 @@ description: "Learn how to enable Cron Monitoring in your app"

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

<PlatformSection supported={["python", "php", "node", "javascript.nextjs", "javascript.sveltekit", "javascript.remix", "go", "java", "ruby"]}>
<PlatformSection supported={["python", "php", "node", "javascript.nextjs", "javascript.sveltekit", "javascript.remix", "javascript.astro", "javascript.bun", "go", "java", "ruby"]}>

## Requirements

Expand All @@ -38,7 +40,7 @@ To link any exceptions captured during your job's lifecycle, use <PlatformLink t

</PlatformSection>

<PlatformSection notSupported={["python", "php", "node", "javascript.nextjs", "javascript.sveltekit", "javascript.remix", "go", "java", "ruby"]}>
<PlatformSection notSupported={["python", "php", "node", "javascript.nextjs", "javascript.sveltekit", "javascript.remix", "javascript.astro", "javascript.bun", "go", "java", "ruby"]}>

## Requirements

Expand Down