Skip to content

Commit e9dc064

Browse files
feat(crons): Add missing .NET docs (#15697)
- Adds upsert docs - Adds Heartbeat docs
1 parent ff09ab4 commit e9dc064

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

platform-includes/crons/setup/dotnet.mdx

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,88 @@ If your job execution fails, you can notify Sentry about the failure:
1818
// 🔴 Notify Sentry your job has failed:
1919
SentrySdk.CaptureCheckIn("<monitor-slug>", CheckInStatus.Error, checkInId);
2020
```
21+
22+
## Heartbeat
23+
24+
Heartbeat monitoring notifies Sentry of a job's status through one check-in. This setup will only notify you if your job didn't run when expected (missed). If you want to monitor job timeouts, use the `InProgress` check-ins as indicated in the previous section.
25+
26+
```csharp
27+
// Execute your scheduled task...
28+
29+
// 🟢 Notify Sentry your job completed successfully:
30+
SentrySdk.CaptureCheckIn(
31+
"<monitor-slug>",
32+
CheckInStatus.Ok,
33+
// Optionally annotate the check-in with the job duration
34+
duration: TimeSpan.FromSeconds(10)
35+
);
36+
```
37+
38+
If your job execution fails, you can:
39+
40+
```csharp
41+
// 🔴 Notify Sentry your job has failed:
42+
SentrySdk.CaptureCheckIn(
43+
"<monitor-slug>",
44+
CheckInStatus.Error,
45+
duration: TimeSpan.FromSeconds(10)
46+
);
47+
```
48+
49+
## Upserting Cron Monitors
50+
51+
You can create and update your Monitors programmatically with code
52+
rather than [creating and configuring them in Sentry.io](https://sentry.io/issues/alerts/new/crons/).
53+
54+
```csharp
55+
// 🟡 Notify Sentry your job is running:
56+
var checkInId = SentrySdk.CaptureCheckIn(
57+
"<monitor-slug>",
58+
CheckInStatus.InProgress,
59+
configureMonitorOptions: options =>
60+
{
61+
// Use a crontab schedule (every 10 minutes)
62+
options.Interval("*/10 * * * *");
63+
options.CheckInMargin = TimeSpan.FromMinutes(5);
64+
options.MaxRuntime = TimeSpan.FromMinutes(15);
65+
options.TimeZone = "Europe/Vienna";
66+
options.FailureIssueThreshold = 2;
67+
options.RecoveryThreshold = 5;
68+
});
69+
70+
// Execute your scheduled task here...
71+
72+
// 🟢 Notify Sentry your job has completed successfully:
73+
SentrySdk.CaptureCheckIn("<monitor-slug>", CheckInStatus.Ok, checkInId);
74+
```
75+
76+
Alternatively, you can use an interval schedule:
77+
78+
```csharp
79+
// 🟡 Notify Sentry your job is running:
80+
var checkInId = SentrySdk.CaptureCheckIn(
81+
"<monitor-slug>",
82+
CheckInStatus.InProgress,
83+
configureMonitorOptions: options =>
84+
{
85+
// Use an interval schedule (every 10 minutes)
86+
options.Interval(10, SentryMonitorInterval.Minute);
87+
options.CheckInMargin = TimeSpan.FromMinutes(5);
88+
options.MaxRuntime = TimeSpan.FromMinutes(15);
89+
options.TimeZone = "Europe/Vienna";
90+
});
91+
92+
// Execute your scheduled task here...
93+
94+
// 🟢 Notify Sentry your job has completed successfully:
95+
SentrySdk.CaptureCheckIn("<monitor-slug>", CheckInStatus.Ok, checkInId);
96+
```
97+
98+
Supported units are:
99+
100+
- `SentryMonitorInterval.Minute`
101+
- `SentryMonitorInterval.Hour`
102+
- `SentryMonitorInterval.Day`
103+
- `SentryMonitorInterval.Week`
104+
- `SentryMonitorInterval.Month`
105+
- `SentryMonitorInterval.Year`

0 commit comments

Comments
 (0)