-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from nikz/support-rails-error-handle
Adds support for Rails' new error handling API
- Loading branch information
Showing
13 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Subscribes to errors using Rails' error reporting API | ||
# https://edgeguides.rubyonrails.org/error_reporting.html | ||
class Raygun::ErrorSubscriber | ||
def report(error, handled:, severity:, context:, source: nil) | ||
tags = context.delete(:tags) if context.is_a?(Hash) | ||
|
||
data = { | ||
custom_data: { | ||
"rails.error": { | ||
handled: handled, | ||
severity: severity, | ||
context: context, | ||
source: source | ||
}, | ||
}, | ||
tags: ["rails_error_reporter", *tags].compact | ||
} | ||
|
||
Raygun.track_exception(error, data) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ENV['RAILS_ENV'] ||= 'test' | ||
require "rails" | ||
|
||
major_minor_patch = Rails::VERSION::STRING.split(".").first(3).join(".") | ||
|
||
require_relative "../spec/rails_applications/#{major_minor_patch}/config/environment" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require_relative "../test_helper.rb" | ||
|
||
class ErrorSubscriberTest < Raygun::UnitTest | ||
|
||
def setup | ||
super | ||
Raygun.configuration.send_in_background = false | ||
end | ||
|
||
|
||
def test_tracking_exception_via_subscriber | ||
body_matcher = lambda do |body| | ||
json = JSON.parse(body) | ||
details = json["details"] | ||
|
||
details["userCustomData"] && | ||
details["userCustomData"]["rails.error"] && | ||
details["userCustomData"]["rails.error"]["handled"] == true && | ||
details["tags"] == ["rails_error_reporter", "test_tag", "test"] | ||
end | ||
|
||
request_stub = stub_request(:post, 'https://api.raygun.com/entries') | ||
.with( | ||
body: body_matcher | ||
) | ||
.to_return(status: 202).times(1) | ||
|
||
result = Raygun::ErrorSubscriber.new.report( | ||
StandardError.new("test error"), | ||
handled: true, | ||
severity: "warning", | ||
context: { | ||
tags: ["test_tag"] | ||
}, | ||
source: "application" | ||
) | ||
|
||
assert result && result.success?, "Expected success, got #{result.class}, #{result.inspect}" | ||
|
||
assert_requested request_stub | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters