Skip to content

Commit

Permalink
Call the Sidekiq Reporter from the Rails error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nikz committed Jul 24, 2024
1 parent 676878f commit 46bfb2a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/raygun/error_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def report(error, handled:, severity:, context:, source: nil)
tags: ["rails_error_reporter", *tags].compact
}

Raygun.track_exception(error, data)
if source == "job.sidekiq" && defined?(Sidekiq)
Raygun::SidekiqReporter.call(error, data)
else
Raygun.track_exception(error, data)
end
end
end
22 changes: 22 additions & 0 deletions test/unit/sidekiq_failure_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,26 @@ def test_we_are_in_sidekiqs_list_of_error_handlers
assert error_handlers.include?(Raygun::SidekiqReporter)
end

def test_rails_error_reporter_uses_sidekiq_reporter
WebMock.reset!

tagged_request = stub_request(:post, 'https://api.raygun.com/entries').
with(body: /"sidekiq"/). # should have a sidekiq tag!
to_return(status: 202)

error = StandardError.new("Oh no! Your Sidekiq has failed!")

response = Raygun::ErrorSubscriber.new.report(
error,
handled: true,
severity: "error",
context: { sidekick_name: "robin" },
source: "job.sidekiq"
)

assert response && response.success?, "Expected success, got #{response.class}: #{response.inspect}"

assert_requested tagged_request
end

end

0 comments on commit 46bfb2a

Please sign in to comment.