Skip to content

Commit

Permalink
Merge pull request #109 from MindscapeHQ/log-skip-reporting-reason
Browse files Browse the repository at this point in the history
Log skip reporting reason
  • Loading branch information
UberMouse authored Mar 10, 2017
2 parents dd81789 + 0d626d7 commit 95cd646
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Features:
- Pass a user object as the third parameter to `Raygun.track_exception` to have affected user tracking for manually tracked exceptions, see the above link for more information on configuring this
- If the exception instance responds to `:raygun_custom_data` that method will be called and the return value merged into the `custom_data` hash sent to Raygun. For convenience a `Raygun::Error` class is provided that takes this custom data as a second argument
- Allowed `Configuration.custom_data` to be set to a proc to allow a global custom data hook for all exceptions. It is passed as arguments the exception and the environment hash
- Added `Configuration.debug` to enable logging the reason why an exception was not reported

## 1.2.1 (09/03/2017)

Expand Down
25 changes: 19 additions & 6 deletions lib/raygun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,28 @@ def deprecation_warning(message)

private

def print_api_key_warning
$stderr.puts(NO_API_KEY_MESSAGE)
def print_api_key_warning
$stderr.puts(NO_API_KEY_MESSAGE)
end

def should_report?(exception)
if configuration.silence_reporting
if configuration.debug
log('[Raygun] skipping reporting because Configuration.silence_reporting is enabled')
end

return false
end

def should_report?(exception)
return false if configuration.silence_reporting
return false if configuration.ignore.flatten.include?(exception.class.to_s)
true
if configuration.ignore.flatten.include?(exception.class.to_s)
if configuration.debug
log("[Raygun] skipping reporting of exception #{exception.class} because it is in the ignore list")
end

return false
end

true
end
end
end
6 changes: 5 additions & 1 deletion lib/raygun/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def self.proc_config_option(name)
# Hash of proxy settings - :address, :port (defaults to 80), :username and :password (both default to nil)
config_option :proxy_settings

# Set this to true to have raygun4ruby log the reason why it skips reporting an exception
config_option :debug

# Exception classes to ignore by default
IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
'ActionController::RoutingError',
Expand Down Expand Up @@ -111,7 +114,8 @@ def initialize
filter_parameters: DEFAULT_FILTER_PARAMETERS,
filter_payload_with_whitelist: false,
whitelist_payload_shape: DEFAULT_WHITELIST_PAYLOAD_SHAPE,
proxy_settings: {}
proxy_settings: {},
debug: false
})
end

Expand Down
12 changes: 12 additions & 0 deletions test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ def test_overriding_defaults
assert_equal({ sally: "stegosaurus" }, Raygun.configuration.custom_data)
end

def test_debug
Raygun.setup do |config|
config.debug = true
end

assert_equal Raygun.configuration.debug, true
end

def test_debug_default_set
assert_equal false, Raygun.configuration.debug
end

def test_setting_filter_paramters_to_proc
Raygun.setup do |config|
config.filter_parameters do |hash|
Expand Down
42 changes: 42 additions & 0 deletions test/unit/raygun_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,51 @@
require_relative "../test_helper.rb"
require 'stringio'

class FakeLogger
def initialize
@logger = StringIO.new
end

def info(message)
@logger.write(message)
end

def reset
@logger.string = ""
end

def get
@logger.string
end
end

class RaygunTest < Raygun::UnitTest
def test_raygun_is_not_configured_with_no_api_key
Raygun.configuration.api_key = nil
assert !Raygun.configured?
end

def test_should_report_logs_silence_reporting_when_debug_is_on
logger = setup_logging
Raygun.configuration.silence_reporting = true
Raygun.send(:should_report?, Exception.new)

assert logger.get.include?("silence_reporting"), "silence_reporting was not logged"
end

def test_should_report_logs_ignored_exceptions_when_debug_is_on
logger = setup_logging
Raygun.configuration.ignore = ["Exception"]
Raygun.send(:should_report?, Exception.new)

assert logger.get =~ /skipping reporting of.*Exception.*/, "ignored exception was not logged"
end

def setup_logging
logger = FakeLogger.new
Raygun.configuration.debug = true
Raygun.configuration.logger = logger

logger
end
end

0 comments on commit 95cd646

Please sign in to comment.