From d2457c81d3e5a702ea52b9b5edfedc3d0f0a7778 Mon Sep 17 00:00:00 2001 From: st0012 Date: Wed, 5 Jan 2022 10:09:31 +0000 Subject: [PATCH] Correctly return Job#perform's return value --- sentry-rails/lib/sentry/rails/active_job.rb | 4 +++- sentry-rails/spec/sentry/rails/activejob_spec.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sentry-rails/lib/sentry/rails/active_job.rb b/sentry-rails/lib/sentry/rails/active_job.rb index 76e5fdedf..c83ae8b0c 100644 --- a/sentry-rails/lib/sentry/rails/active_job.rb +++ b/sentry-rails/lib/sentry/rails/active_job.rb @@ -24,9 +24,11 @@ def capture_and_reraise_with_sentry(scope, &block) scope.set_span(transaction) if transaction - block.call + return_value = block.call finish_sentry_transaction(transaction, 200) + + return_value rescue Exception => e # rubocop:disable Lint/RescueException finish_sentry_transaction(transaction, 500) diff --git a/sentry-rails/spec/sentry/rails/activejob_spec.rb b/sentry-rails/spec/sentry/rails/activejob_spec.rb index f1c43c009..cfbfb1663 100644 --- a/sentry-rails/spec/sentry/rails/activejob_spec.rb +++ b/sentry-rails/spec/sentry/rails/activejob_spec.rb @@ -1,6 +1,12 @@ require "spec_helper" require "active_job/railtie" +class NormalJob < ActiveJob::Base + def perform + "foo" + end +end + class FailedJob < ActiveJob::Base self.logger = nil @@ -47,6 +53,10 @@ def rescue_callback(error) it "runs job" do expect { FailedJob.perform_now }.to raise_error(FailedJob::TestError) end + + it "returns #perform method's return value" do + expect(NormalJob.perform_now).to eq("foo") + end end RSpec.describe "ActiveJob integration" do @@ -62,6 +72,10 @@ def rescue_callback(error) Sentry.get_current_client.transport end + it "returns #perform method's return value" do + expect(NormalJob.perform_now).to eq("foo") + end + it "adds useful context to extra" do expect { FailedJob.perform_now }.to raise_error(FailedJob::TestError)