Skip to content

Commit 0e122f4

Browse files
committed
fix(ruby): Keep running the job when scope data cannot be applied
hook_hash only coerces the top-level value scope_data returns, and apply_scope_data ran outside safely. A tags, extra, user or context value that is not a Hash made the Scope setters raise ArgumentError from start_job, so the job never ran. Apply the scope data through safely, as the other hooks are, so the failure is logged and the job runs.
1 parent a6b58ce commit 0e122f4

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎sentry-ruby/lib/sentry/job_extensions/extension.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def instrument_enqueue(job:, **context, &enqueue)
6868
# @param job [Object]
6969
# @return [Transaction, nil]
7070
def start_job(scope:, job:, **context)
71-
apply_scope_data(scope, hook_hash("collect the scope data") { scope_data(job: job, **context) })
71+
data = hook_hash("collect the scope data") { scope_data(job: job, **context) }
72+
safely("apply the scope data") { apply_scope_data(scope, data) }
7273

7374
job_name = safely("name the transaction") { transaction_name(job: job, **context) }
7475
scope.set_transaction_name(job_name, source: :task) if job_name

‎sentry-ruby/spec/sentry/job_extensions/extension_spec.rb‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ def capture(extension, **options)
277277
expect(string_io.string).to include("Job extension :test_backend failed to collect the messaging data")
278278
end
279279

280+
it "starts the transaction and logs the failure when scope data holds values that are not Hashes" do
281+
extension = build_extension(scope_data: ->(**) { { contexts: { backend: nil }, tags: "low" } })
282+
283+
event = finished_job(extension)
284+
285+
expect(event.contexts.dig(:trace, :op)).to eq("queue.process")
286+
expect(string_io.string).to include("Job extension :test_backend failed to apply the scope data")
287+
end
288+
280289
it "continues the trace described by the extracted trace headers" do
281290
transaction = tracing_extension.start_job(scope: scope, job: job, trace_headers: foreign_trace_headers)
282291

0 commit comments

Comments
 (0)