-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add documentation for Crons in Elixir #9305
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
title: Set Up Crons | ||
description: "Learn how to enable Cron Monitoring in your app" | ||
sidebar_order: 5000 | ||
--- | ||
|
||
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. | ||
|
||
## Requirements | ||
|
||
<PlatformContent includePath="crons/requirements" /> | ||
|
||
<PlatformContent includePath="crons/setup" /> | ||
|
||
## Alerts | ||
|
||
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. | ||
|
||
To receive alerts about these events: | ||
|
||
1. Navigate to **Alerts** in the sidebar. | ||
2. Create a new alert and select "Issues" under "Errors" as the alert type. | ||
3. Configure your alert and define a filter match to use: `The event's tags match {key} {match} {value}`. | ||
|
||
Example: `The event's tags match monitor.slug equals my-monitor-slug-here` | ||
|
||
 | ||
|
||
Learn more in [Issue Alert Configuration](/product/alerts/create-alerts/issue-alert-config/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: Troubleshooting | ||
description: "Learn how to troubleshoot your Cron Monitoring setup." | ||
sidebar_order: 500 | ||
--- | ||
|
||
<PlatformContent includePath="crons/troubleshooting" /> | ||
|
||
### Why Aren't Recurring Job Errors Showing Up on My Monitor Details Page? | ||
|
||
You may not have <PlatformLink to="/crons/#connecting-errors-to-cron-monitors">linked errors to your monitor</PlatformLink>. | ||
|
||
### Why Am I Not Receiving Alerts When My Monitor Fails? | ||
|
||
You may not have <PlatformLink to="/crons/#alerts">set up alerts for your monitor</PlatformLink>. | ||
|
||
### What Is the Crons Data Retention Policy for Check-ins and Attachments? | ||
|
||
Our current data retention policy is 90 days. | ||
|
||
### Do You Support a Monitor Schedule With a Six-field Crontab Expression? | ||
|
||
Currently, we only support crontab expressions with five fields. | ||
|
||
Still having trouble? Reach out to [[email protected]](mailto:[email protected]). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Elixir SDK (min v10.2.0) for your recurring job. | ||
- [Create and configure](https://sentry.io/crons/create/) your first monitor. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
## Job Monitoring | ||
|
||
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: | ||
|
||
```elixir | ||
config :sentry, | ||
integrations: [ | ||
oban: [cron: [enabled: true]], | ||
# Or for Quantum: | ||
quantum: [cron: [enabled: true]], | ||
] | ||
``` | ||
|
||
## Manual Setup | ||
|
||
If you're using another library or a custom solution for scheduling jobs, you'll need to instrument those jobs manually. | ||
|
||
### 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). | ||
|
||
```elixir | ||
{:ok, check_in_id} = Sentry.capture_check_in(status: :in_progress, monitor_slug: "<monitor-slug>") | ||
|
||
# Execute your scheduled task here | ||
my_scheduled_job() | ||
|
||
Sentry.capture_check_in(check_in_id: check_in_id, status: :ok, monitor_slug: "<monitor-slug>") | ||
``` | ||
|
||
If your job execution fails, you can notify Sentry about the failure: | ||
|
||
```elixir | ||
Sentry.capture_check_in(check_in_id: check_in_id, status: :error, monitor_slug: "<monitor-slug>") | ||
``` | ||
|
||
### Heartbeats | ||
|
||
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. | ||
|
||
```elixir | ||
Sentry.capture_check_in(status: :ok, monitor_slug: "<monitor-slug>") | ||
``` | ||
|
||
If your job execution fails, you can notify Sentry about the failure: | ||
|
||
```elixir | ||
Sentry.capture_check_in(status: :error, monitor_slug: "<monitor-slug>") | ||
``` | ||
|
||
## Upserting Cron Monitors | ||
|
||
You can create and update your monitors programmatically with code rather than [creating and configuring them in Sentry](https://sentry.io/crons/create/). | ||
|
||
To do that, you need to pass a `:monitor_config` set of options to `Sentry.capture_check_in/3`: | ||
|
||
```elixir | ||
# Create a config from a crontab schedule (every 10 minutes) | ||
monitor_config = [ | ||
schedule: [ | ||
type: :crontab, | ||
value: "5 * * * *", | ||
], | ||
checkin_margin: 5, # Optional check-in margin in minutes | ||
max_runtime: 15, # Optional max runtime in minutes | ||
timezone: "Europe/Vienna", # Optional timezone | ||
] | ||
|
||
# Alternatively, create a config from an interval schedule (every 10 minutes in this case): | ||
monitor_config = [ | ||
schedule: [ | ||
type: :interval, | ||
unit: :minute, | ||
value: 10 | ||
], | ||
checkin_margin: 5, # Optional check-in margin in minutes | ||
max_runtime: 15, # Optional max runtime in minutes | ||
timezone: "Europe/Vienna", # Optional timezone | ||
] | ||
|
||
# Notify Sentry your job is running: | ||
{:ok, check_in_id} = | ||
Sentry.capture_check_in( | ||
status: :in_progress, | ||
monitor_slug: "<monitor-slug>", | ||
monitor_config: monitor_config | ||
) | ||
|
||
# Execute your job: | ||
execute_job() | ||
|
||
# Notify Sentry your job has completed successfully: | ||
Sentry.capture_check_in( | ||
status: :ok, | ||
check_in_id: check_in_id, | ||
monitor_slug: "<monitor-slug>", | ||
monitor_config: monitor_config | ||
) | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Elixir SDK yet. For now, you can use the [check-in attachments API](/product/crons/getting-started/http/#check-in-attachment-optional). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.