-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 'literal' Sentry error handler and make it separate from legacy R…
…aven
- Loading branch information
Showing
7 changed files
with
83 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
require 'hutch/logging' | ||
require 'raven' | ||
require 'sentry-ruby' | ||
require 'hutch/error_handlers/base' | ||
|
||
module Hutch | ||
module ErrorHandlers | ||
class Sentry < Base | ||
|
||
def initialize | ||
unless Raven.respond_to?(:capture_exception) | ||
raise "The Hutch Sentry error handler requires Raven >= 0.4.0" | ||
end | ||
end | ||
|
||
def handle(properties, payload, consumer, ex) | ||
message_id = properties.message_id | ||
prefix = "message(#{message_id || '-'}):" | ||
logger.error "#{prefix} Logging event to Sentry" | ||
logger.error "#{prefix} #{ex.class} - #{ex.message}" | ||
Raven.capture_exception(ex, extra: { payload: payload }) | ||
::Sentry.configure_scope do |scope| | ||
scope.set_context("payload", payload) | ||
end | ||
::Sentry.capture_exception(ex) | ||
end | ||
|
||
def handle_setup_exception(ex) | ||
logger.error "Logging setup exception to Sentry" | ||
logger.error "#{ex.class} - #{ex.message}" | ||
Raven.capture_exception(ex) | ||
::Sentry.capture_exception(ex) | ||
end | ||
|
||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'hutch/logging' | ||
require 'raven' | ||
require 'hutch/error_handlers/base' | ||
|
||
module Hutch | ||
module ErrorHandlers | ||
class SentryRaven < Base | ||
|
||
def initialize | ||
unless Raven.respond_to?(:capture_exception) | ||
raise "The Hutch Sentry error handler requires Raven >= 0.4.0" | ||
end | ||
end | ||
|
||
def handle(properties, payload, consumer, ex) | ||
message_id = properties.message_id | ||
prefix = "message(#{message_id || '-'}):" | ||
logger.error "#{prefix} Logging event to Sentry" | ||
logger.error "#{prefix} #{ex.class} - #{ex.message}" | ||
Raven.capture_exception(ex, extra: { payload: payload }) | ||
end | ||
|
||
def handle_setup_exception(ex) | ||
logger.error "Logging setup exception to Sentry" | ||
logger.error "#{ex.class} - #{ex.message}" | ||
Raven.capture_exception(ex) | ||
end | ||
|
||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'spec_helper' | ||
|
||
describe Hutch::ErrorHandlers::SentryRaven do | ||
let(:error_handler) { Hutch::ErrorHandlers::SentryRaven.new } | ||
|
||
describe '#handle' do | ||
let(:properties) { OpenStruct.new(message_id: "1") } | ||
let(:payload) { "{}" } | ||
let(:error) do | ||
begin | ||
raise "Stuff went wrong" | ||
rescue RuntimeError => err | ||
err | ||
end | ||
end | ||
|
||
it "logs the error to Sentry" do | ||
expect(Raven).to receive(:capture_exception).with(error, extra: { payload: payload }) | ||
error_handler.handle(properties, payload, double, error) | ||
end | ||
end | ||
|
||
describe '#handle_setup_exception' do | ||
let(:error) do | ||
begin | ||
raise "Stuff went wrong during setup" | ||
rescue RuntimeError => err | ||
err | ||
end | ||
end | ||
|
||
it "logs the error to Sentry" do | ||
expect(Raven).to receive(:capture_exception).with(error) | ||
error_handler.handle_setup_exception(error) | ||
end | ||
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
4285d16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @Azdaroth . Any chance we can get a new release cut with this? Thanks!