Skip to content

feat(ruby): add job extensions and shared instrumentation - #3129

Open
solnic wants to merge 10 commits into
masterfrom
feat/3117-public-backend-extension-registry-for-background-job-integrations
Open

solnic wants to merge 10 commits into
masterfrom
feat/3117-public-backend-extension-registry-for-background-job-integrations

Conversation

@solnic

@solnic solnic commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

This introduces a public API for queue systems (ActiveJob, Sidekiq, GoodJob, SolidQueue etc.) to integrate with Sentry by subclassing Sentry::JobExtensions::Extension:

module MyBackend
  class SentryExtension < Sentry::JobExtensions::Extension
    def initialize
      super(name: "my_backend", integration: MyBackend::SentryIntegration, origin: "auto.queue.my_backend")
    end

    def scope_data(job:, **)
      { tags: { queue: job.queue_name } }
    end

    def messaging_data(job:, **)
      { system: "my_backend", message_id: job.job_id, destination: job.queue_name }
    end
  end
end

Integrations call the extension around enqueueing and performing a job:

extension.instrument_enqueue(job: job) { enqueue }

transaction = extension.start_job(scope: scope, job: job)
# perform the job
extension.finish_job(transaction: transaction, status: 200)

extension.capture_exception(job: job, exception: error) if extension.report_exception?(job: job, exception: error)

These record the queue.publish span and the queue.process transaction, and capture the job's exceptions. The data they record comes from hooks the subclass overrides, such as scope_data, error_data, messaging_data, will_retry?, report_exception?, record_publish_span?, extract_trace_headers, inject_trace_headers, transaction_name and span_origin.

Hooks take keyword arguments and accept keywords they don't read, so integrations can pass extra context. A failing hook is logged and the job runs without its data.


Closes #3117
Closes #3123

@solnic
solnic added this pull request to stack #3135 October 13, 2026 13:17
@solnic
solnic marked this pull request as draft October 13, 2026 13:25
@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch from 120f7a3 to 24621bb Compare October 14, 2026 09:17
@solnic
solnic marked this pull request as ready for review October 14, 2026 09:49
@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch 3 times, most recently from 18edb4c to 605bebc Compare October 14, 2026 11:42
@solnic
solnic removed this pull request from stack #3135 October 14, 2026 11:44
@solnic solnic changed the title feat(ruby): add public backend-extension registry feat(ruby): add job extensions and shared instrumentation Oct 14, 2026
@solnic
solnic added this pull request to stack #3137 October 14, 2026 11:44
cursor[bot]

This comment was marked as resolved.

@solnic
solnic marked this pull request as draft October 15, 2026 08:25
@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch 3 times, most recently from 2cddb72 to 3fa983c Compare October 15, 2026 11:00
@solnic
solnic marked this pull request as ready for review October 15, 2026 12:19
cursor[bot]

This comment was marked as resolved.

@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch 2 times, most recently from 27970e7 to e3ade51 Compare October 15, 2026 12:51
cursor[bot]

This comment was marked as resolved.

@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch from 5eaa1a5 to 77e02b1 Compare October 15, 2026 13:37
@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch 3 times, most recently from 35fb71a to 0df0bb8 Compare October 23, 2026 11:49
@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch from 0df0bb8 to f5eee4a Compare November 2, 2026 15:56
@solnic
solnic marked this pull request as draft November 2, 2026 15:57
@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch 2 times, most recently from 6b133c3 to f5a10e4 Compare November 2, 2026 16:45
Producer, Consumer and Instrumentation are replaced by flow methods on
Extension (instrument_enqueue, start_job, finish_job, capture_exception)
that integrations call and subclasses customize through hooks. Hooks take
keyword arguments and accept keywords they do not read, the capturing
integration and span origin are injected through the constructor, the
retry count travels in the messaging data, and will_retry? replaces
retry_info.
Hook failures are still logged and never stop the enqueue, but whether a
failure of the publish span itself is isolated stays with each
integration, as it does on master.
safely now wraps just the hook calls, and the flow applies their results
outside it. Applying scope data, starting the transaction and capturing
the exception run unguarded, as they do on master.
@solnic
solnic force-pushed the feat/3117-public-backend-extension-registry-for-background-job-integrations branch from a213bfd to 7e7b39b Compare November 3, 2026 12:01
@solnic
solnic marked this pull request as ready for review November 3, 2026 14:29

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7e7b39b. Configure here.

A data hook returning nil or another non-Hash value no longer crashes
the flow outside the guard. nil becomes no data, and any other value is
logged as a hook failure, so the job is still enqueued, performed and
reported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shared queue instrumentation helpers Public backend-extension registry for background job integrations

1 participant