Skip to content

feat(crons): Add Node SDK cron monitoring docs #6842

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 9 commits into from
May 8, 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
1 change: 1 addition & 0 deletions src/docs/product/crons/getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ To set up Sentry Crons, use the links below for supported SDKs or the Sentry CLI
- [Laravel](/platforms/php/guides/laravel/crons/)
- [Python](/platforms/python/crons/)
- [Celery](/platforms/python/guides/celery/crons/)
- [Node](/platforms/node/crons/)

<Alert level="note" title="Don't see your platform?">

Expand Down
7 changes: 7 additions & 0 deletions src/platform-includes/crons/connect-errors/node.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```javascript
Sentry.configureScope(function (scope) {
scope.setContext("monitor", {
slug: "<monitor-slug>",
});
});
```
2 changes: 2 additions & 0 deletions src/platform-includes/crons/requirements/node.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Use our <PlatformLink to="/">getting started</PlatformLink> guide to install and configure the Sentry Node SDK (min v7.51.1) for your recurring job.
- [Create and configure](https://sentry.io/crons/create/) your first Monitor.
55 changes: 55 additions & 0 deletions src/platform-includes/crons/setup/node.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## Check-Ins (Recommended)

Check-in monitoring allows you to track a job's progress by completing two check-ins: one at the start of your job and another at the end of your job. This two-step process allows Sentry to notify you if your job didn't start when expected (missed) or if it exceeded its maximum runtime (failed).

```javascript
// 🟡 Notify Sentry your job is running:
const checkInId = Sentry.captureCheckIn({
monitorSlug: "<monitor-slug>",
status: "in_progress",
});

// Execute your scheduled task here...

// 🟢 Notify Sentry your job has completed successfully:
Sentry.captureCheckIn({
checkInId,
monitorSlug: "<monitor-slug>",
status: "ok",
});
```

If your job execution fails, you can notify Sentry about the failure:

```javascript
// 🔴 Notify Sentry your job has failed:
Sentry.captureCheckIn({
checkInId,
monitorSlug: "<monitor-slug>",
status: "error",
});
```

## Heartbeat

Heartbeat monitoring notifies Sentry of a job's status through one check-in. This setup will only notify you if your job didn't start when expected (missed). If you need to track a job to see if it exceeded its maximum runtime (failed), use check-ins instead.

```javascript
// Execute your scheduled task...

// 🟢 Notify Sentry your job completed successfully:
Sentry.captureCheckIn({
monitorSlug: "<monitor-slug>",
status: "ok",
});
```

If your job execution fails, you can:

```javascript
// 🔴 Notify Sentry your job has failed:
Sentry.captureCheckIn({
monitorSlug: "<monitor-slug>",
status: "error",
});
```
2 changes: 1 addition & 1 deletion src/platform-includes/crons/setup/php.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $event->setCheckIn(new CheckIn(
SentrySdk::getCurrentHub()->captureEvent($event);
```

If your job execution fails, you can do:
If your job execution fails, you can notify Sentry about the failure:

```php
// 🔴 Notify Sentry your job has failed:
Expand Down
3 changes: 3 additions & 0 deletions src/platform-includes/crons/troubleshooting/node.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### How Do I Send an Attachment With a Check-in (Such as a Log Output)?

Attachments aren't supported by our Node SDK yet. For now, you can use the [check-in attachments API](/product/crons/getting-started/http/#check-in-attachment-optional).
Comment on lines +1 to +3
Copy link
Contributor

Choose a reason for hiding this comment

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

This content doesn't appear in the preview.

I think you missed adding <PlatformSection supported={["python", "php", "node"]}>

to src/platforms/common/crons/troubleshooting-crons.mdx

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Fixed with 8a30507

5 changes: 3 additions & 2 deletions src/platforms/common/crons/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ sidebar_order: 5000
supported:
- python
- php
- node
description: "Learn how to enable Cron Monitoring in your app"
---

<Include name="beta-alert-crons.mdx" />

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"]}>
<PlatformSection supported={["python", "php", "node"]}>

## Requirements

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

</PlatformSection>

<PlatformSection notSupported={["python", "php"]}>
<PlatformSection notSupported={["python", "php", "node"]}>

## Requirements

Expand Down
2 changes: 1 addition & 1 deletion src/platforms/common/crons/troubleshooting-crons.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ supported:
description: "Learn how to troubleshoot your Cron Monitoring setup."
---

<PlatformSection supported={["python", "php"]}>
<PlatformSection supported={["python", "php", "node"]}>

<PlatformContent includePath="crons/troubleshooting" />

Expand Down