govuk_app_config 3.1.0 → 4.0.0.pre.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e875cdeb8303839a0f8cf66370ff3d355b7c770877dad6216fc47989ebc5c7a6
4
- data.tar.gz: b060cceb5e5d54c1e81b76a01585ff75eeae4d630a3f9102fea91597eaf00a95
3
+ metadata.gz: 494d23c9b999e7cfd6a7e2fac76f1a52cdf70aa5b7c62509e48693c13bb07d7c
4
+ data.tar.gz: ccd962b2f670063ead978e49f38affcf925b1e05a47b4a97066b88b5243dcbaa
5
5
  SHA512:
6
- metadata.gz: b7d7d5b3f26029738e974dd096f2ce8ade8f44be23f87526cc589da2219d2847b58553ddd57d320d5f412b65c5349bde8b2a8f746efb02286e4867fe594a2214
7
- data.tar.gz: abfe7e93cc5b2e1b30cbcca6886a71f3f42f1e41d05cb12268a4ca8b9ae56b74d4f68dcafd602ab9166f5df8c7466c83c5dffa4332270f08172c7e73972220e2
6
+ metadata.gz: 624aefd37a2c76460bfecdbf17071991fa3745249ac27b9bb6026bc67e4e335cd94bdf67d82f8521557c8661fca36ced879a68a346bfe592786e88df0f06ddbe
7
+ data.tar.gz: 7cbbc37819f1b176dde9d4d90bf71b333621cdfabfd042b2fe439223aa47a98c43713b86f2784c6ced2c43a9f28cb01bf83f021e724de7def9e4a7a74dd0c264
data/CHANGELOG.md CHANGED
@@ -1,3 +1,28 @@
1
+ # 4.0.0.pre.4
2
+
3
+ - Fix Sentry client initialisation ([#205](https://github.com/alphagov/govuk_app_config/pull/205)).
4
+ - BREAKING: non-Rails apps will need to manually call `GovukError.configure` in order to initialise Sentry.
5
+ - BREAKING: `GovukError.configure` can only be called once by the downstream application.
6
+
7
+ # 4.0.0.pre.3
8
+
9
+ - Include [sentry-rails](https://github.com/getsentry/sentry-ruby/tree/master/sentry-rails) by default ([#203](https://github.com/alphagov/govuk_app_config/pull/203)).
10
+
11
+ # 4.0.0.pre.2
12
+
13
+ - Fix default Sentry configuration ([#202](https://github.com/alphagov/govuk_app_config/pull/202)).
14
+ - BREAKING: this means no more `silence_ready` or `transport_failure_callback` options.
15
+
16
+ # 4.0.0.pre.1
17
+
18
+ - BREAKING: upgrades Sentry gem from `sentry-raven` to `sentry-ruby` ([#199](https://github.com/alphagov/govuk_app_config/pull/199)). There is a **[migration guide](https://docs.sentry.io/platforms/ruby/migration/)** you should follow before upgrading to this version of govuk_app_config.
19
+ - This release also fixes the `data_sync_excluded_exceptions` behaviour that has been broken since v3.1.0.
20
+ - Released as a pre-release to identify and fix any problems before a wider rollout.
21
+
22
+ # 3.1.1
23
+
24
+ - Fix the new before_send behaviour & tests, and add documentation ([#197](https://github.com/alphagov/govuk_app_config/pull/197))
25
+
1
26
  # 3.1.0
2
27
 
3
28
  - Remove support for `should_capture` callbacks in favour of `before_send` ([#196](https://github.com/alphagov/govuk_app_config/pull/196))
data/README.md CHANGED
@@ -87,7 +87,7 @@ You can add your environment to the list of active Sentry environments like so:
87
87
 
88
88
  ```ruby
89
89
  GovukError.configure do |config|
90
- config.active_sentry_environments << "my-test-environment"
90
+ config.enabled_environments << "my-test-environment"
91
91
  end
92
92
  ```
93
93
 
@@ -112,12 +112,12 @@ end
112
112
  Finally, you can pass your own callback to evaluate whether or not to capture the exception.
113
113
  Note that if an exception is on the `excluded_exceptions` list, or on the `data_sync_excluded_exceptions`
114
114
  and occurs at the time of a data sync, then it will be excluded even if the custom
115
- `should_capture` callback returns `true`.
115
+ `before_send` callback doesn't return `nil`.
116
116
 
117
117
  ```ruby
118
118
  GovukError.configure do |config|
119
- config.should_capture = lambda do |error_or_event|
120
- error_or_event == "do capture"
119
+ config.before_send = lambda do |event, hint|
120
+ hint[:exception].is_a?(ErrorWeWantToIgnore) ? nil : event
121
121
  end
122
122
  end
123
123
  ```
@@ -13,15 +13,16 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/alphagov/govuk_app_config"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
18
- end
16
+ spec.required_ruby_version = ">= 2.6"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
19
  spec.bindir = "exe"
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = %w[lib]
22
22
 
23
23
  spec.add_dependency "logstasher", ">= 1.2.2", "< 2.2.0"
24
- spec.add_dependency "sentry-raven", "~> 3.1.1"
24
+ spec.add_dependency "sentry-rails", "~> 4.5.0"
25
+ spec.add_dependency "sentry-ruby", "~> 4.5.0"
25
26
  spec.add_dependency "statsd-ruby", "~> 1.5.0"
26
27
  spec.add_dependency "unicorn", ">= 5.4", "< 5.9"
27
28
 
@@ -1,7 +1,6 @@
1
1
  require "govuk_app_config/version"
2
2
  require "govuk_app_config/govuk_statsd"
3
3
  require "govuk_app_config/govuk_error"
4
- require "govuk_app_config/govuk_error/configure"
5
4
  require "govuk_app_config/govuk_healthcheck"
6
5
  require "govuk_app_config/govuk_i18n"
7
6
  # This require is deprecated and should be removed on next major version bump
@@ -1,9 +1,16 @@
1
- require "sentry-raven"
1
+ require "sentry-ruby"
2
+ require "sentry-rails"
2
3
  require "govuk_app_config/govuk_statsd"
3
4
  require "govuk_app_config/govuk_error/configuration"
4
5
  require "govuk_app_config/version"
5
6
 
6
7
  module GovukError
8
+ class AlreadyInitialised < StandardError
9
+ def initialize(msg = "You can only call GovukError.configure once!")
10
+ super
11
+ end
12
+ end
13
+
7
14
  def self.notify(exception_or_message, args = {})
8
15
  # Allow users to use `parameters` as a key like the Airbrake
9
16
  # client, allowing easy upgrades.
@@ -13,11 +20,23 @@ module GovukError
13
20
  args[:tags] ||= {}
14
21
  args[:tags][:govuk_app_config_version] = GovukAppConfig::VERSION
15
22
 
16
- Raven.capture_exception(exception_or_message, args)
23
+ if exception_or_message.is_a?(String)
24
+ Sentry.capture_message(exception_or_message, args)
25
+ else
26
+ Sentry.capture_exception(exception_or_message, args)
27
+ end
28
+ end
29
+
30
+ def self.is_configured?
31
+ Sentry.get_current_client != nil
17
32
  end
18
33
 
19
34
  def self.configure
20
- @configuration ||= Configuration.new(Raven.configuration)
21
- yield @configuration
35
+ raise GovukError::AlreadyInitialised if is_configured?
36
+
37
+ Sentry.init do |sentry_config|
38
+ config = Configuration.new(sentry_config)
39
+ yield config if block_given?
40
+ end
22
41
  end
23
42
  end
@@ -3,62 +3,122 @@ require "govuk_app_config/govuk_error/govuk_data_sync"
3
3
 
4
4
  module GovukError
5
5
  class Configuration < SimpleDelegator
6
- attr_reader :data_sync, :sentry_environment
7
- attr_accessor :active_sentry_environments, :data_sync_excluded_exceptions
6
+ attr_reader :data_sync
7
+ attr_accessor :data_sync_excluded_exceptions
8
8
 
9
- def initialize(_raven_configuration)
9
+ def initialize(_sentry_configuration)
10
10
  super
11
- @sentry_environment = ENV["SENTRY_CURRENT_ENV"]
12
11
  @data_sync = GovukDataSync.new(ENV["GOVUK_DATA_SYNC_PERIOD"])
13
- self.active_sentry_environments = []
14
- self.data_sync_excluded_exceptions = []
12
+ set_up_defaults
13
+ end
14
+
15
+ def set_up_defaults
16
+ # These are the environments (described by the `SENTRY_CURRENT_ENV`
17
+ # ENV variable) where we want to capture Sentry errors. If
18
+ # `SENTRY_CURRENT_ENV` isn't in this list, or isn't defined, then
19
+ # don't capture the error.
20
+ self.enabled_environments = %w[
21
+ integration-blue-aws
22
+ staging
23
+ production
24
+ ]
25
+
26
+ self.excluded_exceptions = [
27
+ # Default ActionDispatch rescue responses
28
+ "ActionController::RoutingError",
29
+ "AbstractController::ActionNotFound",
30
+ "ActionController::MethodNotAllowed",
31
+ "ActionController::UnknownHttpMethod",
32
+ "ActionController::NotImplemented",
33
+ "ActionController::UnknownFormat",
34
+ "Mime::Type::InvalidMimeType",
35
+ "ActionController::MissingExactTemplate",
36
+ "ActionController::InvalidAuthenticityToken",
37
+ "ActionController::InvalidCrossOriginRequest",
38
+ "ActionDispatch::Http::Parameters::ParseError",
39
+ "ActionController::BadRequest",
40
+ "ActionController::ParameterMissing",
41
+ "Rack::QueryParser::ParameterTypeError",
42
+ "Rack::QueryParser::InvalidParameterError",
43
+ # Default ActiveRecord rescue responses
44
+ "ActiveRecord::RecordNotFound",
45
+ "ActiveRecord::StaleObjectError",
46
+ "ActiveRecord::RecordInvalid",
47
+ "ActiveRecord::RecordNotSaved",
48
+ # Additional items
49
+ "ActiveJob::DeserializationError",
50
+ "CGI::Session::CookieStore::TamperedWithCookie",
51
+ "GdsApi::HTTPIntermittentServerError",
52
+ "GdsApi::TimedOutException",
53
+ "Mongoid::Errors::DocumentNotFound",
54
+ "Sinatra::NotFound",
55
+ "Slimmer::IntermittentRetrievalError",
56
+ ]
57
+
58
+ # This will exclude exceptions that are triggered by one of the ignored
59
+ # exceptions. For example, when any exception occurs in a template,
60
+ # Rails will raise a ActionView::Template::Error, instead of the original error.
61
+ self.inspect_exception_causes_for_exclusion = true
62
+
63
+ # List of exceptions to ignore if they take place during the data sync.
64
+ # Some errors are transient in nature, e.g. PostgreSQL databases being
65
+ # unavailable, and add little value. In fact, their presence can greatly
66
+ # increase the number of errors being sent and risk genuine errors being
67
+ # rate-limited by Sentry.
68
+ self.data_sync_excluded_exceptions = [
69
+ "PG::Error",
70
+ "GdsApi::ContentStore::ItemNotFound",
71
+ ]
72
+
15
73
  @before_send_callbacks = [
16
- ignore_exceptions_if_not_in_active_sentry_env,
17
74
  ignore_excluded_exceptions_in_data_sync,
18
75
  increment_govuk_statsd_counters,
19
76
  ]
20
- super.before_send = run_before_send_callbacks
77
+ # Need to invoke an arbitrary `before_send=` in order to trigger the
78
+ # `before_send_callbacks` behaviour
79
+ self.before_send = lambda { |error_or_event, _hint|
80
+ error_or_event
81
+ }
21
82
  end
22
83
 
23
84
  def before_send=(closure)
24
85
  @before_send_callbacks.insert(-2, closure)
86
+ super(run_before_send_callbacks)
25
87
  end
26
88
 
27
89
  protected
28
90
 
29
- def ignore_exceptions_if_not_in_active_sentry_env
30
- ->(error_or_event, _hint) { error_or_event if active_sentry_environments.include?(sentry_environment) }
31
- end
32
-
33
91
  def ignore_excluded_exceptions_in_data_sync
34
- lambda { |error_or_event, _hint|
92
+ lambda { |event, hint|
35
93
  data_sync_ignored_error = data_sync_excluded_exceptions.any? do |exception_to_ignore|
36
94
  exception_to_ignore = Object.const_get(exception_to_ignore) unless exception_to_ignore.is_a?(Module)
37
- exception_chain = Raven::Utils::ExceptionCauseChain.exception_to_array(error_or_event)
95
+ exception_chain = Sentry::Utils::ExceptionCauseChain.exception_to_array(hint[:exception])
38
96
  exception_chain.any? { |exception| exception.is_a?(exception_to_ignore) }
39
97
  rescue NameError
40
98
  # the exception type represented by the exception_to_ignore string
41
99
  # doesn't even exist in this environment, so won't be found in the chain
42
- nil
100
+ false
43
101
  end
44
102
 
45
- error_or_event unless data_sync.in_progress? && data_sync_ignored_error
103
+ event unless data_sync.in_progress? && data_sync_ignored_error
46
104
  }
47
105
  end
48
106
 
49
107
  def increment_govuk_statsd_counters
50
- lambda { |error_or_event, _hint|
51
- GovukStatsd.increment("errors_occurred")
52
- GovukStatsd.increment("error_types.#{error_or_event.class.name.demodulize.underscore}")
53
- error_or_event
108
+ lambda { |event, hint|
109
+ if hint[:exception]
110
+ GovukStatsd.increment("errors_occurred")
111
+ GovukStatsd.increment("error_types.#{hint[:exception].class.name.split('::').last.underscore}")
112
+ end
113
+ event
54
114
  }
55
115
  end
56
116
 
57
117
  def run_before_send_callbacks
58
- lambda do |error_or_event, hint|
59
- result = error_or_event
118
+ lambda do |event, hint|
119
+ result = event
60
120
  @before_send_callbacks.each do |callback|
61
- result = callback.call(error_or_event, hint)
121
+ result = callback.call(event, hint)
62
122
  break if result.nil?
63
123
  end
64
124
  result
@@ -3,14 +3,8 @@ require "time"
3
3
  module GovukError
4
4
  class GovukDataSync
5
5
  class MalformedDataSyncPeriod < RuntimeError
6
- attr_reader :invalid_value
7
-
8
6
  def initialize(invalid_value)
9
- @invalid_value = invalid_value
10
- end
11
-
12
- def message
13
- "\"#{invalid_value}\" is not a valid value (should be of form '22:00-03:00')."
7
+ super("\"#{invalid_value}\" is not a valid value (should be of form '22:00-03:00').")
14
8
  end
15
9
  end
16
10
 
@@ -3,5 +3,9 @@ module GovukAppConfig
3
3
  config.before_initialize do
4
4
  GovukLogging.configure if Rails.env.production?
5
5
  end
6
+
7
+ config.after_initialize do
8
+ GovukError.configure unless GovukError.is_configured?
9
+ end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "3.1.0".freeze
2
+ VERSION = "4.0.0.pre.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-18 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstasher
@@ -31,19 +31,33 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.2.0
33
33
  - !ruby/object:Gem::Dependency
34
- name: sentry-raven
34
+ name: sentry-rails
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 3.1.1
39
+ version: 4.5.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 3.1.1
46
+ version: 4.5.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: sentry-ruby
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 4.5.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 4.5.0
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: statsd-ruby
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -230,7 +244,6 @@ files:
230
244
  - lib/govuk_app_config/govuk_content_security_policy.rb
231
245
  - lib/govuk_app_config/govuk_error.rb
232
246
  - lib/govuk_app_config/govuk_error/configuration.rb
233
- - lib/govuk_app_config/govuk_error/configure.rb
234
247
  - lib/govuk_app_config/govuk_error/govuk_data_sync.rb
235
248
  - lib/govuk_app_config/govuk_healthcheck.rb
236
249
  - lib/govuk_app_config/govuk_healthcheck/active_record.rb
@@ -258,14 +271,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
258
271
  requirements:
259
272
  - - ">="
260
273
  - !ruby/object:Gem::Version
261
- version: '0'
274
+ version: '2.6'
262
275
  required_rubygems_version: !ruby/object:Gem::Requirement
263
276
  requirements:
264
- - - ">="
277
+ - - ">"
265
278
  - !ruby/object:Gem::Version
266
- version: '0'
279
+ version: 1.3.1
267
280
  requirements: []
268
- rubygems_version: 3.1.4
281
+ rubygems_version: 3.0.3
269
282
  signing_key:
270
283
  specification_version: 4
271
284
  summary: Base configuration for GOV.UK applications
@@ -1,64 +0,0 @@
1
- GovukError.configure do |config|
2
- config.silence_ready = !Rails.env.production? if defined?(Rails)
3
-
4
- # These are the environments (described by the `SENTRY_CURRENT_ENV`
5
- # ENV variable) where we want to capture Sentry errors. If
6
- # `SENTRY_CURRENT_ENV` isn't in this list, or isn't defined, then
7
- # don't capture the error.
8
- config.active_sentry_environments = %w[
9
- integration-blue-aws
10
- staging
11
- production
12
- ]
13
-
14
- config.excluded_exceptions = [
15
- # Default ActionDispatch rescue responses
16
- "ActionController::RoutingError",
17
- "AbstractController::ActionNotFound",
18
- "ActionController::MethodNotAllowed",
19
- "ActionController::UnknownHttpMethod",
20
- "ActionController::NotImplemented",
21
- "ActionController::UnknownFormat",
22
- "Mime::Type::InvalidMimeType",
23
- "ActionController::MissingExactTemplate",
24
- "ActionController::InvalidAuthenticityToken",
25
- "ActionController::InvalidCrossOriginRequest",
26
- "ActionDispatch::Http::Parameters::ParseError",
27
- "ActionController::BadRequest",
28
- "ActionController::ParameterMissing",
29
- "Rack::QueryParser::ParameterTypeError",
30
- "Rack::QueryParser::InvalidParameterError",
31
- # Default ActiveRecord rescue responses
32
- "ActiveRecord::RecordNotFound",
33
- "ActiveRecord::StaleObjectError",
34
- "ActiveRecord::RecordInvalid",
35
- "ActiveRecord::RecordNotSaved",
36
- # Additional items
37
- "ActiveJob::DeserializationError",
38
- "CGI::Session::CookieStore::TamperedWithCookie",
39
- "GdsApi::HTTPIntermittentServerError",
40
- "GdsApi::TimedOutException",
41
- "Mongoid::Errors::DocumentNotFound",
42
- "Sinatra::NotFound",
43
- "Slimmer::IntermittentRetrievalError",
44
- ]
45
-
46
- # This will exclude exceptions that are triggered by one of the ignored
47
- # exceptions. For example, when any exception occurs in a template,
48
- # Rails will raise a ActionView::Template::Error, instead of the original error.
49
- config.inspect_exception_causes_for_exclusion = true
50
-
51
- # List of exceptions to ignore if they take place during the data sync.
52
- # Some errors are transient in nature, e.g. PostgreSQL databases being
53
- # unavailable, and add little value. In fact, their presence can greatly
54
- # increase the number of errors being sent and risk genuine errors being
55
- # rate-limited by Sentry.
56
- config.data_sync_excluded_exceptions = [
57
- "PG::Error",
58
- "GdsApi::ContentStore::ItemNotFound",
59
- ]
60
-
61
- config.transport_failure_callback = proc {
62
- GovukStatsd.increment("error_reports_failed")
63
- }
64
- end