Skip to content

Commit f82c68c

Browse files
authored
Add documentation for Crons in Elixir (#9305)
1 parent e867d6d commit f82c68c

File tree

6 files changed

+159
-0
lines changed

6 files changed

+159
-0
lines changed

docs/platforms/elixir/crons/index.mdx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Set Up Crons
3+
description: "Learn how to enable Cron Monitoring in your app"
4+
sidebar_order: 5000
5+
---
6+
7+
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.
8+
9+
## Requirements
10+
11+
<PlatformContent includePath="crons/requirements" />
12+
13+
<PlatformContent includePath="crons/setup" />
14+
15+
## Alerts
16+
17+
When your recurring job fails to check in (missed), runs beyond its configured maximum runtime (failed), or manually reports a failure, Sentry will create an error event with a tag connected to your monitor.
18+
19+
To receive alerts about these events:
20+
21+
1. Navigate to **Alerts** in the sidebar.
22+
2. Create a new alert and select "Issues" under "Errors" as the alert type.
23+
3. Configure your alert and define a filter match to use: `The event's tags match {key} {match} {value}`.
24+
25+
Example: `The event's tags match monitor.slug equals my-monitor-slug-here`
26+
27+
![Cron completed alert filter](/platforms/ruby/common/crons/crons-alerts-example.png)
28+
29+
Learn more in [Issue Alert Configuration](/product/alerts/create-alerts/issue-alert-config/).
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Troubleshooting
3+
description: "Learn how to troubleshoot your Cron Monitoring setup."
4+
sidebar_order: 500
5+
---
6+
7+
<PlatformContent includePath="crons/troubleshooting" />
8+
9+
### Why Aren't Recurring Job Errors Showing Up on My Monitor Details Page?
10+
11+
You may not have <PlatformLink to="/crons/#connecting-errors-to-cron-monitors">linked errors to your monitor</PlatformLink>.
12+
13+
### Why Am I Not Receiving Alerts When My Monitor Fails?
14+
15+
You may not have <PlatformLink to="/crons/#alerts">set up alerts for your monitor</PlatformLink>.
16+
17+
### What Is the Crons Data Retention Policy for Check-ins and Attachments?
18+
19+
Our current data retention policy is 90 days.
20+
21+
### Do You Support a Monitor Schedule With a Six-field Crontab Expression?
22+
23+
Currently, we only support crontab expressions with five fields.
24+
25+
Still having trouble? Reach out to [crons-feedback@sentry.io](mailto:crons-feedback@sentry.io).

docs/product/crons/getting-started/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ To set up Sentry Crons, use the links below for supported SDKs or the Sentry CLI
2020
- [Java](/platforms/java/crons/)
2121
- [Spring Boot](/platforms/java/guides/spring-boot/crons/)
2222
- [Ruby](/platforms/ruby/crons/)
23+
- [Elixir](/platforms/elixir/crons/)
2324

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Use our <PlatformLink to="/">getting started</PlatformLink> guide to install and configure the Sentry Elixir SDK (min v10.2.0) for your recurring job.
2+
- [Create and configure](https://sentry.io/crons/create/) your first monitor.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
## Job Monitoring
2+
3+
If you're using [Oban](https://github.com/sorentwo/oban) or [Quantum](https://github.com/quantum-elixir/quantum-core), Sentry can automatically capture check-ins for all jobs that are scheduled to run periodically. To achieve this, you need to enable the corresponding Sentry plugin:
4+
5+
```elixir
6+
config :sentry,
7+
integrations: [
8+
oban: [cron: [enabled: true]],
9+
# Or for Quantum:
10+
quantum: [cron: [enabled: true]],
11+
]
12+
```
13+
14+
## Manual Setup
15+
16+
If you're using another library or a custom solution for scheduling jobs, you'll need to instrument those jobs manually.
17+
18+
### Check-Ins (Recommended)
19+
20+
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).
21+
22+
```elixir
23+
{:ok, check_in_id} = Sentry.capture_check_in(status: :in_progress, monitor_slug: "<monitor-slug>")
24+
25+
# Execute your scheduled task here
26+
my_scheduled_job()
27+
28+
Sentry.capture_check_in(check_in_id: check_in_id, status: :ok, monitor_slug: "<monitor-slug>")
29+
```
30+
31+
If your job execution fails, you can notify Sentry about the failure:
32+
33+
```elixir
34+
Sentry.capture_check_in(check_in_id: check_in_id, status: :error, monitor_slug: "<monitor-slug>")
35+
```
36+
37+
### Heartbeats
38+
39+
Heartbeat monitoring notifies Sentry of a job's status through _a single 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.
40+
41+
```elixir
42+
Sentry.capture_check_in(status: :ok, monitor_slug: "<monitor-slug>")
43+
```
44+
45+
If your job execution fails, you can notify Sentry about the failure:
46+
47+
```elixir
48+
Sentry.capture_check_in(status: :error, monitor_slug: "<monitor-slug>")
49+
```
50+
51+
## Upserting Cron Monitors
52+
53+
You can create and update your monitors programmatically with code rather than [creating and configuring them in Sentry](https://sentry.io/crons/create/).
54+
55+
To do that, you need to pass a `:monitor_config` set of options to `Sentry.capture_check_in/3`:
56+
57+
```elixir
58+
# Create a config from a crontab schedule (every 10 minutes)
59+
monitor_config = [
60+
schedule: [
61+
type: :crontab,
62+
value: "5 * * * *",
63+
],
64+
checkin_margin: 5, # Optional check-in margin in minutes
65+
max_runtime: 15, # Optional max runtime in minutes
66+
timezone: "Europe/Vienna", # Optional timezone
67+
]
68+
69+
# Alternatively, create a config from an interval schedule (every 10 minutes in this case):
70+
monitor_config = [
71+
schedule: [
72+
type: :interval,
73+
unit: :minute,
74+
value: 10
75+
],
76+
checkin_margin: 5, # Optional check-in margin in minutes
77+
max_runtime: 15, # Optional max runtime in minutes
78+
timezone: "Europe/Vienna", # Optional timezone
79+
]
80+
81+
# Notify Sentry your job is running:
82+
{:ok, check_in_id} =
83+
Sentry.capture_check_in(
84+
status: :in_progress,
85+
monitor_slug: "<monitor-slug>",
86+
monitor_config: monitor_config
87+
)
88+
89+
# Execute your job:
90+
execute_job()
91+
92+
# Notify Sentry your job has completed successfully:
93+
Sentry.capture_check_in(
94+
status: :ok,
95+
check_in_id: check_in_id,
96+
monitor_slug: "<monitor-slug>",
97+
monitor_config: monitor_config
98+
)
99+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### How Do I Send an Attachment With a Check-in (Such as a Log Output)?
2+
3+
Attachments aren't supported by our Elixir SDK yet. For now, you can use the [check-in attachments API](/product/crons/getting-started/http/#check-in-attachment-optional).

0 commit comments

Comments
 (0)