From 75f0ffd8c5b4ff4132f19bfe70d78e0e65867ea0 Mon Sep 17 00:00:00 2001 From: Skip Baney Date: Fri, 9 Aug 2013 12:57:32 -0500 Subject: [PATCH 1/3] support custom logger value --- README.md | 3 +++ lib/resque/failure/sentry.rb | 15 ++++++++++++++- spec/sentry_spec.rb | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 680233c..9364a85 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ Add the following to an initializer: ```ruby require 'resque-sentry' +# [optional] custom logger value to use when sending to Sentry (default is 'root') +Resque::Failure::Sentry.logger = "resque" + Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Sentry] Resque::Failure.backend = Resque::Failure::Multiple ``` diff --git a/lib/resque/failure/sentry.rb b/lib/resque/failure/sentry.rb index 5c7e850..f262e86 100644 --- a/lib/resque/failure/sentry.rb +++ b/lib/resque/failure/sentry.rb @@ -16,8 +16,21 @@ module Failure # Resque::Failure.backend = Resque::Failure::Multiple # class Sentry < Base + + @@logger = nil + + def self.logger + @@logger + end + + def self.logger=(value) + @@logger = value + end + def save - Raven.capture_exception(exception) + options = {} + options[:logger] = self.class.logger if self.class.logger + Raven.capture_exception(exception, options) end def self.count diff --git a/spec/sentry_spec.rb b/spec/sentry_spec.rb index 9d7fa13..106f49a 100644 --- a/spec/sentry_spec.rb +++ b/spec/sentry_spec.rb @@ -2,16 +2,30 @@ describe Resque::Failure::Sentry do it "sends errors to Sentry" do + sentry_options = {} exception = StandardError.new("Test Error") worker = Resque::Worker.new(:test) queue = "test" payload = {'class' => Object, 'args' => 1} event = mock - Raven.expects(:capture_exception).with(exception) + Raven.expects(:capture_exception).with(exception, sentry_options) backend = Resque::Failure::Sentry.new(exception, worker, queue, payload) backend.save end + + it "will use the configured Sentry logger" do + Resque::Failure::Sentry.logger = "resque" + sentry_options = { :logger => "resque" } + exception = StandardError.new("Test Error") + worker = Resque::Worker.new(:test) + queue = "test" + payload = {'class' => Object, 'args' => 1} + + Raven.expects(:capture_exception).with(exception, sentry_options) + backend = Resque::Failure::Sentry.new(exception, worker, queue, payload) + backend.save + end end From ea723c413f06e7907be91b74a64042aeac80e07c Mon Sep 17 00:00:00 2001 From: Skip Baney Date: Fri, 9 Aug 2013 12:58:55 -0500 Subject: [PATCH 2/3] support running against current sentry-raven --- resque-sentry.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resque-sentry.gemspec b/resque-sentry.gemspec index 847bb78..a6ba8c1 100644 --- a/resque-sentry.gemspec +++ b/resque-sentry.gemspec @@ -7,7 +7,7 @@ Gem::Specification.new do |gem| gem.homepage = 'https://github.com/gocardless/resque-sentry' gem.add_dependency 'resque', '>= 1.18.0' - gem.add_dependency 'sentry-raven', '~> 0.4.6' + gem.add_dependency 'sentry-raven', '>= 0.4.6' gem.add_development_dependency 'rspec', '~> 2.6' gem.add_development_dependency 'mocha', '~> 0.11.0' From 122db0447fac75ccebbe1d5b28bd59fda123e1a4 Mon Sep 17 00:00:00 2001 From: Skip Baney Date: Tue, 13 Aug 2013 14:20:00 -0500 Subject: [PATCH 3/3] use class ivar --- lib/resque/failure/sentry.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/resque/failure/sentry.rb b/lib/resque/failure/sentry.rb index f262e86..7b3a015 100644 --- a/lib/resque/failure/sentry.rb +++ b/lib/resque/failure/sentry.rb @@ -17,14 +17,12 @@ module Failure # class Sentry < Base - @@logger = nil - def self.logger - @@logger + @logger end def self.logger=(value) - @@logger = value + @logger = value end def save