Skip to content

Commit

Permalink
Merge pull request #197 from alphagov/fix-datasync
Browse files Browse the repository at this point in the history
Fix the new `before_send` behaviour & tests, and add documentation
  • Loading branch information
ChrisBAshton authored May 21, 2021
2 parents 895a35c + d0562b8 commit a21414a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.1.1

- Fix the new before_send behaviour & tests, and add documentation ([#197](/~https://github.com/alphagov/govuk_app_config/pull/197))

# 3.1.0

- Remove support for `should_capture` callbacks in favour of `before_send` ([#196](/~https://github.com/alphagov/govuk_app_config/pull/196))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ end
Finally, you can pass your own callback to evaluate whether or not to capture the exception.
Note that if an exception is on the `excluded_exceptions` list, or on the `data_sync_excluded_exceptions`
and occurs at the time of a data sync, then it will be excluded even if the custom
`should_capture` callback returns `true`.
`before_send` callback doesn't return `nil`.

```ruby
GovukError.configure do |config|
config.should_capture = lambda do |error_or_event|
error_or_event == "do capture"
config.before_send = lambda do |error_or_event|
error_or_event == "do capture" ? error_or_event : nil
end
end
```
Expand Down
4 changes: 2 additions & 2 deletions lib/govuk_app_config/govuk_error/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def initialize(_raven_configuration)
ignore_excluded_exceptions_in_data_sync,
increment_govuk_statsd_counters,
]
super.before_send = run_before_send_callbacks
end

def before_send=(closure)
@before_send_callbacks.insert(-2, closure)
super(run_before_send_callbacks)
end

protected
Expand All @@ -39,7 +39,7 @@ def ignore_excluded_exceptions_in_data_sync
rescue NameError
# the exception type represented by the exception_to_ignore string
# doesn't even exist in this environment, so won't be found in the chain
nil
false
end

error_or_event unless data_sync.in_progress? && data_sync_ignored_error
Expand Down
4 changes: 4 additions & 0 deletions lib/govuk_app_config/govuk_error/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
"GdsApi::ContentStore::ItemNotFound",
]

config.before_send = lambda { |error_or_event, _hint|
error_or_event
}

config.transport_failure_callback = proc {
GovukStatsd.increment("error_reports_failed")
}
Expand Down
2 changes: 1 addition & 1 deletion lib/govuk_app_config/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module GovukAppConfig
VERSION = "3.1.0".freeze
VERSION = "3.1.1".freeze
end
15 changes: 11 additions & 4 deletions spec/govuk_error/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
require "govuk_app_config/govuk_error/configuration"

RSpec.describe GovukError::Configuration do
before :each do
stub_const("GovukStatsd", double(Module, increment: nil))
end

describe ".initialize" do
it "delegates to the passed object if it doesn't have the method defined" do
delegated_object = double("Raven.configuration").as_null_object
Expand All @@ -12,7 +16,13 @@
end

describe ".before_send" do
let(:configuration) { GovukError::Configuration.new(Raven.configuration) }
let(:configuration) do
configuration = GovukError::Configuration.new(Raven.configuration)
configuration.before_send = lambda { |error_or_event, _hint|
error_or_event
}
configuration
end

it "ignores errors if they happen in an environment we don't care about" do
ClimateControl.modify SENTRY_CURRENT_ENV: "some-temporary-environment" do
Expand Down Expand Up @@ -101,7 +111,6 @@
end

context "when the before_send lambda has not been overridden" do
before { stub_const("GovukStatsd", double(Module)) }
it "increments the appropriate counters" do
ClimateControl.modify SENTRY_CURRENT_ENV: "production" do
configuration.active_sentry_environments << "production"
Expand All @@ -113,7 +122,6 @@
end

context "when the before_send lambda has been overridden" do
before { stub_const("GovukStatsd", double(Module)) }
it "increments the appropriate counters" do
ClimateControl.modify SENTRY_CURRENT_ENV: "production" do
configuration.active_sentry_environments << "production"
Expand All @@ -132,7 +140,6 @@
end

context "when the before_send lambda has been overridden several times, all take effect" do
before { stub_const("GovukStatsd", double(Module)) }
it "increments the appropriate counters" do
ClimateControl.modify SENTRY_CURRENT_ENV: "production" do
configuration.active_sentry_environments << "production"
Expand Down

0 comments on commit a21414a

Please sign in to comment.