Oban
Sentry supports monitoring scheduled Oban jobs and automatically capturing exceptions.
The Oban integration supports:
- Capturing errors and exceptions that happen in Oban jobs.
- Cron monitoring for scheduled Oban jobs.
This integration is built into the Sentry SDK starting with v10.2.0. It supports automatic monitoring starting with v10.3.0. It requires:
- Oban version 2.17.6 and up to be a dependency of your application.
- Elixir version 1.13 and up, (since that's required by Oban).
You can configure the Oban integration in your Sentry configuration, under the :integrations
key:
config/config.exs
config :sentry,
# ...,
integrations: [
oban: [
# Capture errors:
capture_errors: true,
# Monitor cron jobs:
cron: [enabled: true]
]
]
This configuration will report failed Oban jobs to Sentry. It will also report started, completed, and failed jobs, as well as their duration. It will use the worker name as the monitor_slug
of the reported cron.
Perform Errors
Oban wraps unhandled crashes, exits, and throws in jobs inside Oban.CrashError
exceptions. However, if jobs return errors manually (such as by returning {:error, reason}
tuples) then Oban will wrap those inside Oban.PerformError
exceptions. If you only want to report crashes to Sentry, you can either configure an event filter that doesn't report Oban.PerformError
events, or that inspects its :reason
field to determine whether to report them. For example:
def before_send(event) do
case event.original_exception do
%Oban.PerformError{reason: {:error, reason}} -> event
%Oban.PerformError{} -> nil
_other -> event
end
end
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").