Skip to content

Commit 40df9e1

Browse files
gaprlgetsantry[bot]vivianyentran
authored
Add javascript documentation for Crons upsert (#8723)
* add node.js documentation for crons upsert * [getsentry/action-github-commit] Auto commit * add crons upsert to remaining javascript platforms * Apply copy suggestions from crons upsert code review Co-authored-by: vivianyentran <[email protected]> * [getsentry/action-github-commit] Auto commit * separate crons upsert monitor config in upsert example * [getsentry/action-github-commit] Auto commit * apply additional formatting editing to crons check-ins --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com> Co-authored-by: vivianyentran <[email protected]>
1 parent 5ff4c2a commit 40df9e1

File tree

7 files changed

+174
-0
lines changed

7 files changed

+174
-0
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
You can create and update your Monitors programmatically with code rather than [creating and configuring them in Sentry.io](https://sentry.io/crons/create/).
2+
3+
To create/update a monitor, use `Sentry.withMonitor()` and pass in your monitor configuration as a third parameter:
4+
5+
```javascript
6+
const monitorConfig = {
7+
schedule: {
8+
type: "crontab",
9+
value: "* * * * *",
10+
},
11+
checkinMargin: 2, // In minutes. Optional.
12+
maxRuntime: 10, // In minutes. Optional.
13+
timezone: "America/Los_Angeles", // Optional.
14+
};
15+
16+
Sentry.withMonitor(
17+
"<monitor-slug>",
18+
() => {
19+
// Execute your scheduled task here...
20+
},
21+
monitorConfig
22+
);
23+
```
24+
25+
```typescript
26+
import { MonitorConfig } from "@sentry/types";
27+
28+
const monitorConfig: MonitorConfig = {
29+
schedule: {
30+
type: "crontab",
31+
value: "* * * * *",
32+
},
33+
checkinMargin: 2, // In minutes. Optional.
34+
maxRuntime: 10, // In minutes. Optional.
35+
timezone: "America/Los_Angeles", // Optional.
36+
};
37+
38+
Sentry.withMonitor(
39+
"<monitor-slug>",
40+
() => {
41+
// Execute your scheduled task here...
42+
},
43+
monitorConfig
44+
);
45+
```
46+
47+
To configure the monitor's check-ins, use `Sentry.captureCheckIn()` and pass in your monitor configuration as a second parameter:
48+
49+
```javascript
50+
const monitorConfig = {
51+
schedule: {
52+
type: "crontab",
53+
value: "* * * * *",
54+
},
55+
checkinMargin: 2, // In minutes. Optional.
56+
maxRuntime: 10, // In minutes. Optional.
57+
timezone: "America/Los_Angeles", // Optional.
58+
};
59+
60+
// 🟡 Notify Sentry your job is running:
61+
const checkInId = Sentry.captureCheckIn(
62+
{
63+
monitorSlug: "<monitor-slug>",
64+
status: "in_progress",
65+
},
66+
monitorConfig
67+
);
68+
69+
// Execute your scheduled task here...
70+
71+
// 🟢 Notify Sentry your job has completed successfully:
72+
Sentry.captureCheckIn(
73+
{
74+
// Make sure this variable is named `checkInId`
75+
checkInId,
76+
monitorSlug: "<monitor-slug>",
77+
status: "ok",
78+
},
79+
monitorConfig
80+
);
81+
```
82+
83+
```typescript
84+
import { MonitorConfig } from "@sentry/types";
85+
86+
const monitorConfig: MonitorConfig = {
87+
schedule: {
88+
type: "crontab",
89+
value: "* * * * *",
90+
},
91+
checkinMargin: 2, // In minutes. Optional.
92+
maxRuntime: 10, // In minutes. Optional.
93+
timezone: "America/Los_Angeles", // Optional.
94+
};
95+
96+
// 🟡 Notify Sentry your job is running:
97+
const checkInId = Sentry.captureCheckIn(
98+
{
99+
monitorSlug: "<monitor-slug>",
100+
status: "in_progress",
101+
},
102+
monitorConfig
103+
);
104+
105+
// Execute your scheduled task here...
106+
107+
// 🟢 Notify Sentry your job has completed successfully:
108+
Sentry.captureCheckIn(
109+
{
110+
// Make sure this variable is named `checkInId`
111+
checkInId,
112+
monitorSlug: "<monitor-slug>",
113+
status: "ok",
114+
},
115+
monitorConfig
116+
);
117+
```
118+
119+
### Monitor Configuration Properties
120+
121+
The following are available monitor configuration properties:
122+
123+
`schedule`:
124+
125+
: The job's schedule:
126+
127+
The schedule representation for your monitor, either `crontab` or `interval`. The structure will vary depending on the type:
128+
129+
```json
130+
{"type": "crontab", "value": "0 * * * *"}
131+
{"type": "interval", "value": "2", "unit": "hour"}
132+
```
133+
134+
`checkinMargin`:
135+
136+
: The amount of time (in minutes) Sentry should wait for your check-in before it's considered missed ("grace period"). Optional.
137+
138+
<Note>
139+
140+
We recommend that your check-in margin be less than or equal to your interval.
141+
142+
</Note>
143+
144+
`maxRuntime`:
145+
146+
: The amount of time (in minutes) your job is allowed to run before it's considered failed. Optional.
147+
148+
`timezone`:
149+
150+
: The `tz` where your job is running. This is usually your server's timezone, (such as `America/Los_Angeles`). See [list of tz database time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Optional.

src/platform-includes/crons/setup/javascript.astro.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Cron monitoring is only supported in Astro server-side
77
## Check-Ins
88

99
<Include name="javascript-crons-checkins.mdx" />
10+
11+
## Upserting Cron Monitors
12+
13+
<Include name="javascript-crons-upsert.mdx" />

src/platform-includes/crons/setup/javascript.bun.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
## Check-Ins
66

77
<Include name="javascript-crons-checkins.mdx" />
8+
9+
## Upserting Cron Monitors
10+
11+
<Include name="javascript-crons-upsert.mdx" />

src/platform-includes/crons/setup/javascript.nextjs.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ Set the `automaticVercelMonitors` option to `true` in your Sentry settings in `n
1414
## Check-Ins
1515

1616
<Include name="javascript-crons-checkins.mdx" />
17+
18+
## Upserting Cron Monitors
19+
20+
<Include name="javascript-crons-upsert.mdx" />

src/platform-includes/crons/setup/javascript.remix.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Cron monitoring is only supported in Remix server-side
77
## Check-Ins
88

99
<Include name="javascript-crons-checkins.mdx" />
10+
11+
## Upserting Cron Monitors
12+
13+
<Include name="javascript-crons-upsert.mdx" />

src/platform-includes/crons/setup/javascript.sveltekit.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Cron monitoring is only supported in SvelteKit server-side
77
## Check-Ins
88

99
<Include name="javascript-crons-checkins.mdx" />
10+
11+
## Upserting Cron Monitors
12+
13+
<Include name="javascript-crons-upsert.mdx" />

src/platform-includes/crons/setup/node.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
## Check-Ins
66

77
<Include name="javascript-crons-checkins.mdx" />
8+
9+
## Upserting Cron Monitors
10+
11+
<Include name="javascript-crons-upsert.mdx" />

0 commit comments

Comments
 (0)