Connect Delayed Job to Bugsink

The Delayed Job integration reports exceptions from background jobs with the job class, queue, record ID, and worker-side Ruby stack.

This guide adds the integration to an existing Delayed Job worker, runs a job which fails, and checks the result in Bugsink. To follow along, create a Bugsink project and copy its DSN from the project setup page.

Install the SDK

Add the open-source Sentry Ruby and Delayed Job gems to the worker’s bundle. Bugsink accepts the Sentry event protocol, so these SDKs can send job failures directly to your Bugsink project:

bundle add sentry-ruby sentry-delayed_job

Configure your DSN

Initialize the SDK when the worker starts. Requiring sentry-delayed_job installs the Delayed Job lifecycle plugin, while reading the DSN from the environment keeps the project credential out of source control:

require "sentry-delayed_job"

Sentry.init do |config|
  config.dsn = ENV.fetch("SENTRY_DSN")
end

Set SENTRY_DSN to the DSN shown by your Bugsink project when you start the worker:

export SENTRY_DSN=https://key@bugsink.example/1

Load this setup before the worker starts processing jobs. In this small worker, the integration is loaded alongside the database and job class:

require "delayed_job_active_record"
require "database"
require "inventory_sync_job"
require "error_reporting"

Run a job that fails

A job does not need a Bugsink call. When perform raises, the integration reports the exception from Delayed Job’s worker lifecycle and then lets the worker apply its normal failure and retry behavior:

class InventorySyncJob
  INVENTORY = {"coffee" => 12, "tea" => 2}.freeze

  def initialize(sku)
    @sku = sku
  end

  def perform
    return INVENTORY.fetch(@sku) if INVENTORY.key?(@sku)

    raise ProductNotFound, "Product #{@sku} is not in inventory"
  end

  def max_attempts
    1
  end
end

Start your worker normally. For a setup check, the example enqueues an unknown product and asks a worker to process that one job:

bundle exec ruby bin/run-job

The command exits with a failure after Delayed Job records the unsuccessful execution. The example allows one attempt so the deliberate error is not retried.

See the failed job in Bugsink

Open your Bugsink project and select the new ProductNotFound issue. The event points to the worker code and identifies the Delayed Job task which failed.

Bugsink preview

That’s it: failed Delayed Job tasks will now be reported to Bugsink.

The integration also records the job class, queue, record ID, priority, attempt count, and scheduling timestamps. That context lets you connect a Bugsink event to the matching database record and distinguish failures from different worker queues.

Report only the final retry

Retry reporting controls whether a recurring job failure creates an event for every attempt. By default, the integration reports each failed execution. If you only want the last failure after Delayed Job exhausts its retries, enable report_after_job_retries during SDK setup:

Sentry.init do |config|
  config.dsn = ENV.fetch("SENTRY_DSN")
  config.delayed_job.report_after_job_retries = true
end

For handled exceptions, Ruby logging, messages, tags, structured context, and other SDK options, continue with the Ruby guide.