Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Configuration#use_exception_level_filters option #588

Merged
merged 2 commits into from
May 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ installed, uses `girl_friday`, otherwise defaults to `Thread`.
When `true` indicates you wish to send data to Rollbar with `eventmachine`.
Won't work unless `eventmachine` is installed.

### use_exception_level_filters_default

**Default** `false`

When `true` the notifier will use the `exception_level_filters` when reporting. It can be overriden using `:use_exception_level_filters` option. see [Exception level filters](https://github.com/rollbar/rollbar-gem#exception-level-filters)

### web_base

**Default** `'https://rollbar.com'`
Expand Down
2 changes: 2 additions & 0 deletions lib/rollbar/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Configuration
attr_accessor :web_base
attr_accessor :write_to_file
attr_reader :send_extra_frame_data
attr_accessor :use_exception_level_filters_default

attr_reader :project_gem_paths

Expand Down Expand Up @@ -116,6 +117,7 @@ def initialize
@write_to_file = false
@send_extra_frame_data = :none
@project_gem_paths = []
@use_exception_level_filters_default = false
end

def initialize_copy(orig)
Expand Down
10 changes: 9 additions & 1 deletion lib/rollbar/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def log(level, *args)
return 'disabled' unless configuration.enabled

message, exception, extra = extract_arguments(args)
use_exception_level_filters = extra && extra.delete(:use_exception_level_filters) == true
use_exception_level_filters = use_exception_level_filters?(extra)

return 'ignored' if ignored?(exception, use_exception_level_filters)

Expand Down Expand Up @@ -291,6 +291,14 @@ def send_failsafe(message, exception, uuid = nil, host = nil)

private

def use_exception_level_filters?(options)
option_value = options && options.delete(:use_exception_level_filters)

return option_value unless option_value.nil?

configuration.use_exception_level_filters_default
end

def call_before_process(options)
options = {
:level => options[:level],
Expand Down
76 changes: 76 additions & 0 deletions spec/rollbar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,82 @@
Rollbar.error(exception).should == 'disabled'
end

context 'using configuration.use_exception_level_filters_default' do
before do
Rollbar.configure do |config|
config.use_exception_level_filters_default = true
end
end

context 'without use_exception_level_filters argument' do
it 'sends the correct filtered level' do
Rollbar.configure do |config|
config.exception_level_filters = { 'NameError' => 'warning' }
end

Rollbar.error(exception)

expect(Rollbar.last_report[:level]).to be_eql('warning')
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a test when config.use_exception_level_filters_default = true has been set, and when :use_exception_level_filters => false is passed in with the Rollbar.error call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added one

it 'ignore ignored exception classes' do
Rollbar.configure do |config|
config.exception_level_filters = { 'NameError' => 'ignore' }
end

logger_mock.should_not_receive(:info)
logger_mock.should_not_receive(:warn)
logger_mock.should_not_receive(:error)

Rollbar.error(exception)
end
end
end

context 'using :use_exception_level_filters option as true' do
it 'sends the correct filtered level' do
Rollbar.configure do |config|
config.exception_level_filters = { 'NameError' => 'warning' }
end

Rollbar.error(exception, :use_exception_level_filters => true)
expect(Rollbar.last_report[:level]).to be_eql('warning')
end

it 'ignore ignored exception classes' do
Rollbar.configure do |config|
config.exception_level_filters = { 'NameError' => 'ignore' }
end

logger_mock.should_not_receive(:info)
logger_mock.should_not_receive(:warn)
logger_mock.should_not_receive(:error)

Rollbar.error(exception, :use_exception_level_filters => true)
end

context 'using :use_exception_level_filters option as false' do
it 'sends the correct filtered level' do
Rollbar.configure do |config|
config.exception_level_filters = { 'NameError' => 'warning' }
end

Rollbar.error(exception, :use_exception_level_filters => false)
expect(Rollbar.last_report[:level]).to be_eql('error')
end

it 'ignore ignored exception classes' do
Rollbar.configure do |config|
config.exception_level_filters = { 'NameError' => 'ignore' }
end

Rollbar.error(exception, :use_exception_level_filters => false)

expect(Rollbar.last_report[:level]).to be_eql('error')
end
end
end

context 'using :use_exception_level_filters option as true' do
it 'sends the correct filtered level' do
Rollbar.configure do |config|
Expand Down