Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from twelvelabs/master
Browse files Browse the repository at this point in the history
Support custom Sentry logger value
  • Loading branch information
hmarr committed Aug 13, 2013
2 parents 29fdf56 + 122db04 commit 98e75c7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
13 changes: 12 additions & 1 deletion lib/resque/failure/sentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ module Failure
# Resque::Failure.backend = Resque::Failure::Multiple
#
class Sentry < Base

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
Expand Down
2 changes: 1 addition & 1 deletion resque-sentry.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
16 changes: 15 additions & 1 deletion spec/sentry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 98e75c7

Please sign in to comment.