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:

  1. Oban version 2.17.6 and up to be a dependency of your application.
  2. 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
Copied
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.

If you want to customize the information that is sent to Sentry when a job checks in, you can do so by providing a function that takes the job and returns a map of metadata.

lib/my_app/my_worker.ex
Copied
defmodule MyApp.MyWorker do
  use Oban.Worker
  
  @behaviour Sentry.Integrations.Oban.Cron
  
  @impl Oban.Worker
  def perform(args) do
    # ...
  end
  
  @impl Sentry.Integrations.Oban.Cron
  def sentry_check_in_configuration(job) do
    [monitor_slug: "custom-slug-#{job.id}"]
  end
end

This is available since v10.9.0 of the SDK.

Was this helpful?
Help improve this content
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").