exception_handling 2.6.0 → 2.7.0.pre.1

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: 5720f1d81733d8912d7777a97e57f29c412b05fd938ebe073c91973d1b948685
4
- data.tar.gz: b7f587666d212e629be8603cbb711c76ade2917d1a03c91e541f87b7c3eb09c6
3
+ metadata.gz: 3794611262e09346bab80e7a683f4ce1d78d6ba04b46fa15fa4bc84ac087e41e
4
+ data.tar.gz: 36f96bed7f2b3375df4730d35ee5ec96cdf70e7c07f4ba589e187c75275c1736
5
5
  SHA512:
6
- metadata.gz: c7138e98374c2f2609500fdd2c11c7bee9211d6f6d548e5c1afe3191318e5966c48ff8fd6e6af2230f5c3ceb6ca44ece1535a85009881e9bd748adcf7d8438e9
7
- data.tar.gz: 6f6cdf2a385a190f1439488c3ac0e3dbaa4c5726a6dfdb4c8bb647b7e86c4dd06bb8d2740cc6e1ee54dfebd77a65b204884fd0bd76346367d201eb624f036757
6
+ metadata.gz: 2d1dad10749b867696c0f4dcacedcfb4af466ba792fa0c98ae307ee4bbeda10657f172fc95ff3c9b0162d1787d39c3c2a15a220fa6c6f4a7f7b10d857dad5eec
7
+ data.tar.gz: 8b28f2829a1e34787d7de51fdee4d0fe5a39356584d6d910c106edac2fe5d8ebcf0f3f5f1e9e1b7e4e7b0c36dd62035885214248072e47a7fdec7d1e4a854f94
@@ -4,7 +4,17 @@ Inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
5
  Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [2.6.0] - Unreleased
7
+ ## [2.7.0] - Unreleased
8
+ ### Added
9
+ - Added `LoggingMethods` as a replacement for `Methods` without setting controller or checking for long controller action.
10
+ ### Deprecated
11
+ - Deprecated `Methods` in favor of `LoggingMethods`.
12
+
13
+ ## [2.6.1] - Unreleased
14
+ ### Fixed
15
+ - Fixed honeybadger_context_data to always merge `current_context_for_thread`, even if `log_context:` is passed as `nil`.
16
+
17
+ ## [2.6.0] - 2020-08-26
8
18
  ### Changed
9
19
  - Calling `log_warning` will now log with Severity::WARNING rather than FATAL.
10
20
  - Reordered the logging to put the exception class next to the message.
@@ -42,6 +52,8 @@ Note: this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0
42
52
  ### Changed
43
53
  - No longer depends on hobo_support. Uses invoca-utils 0.3 instead.
44
54
 
55
+ [2.7.0]: https://github.com/Invoca/exception_handling/compare/v2.6.1...v2.7.0
56
+ [2.6.1]: https://github.com/Invoca/exception_handling/compare/v2.6.0...v2.6.1
45
57
  [2.6.0]: https://github.com/Invoca/exception_handling/compare/v2.5.0...v2.6.0
46
58
  [2.5.0]: https://github.com/Invoca/exception_handling/compare/v2.4.4...v2.5.0
47
59
  [2.4.4]: https://github.com/Invoca/exception_handling/compare/v2.4.3...v2.4.4
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- exception_handling (2.6.0)
11
+ exception_handling (2.7.0.pre.1)
12
12
  actionmailer (>= 4.2, < 7.0)
13
13
  actionpack (>= 4.2, < 7.0)
14
14
  activesupport (>= 4.2, < 7.0)
@@ -55,7 +55,7 @@ GEM
55
55
  builder (3.2.3)
56
56
  coderay (1.1.2)
57
57
  concurrent-ruby (1.1.5)
58
- contextual_logger (0.9.1)
58
+ contextual_logger (0.11.0)
59
59
  activesupport
60
60
  json
61
61
  crass (1.0.6)
@@ -29,6 +29,8 @@ module ExceptionHandling # never included
29
29
  AUTHENTICATION_HEADERS = ['HTTP_AUTHORIZATION', 'X-HTTP_AUTHORIZATION', 'X_HTTP_AUTHORIZATION', 'REDIRECT_X_HTTP_AUTHORIZATION'].freeze
30
30
  HONEYBADGER_STATUSES = [:success, :failure, :skipped].freeze
31
31
 
32
+ Deprecation3_0 = ActiveSupport::Deprecation.new('3.0', 'exception_handling')
33
+
32
34
  class << self
33
35
 
34
36
  #
@@ -54,8 +56,6 @@ module ExceptionHandling # never included
54
56
  @logger or raise ArgumentError, "You must assign a value to #{name}.logger"
55
57
  end
56
58
 
57
- Deprecation3_0 = ActiveSupport::Deprecation.new('3.0', 'exception_handling')
58
-
59
59
  def logger=(logger)
60
60
  @logger = if logger.nil? || logger.is_a?(ContextualLogger::LoggerMixin)
61
61
  logger
@@ -57,9 +57,8 @@ module ExceptionHandling
57
57
  @timestamp = timestamp
58
58
  @controller = controller || controller_from_context(exception_context)
59
59
  @data_callback = data_callback
60
- @merged_log_context = if log_context # merge into the surrounding context just like ContextualLogger does when logging
61
- ExceptionHandling.logger.current_context_for_thread.deep_merge(log_context)
62
- end
60
+ # merge into the surrounding context just like ContextualLogger does when logging
61
+ @merged_log_context = ExceptionHandling.logger.current_context_for_thread.deep_merge(log_context || {})
63
62
  end
64
63
 
65
64
  def data
@@ -273,13 +272,11 @@ module ExceptionHandling
273
272
  data[:exception_context] = deep_clean_hash(@exception_context) if @exception_context.present?
274
273
  data[:log_context] = @merged_log_context
275
274
  unstringify_sections(data)
276
- context_data = HONEYBADGER_CONTEXT_SECTIONS.reduce({}) do |context, section|
275
+ HONEYBADGER_CONTEXT_SECTIONS.each_with_object({}) do |section, context|
277
276
  if data[section].present?
278
277
  context[section] = data[section]
279
278
  end
280
- context
281
279
  end
282
- context_data
283
280
  end
284
281
  end
285
282
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'active_support/core_ext/module/delegation.rb'
5
+
6
+ module ExceptionHandling
7
+ module LoggingMethods # included on models and controllers
8
+ extend ActiveSupport::Concern
9
+
10
+ protected
11
+
12
+ delegate :log_error_rack, :log_warning, :log_info, :log_debug, :escalate_error, :escalate_warning, :ensure_escalation, :alert_warning, to: ExceptionHandling
13
+
14
+ # TODO: delegate log_error as well
15
+ def log_error(exception_or_string, exception_context = '')
16
+ controller = self if respond_to?(:request) && respond_to?(:session)
17
+ ExceptionHandling.log_error(exception_or_string, exception_context, controller)
18
+ end
19
+
20
+ def ensure_safe(exception_context = "")
21
+ yield
22
+ rescue => ex
23
+ log_error ex, exception_context
24
+ nil
25
+ end
26
+
27
+ def ensure_alert(*args)
28
+ ExceptionHandling.ensure_alert(*args) do
29
+ yield
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,65 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/concern'
4
+ require_relative 'logging_methods'
4
5
 
5
6
  module ExceptionHandling
6
7
  module Methods # included on models and controllers
7
8
  extend ActiveSupport::Concern
9
+ include ExceptionHandling::LoggingMethods
8
10
 
9
11
  protected
10
12
 
11
- def log_error(exception_or_string, exception_context = '')
12
- controller = self if respond_to?(:request) && respond_to?(:session)
13
- ExceptionHandling.log_error(exception_or_string, exception_context, controller)
14
- end
15
-
16
- def log_error_rack(exception_or_string, exception_context = '', rack_filter = '')
17
- ExceptionHandling.log_error_rack(exception_or_string, exception_context, rack_filter)
18
- end
19
-
20
- def log_warning(message)
21
- ExceptionHandling.log_warning(message)
22
- end
23
-
24
- def log_info(message)
25
- ExceptionHandling.logger.info(message)
26
- end
27
-
28
- def log_debug(message)
29
- ExceptionHandling.logger.debug(message)
30
- end
31
-
32
- def ensure_safe(exception_context = "")
33
- yield
34
- rescue => ex
35
- log_error ex, exception_context
36
- nil
37
- end
38
-
39
- def escalate_error(exception_or_string, email_subject)
40
- ExceptionHandling.escalate_error(exception_or_string, email_subject)
41
- end
42
-
43
- def escalate_warning(message, email_subject)
44
- ExceptionHandling.escalate_warning(message, email_subject)
45
- end
46
-
47
- def ensure_escalation(*args)
48
- ExceptionHandling.ensure_escalation(*args) do
49
- yield
50
- end
51
- end
52
-
53
- def alert_warning(*args)
54
- ExceptionHandling.alert_warning(*args)
55
- end
56
-
57
- def ensure_alert(*args)
58
- ExceptionHandling.ensure_alert(*args) do
59
- yield
60
- end
61
- end
62
-
63
13
  def long_controller_action_timeout
64
14
  if defined?(Rails) && Rails.respond_to?(:env) && Rails.env == 'test'
65
15
  300
@@ -88,7 +38,10 @@ module ExceptionHandling
88
38
  end
89
39
 
90
40
  included do
91
- around_filter :set_current_controller if respond_to? :around_filter
41
+ Deprecation3_0.deprecation_warning('ExceptionHandling::Methods', 'include LoggingMethods; in controllers, set your own around_filter to set logging context')
42
+ if respond_to? :around_filter
43
+ around_filter :set_current_controller
44
+ end
92
45
  end
93
46
 
94
47
  class_methods do
@@ -4,7 +4,7 @@
4
4
 
5
5
  module ExceptionHandling
6
6
  module Testing
7
- class ControllerStub
7
+ class ControllerStubBase
8
8
 
9
9
  class Request
10
10
  attr_accessor :parameters, :protocol, :host, :request_uri, :env, :session_options
@@ -25,7 +25,7 @@ module ExceptionHandling
25
25
  attr_accessor :around_filter_method
26
26
 
27
27
  def around_filter(method)
28
- ControllerStub.around_filter_method = method
28
+ self.around_filter_method = method
29
29
  end
30
30
  end
31
31
 
@@ -44,14 +44,6 @@ module ExceptionHandling
44
44
  end
45
45
  end
46
46
 
47
- def simulate_around_filter(&block)
48
- set_current_controller(&block)
49
- end
50
-
51
- def controller_name
52
- "ControllerStub"
53
- end
54
-
55
47
  def action_name
56
48
  "test_action"
57
49
  end
@@ -59,9 +51,27 @@ module ExceptionHandling
59
51
  def complete_request_uri
60
52
  "#{@request.protocol}#{@request.host}#{@request.request_uri}"
61
53
  end
54
+ end
55
+
56
+ class LoggingMethodsControllerStub < ControllerStubBase
57
+ include ExceptionHandling::LoggingMethods
58
+
59
+ def controller_name
60
+ "LoggingMethodsControllerStub"
61
+ end
62
+ end
62
63
 
64
+ class MethodsControllerStub < ControllerStubBase
63
65
  include ExceptionHandling::Methods
64
66
  set_long_controller_action_timeout 2
67
+
68
+ def simulate_around_filter(&block)
69
+ set_current_controller(&block)
70
+ end
71
+
72
+ def controller_name
73
+ "MethodsControllerStub"
74
+ end
65
75
  end
66
76
  end
67
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExceptionHandling
4
- VERSION = '2.6.0'
4
+ VERSION = '2.7.0.pre.1'
5
5
  end
@@ -417,6 +417,26 @@ module ExceptionHandling
417
417
  end
418
418
 
419
419
  context "honeybadger_context_data" do
420
+ setup do
421
+ stub(ExceptionHandling.logger).current_context_for_thread { { cuid: 'ABCD' } }
422
+ end
423
+
424
+ should "include thread_context when log_context: is nil" do
425
+ exception_with_nil_message = RuntimeError.new(nil)
426
+ stub(exception_with_nil_message).message { nil }
427
+ exception_info = ExceptionInfo.new(exception_with_nil_message, @exception_context, @timestamp)
428
+ honeybadger_context_data = exception_info.honeybadger_context_data
429
+ assert_equal({ "cuid" => 'ABCD' }, honeybadger_context_data[:log_context])
430
+ end
431
+
432
+ should "include thread context merged with log_context:" do
433
+ exception_with_nil_message = RuntimeError.new(nil)
434
+ stub(exception_with_nil_message).message { nil }
435
+ exception_info = ExceptionInfo.new(exception_with_nil_message, @exception_context, @timestamp, log_context: { url: 'http://example.com' })
436
+ honeybadger_context_data = exception_info.honeybadger_context_data
437
+ assert_equal({ "cuid" => 'ABCD', "url" => 'http://example.com' }, honeybadger_context_data[:log_context])
438
+ end
439
+
420
440
  should "return the error details and relevant context data to be used as honeybadger notification context while filtering sensitive data" do
421
441
  env = { server: "fe98" }
422
442
  parameters = { advertiser_id: 435 }
@@ -464,7 +484,8 @@ module ExceptionHandling
464
484
  "test/unit/exception_handling_test.rb:847:in `exception_1'",
465
485
  "test/unit/exception_handling_test.rb:455:in `block (4 levels) in <class:ExceptionHandlingTest>'"
466
486
  ],
467
- event_response: "Event successfully received"
487
+ event_response: "Event successfully received",
488
+ log_context: { "cuid" => "ABCD" }
468
489
  }
469
490
  assert_equal_with_diff expected_data, exception_info.honeybadger_context_data
470
491
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../test_helper'
4
+ require_relative '../../helpers/exception_helpers'
5
+
6
+ require "exception_handling/testing"
7
+
8
+ module ExceptionHandling
9
+ class LoggingMethodsTest < ActiveSupport::TestCase
10
+ include ExceptionHelpers
11
+
12
+ def dont_stub_log_error
13
+ true
14
+ end
15
+
16
+ context "ExceptionHandling::LoggingMethods" do
17
+ setup do
18
+ @controller = Testing::LoggingMethodsControllerStub.new
19
+ ExceptionHandling.stub_handler = nil
20
+ end
21
+
22
+ context "#log_warning" do
23
+ should "be available to the controller" do
24
+ klass = Class.new
25
+ klass.include ExceptionHandling::LoggingMethods
26
+ instance = klass.new
27
+ assert instance.methods.include?(:log_warning)
28
+ end
29
+
30
+ should "call ExceptionHandling#log_warning" do
31
+ mock(ExceptionHandling).log_warning("Hi mom")
32
+ @controller.send(:log_warning, "Hi mom")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../../test_helper', __dir__)
3
+ require_relative '../../test_helper'
4
+ require_relative '../../helpers/exception_helpers'
4
5
 
5
6
  require "exception_handling/testing"
6
7
 
@@ -12,14 +13,14 @@ module ExceptionHandling
12
13
  true
13
14
  end
14
15
 
15
- context "ExceptionHandling.Methods" do
16
+ context "ExceptionHandling::Methods" do
16
17
  setup do
17
- @controller = Testing::ControllerStub.new
18
+ @controller = Testing::MethodsControllerStub.new
18
19
  ExceptionHandling.stub_handler = nil
19
20
  end
20
21
 
21
22
  should "set the around filter" do
22
- assert_equal :set_current_controller, Testing::ControllerStub.around_filter_method
23
+ assert_equal :set_current_controller, Testing::MethodsControllerStub.around_filter_method
23
24
  assert_nil ExceptionHandling.current_controller
24
25
  @controller.simulate_around_filter do
25
26
  assert_equal @controller, ExceptionHandling.current_controller
@@ -70,15 +71,35 @@ module ExceptionHandling
70
71
 
71
72
  context "#log_warning" do
72
73
  should "be available to the controller" do
73
- assert_equal true, @controller.methods.include?(:log_warning)
74
+ assert @controller.methods.include?(:log_warning)
74
75
  end
76
+ end
77
+ end
78
+
79
+ context "included deprecation" do
80
+ setup do
81
+ mock_deprecation_3_0
82
+ end
75
83
 
76
- should "call ExceptionHandling#log_warning" do
77
- mock(ExceptionHandling).log_warning("Hi mom")
78
- @controller.send(:log_warning, "Hi mom")
84
+ should "deprecate when no around_filter in included hook" do
85
+ k = Class.new
86
+ k.include ExceptionHandling::Methods
87
+ end
88
+
89
+ should "deprecate controller around_filter in included hook" do
90
+ controller = Class.new
91
+ class << controller
92
+ def around_filter(*)
93
+ end
79
94
  end
95
+ controller.include ExceptionHandling::Methods
80
96
  end
81
97
  end
82
98
 
99
+ private
100
+
101
+ def mock_deprecation_3_0
102
+ mock(STDERR).puts(/DEPRECATION WARNING: ExceptionHandling::Methods is deprecated and will be removed from exception_handling 3\.0/)
103
+ end
83
104
  end
84
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_handling
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -143,6 +143,7 @@ files:
143
143
  - lib/exception_handling/exception_info.rb
144
144
  - lib/exception_handling/honeybadger_callbacks.rb
145
145
  - lib/exception_handling/log_stub_error.rb
146
+ - lib/exception_handling/logging_methods.rb
146
147
  - lib/exception_handling/mailer.rb
147
148
  - lib/exception_handling/methods.rb
148
149
  - lib/exception_handling/sensu.rb
@@ -157,6 +158,7 @@ files:
157
158
  - test/unit/exception_handling/exception_info_test.rb
158
159
  - test/unit/exception_handling/honeybadger_callbacks_test.rb
159
160
  - test/unit/exception_handling/log_error_stub_test.rb
161
+ - test/unit/exception_handling/logging_methods_test.rb
160
162
  - test/unit/exception_handling/mailer_test.rb
161
163
  - test/unit/exception_handling/methods_test.rb
162
164
  - test/unit/exception_handling/sensu_test.rb
@@ -169,7 +171,7 @@ licenses: []
169
171
  metadata:
170
172
  source_code_uri: https://github.com/Invoca/exception_handling
171
173
  allowed_push_host: https://rubygems.org
172
- post_install_message:
174
+ post_install_message:
173
175
  rdoc_options: []
174
176
  require_paths:
175
177
  - lib
@@ -180,12 +182,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
182
  version: '0'
181
183
  required_rubygems_version: !ruby/object:Gem::Requirement
182
184
  requirements:
183
- - - ">="
185
+ - - ">"
184
186
  - !ruby/object:Gem::Version
185
- version: '0'
187
+ version: 1.3.1
186
188
  requirements: []
187
189
  rubygems_version: 3.0.3
188
- signing_key:
190
+ signing_key:
189
191
  specification_version: 4
190
192
  summary: Invoca's exception handling logger/emailer layer, based on exception_notifier.
191
193
  Works with Rails or EventMachine or EventMachine+Synchrony.
@@ -199,6 +201,7 @@ test_files:
199
201
  - test/unit/exception_handling/exception_info_test.rb
200
202
  - test/unit/exception_handling/honeybadger_callbacks_test.rb
201
203
  - test/unit/exception_handling/log_error_stub_test.rb
204
+ - test/unit/exception_handling/logging_methods_test.rb
202
205
  - test/unit/exception_handling/mailer_test.rb
203
206
  - test/unit/exception_handling/methods_test.rb
204
207
  - test/unit/exception_handling/sensu_test.rb