honeybadger 3.3.1 → 3.4.0.beta1

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
- SHA1:
3
- metadata.gz: 2dbccf9f60503c126bc9f6b66cdde42481fac83e
4
- data.tar.gz: f659d0157462c409907932c85a4b9a5e0e2cf8cf
2
+ SHA256:
3
+ metadata.gz: b610a8fe048c882cb15dadd39ae9adc1955e82952d58cd5852ee6ed0477a72bf
4
+ data.tar.gz: d65617bd6beb55778cc44001c0d1a8703b797b180e628d5f66f1c3278986fafe
5
5
  SHA512:
6
- metadata.gz: 1db263977550ca7fe10f9c47c8a49518b3c25ccc23f9e5b47b49980c944f2c4e86eeddf6e41a9fe70e93d07a87b19f45b9bc7f3acdce34dc9e5b1065ca1e91f0
7
- data.tar.gz: efd096b1bb6b968796bc2c00b46c0cb59b0c3d593e028b8551efb84e21e7a2de9e0f124500584b2f106af92c7c0f9c89357b6a10f42aa97f6de80551d05694d8
6
+ metadata.gz: 66818e625bb5e5c8ca2c06f8ebd3e7bbac07f4caacb4955ecb90fbb77f08df014df579adf1f3606ed4d26b315c5f108764f61f459d35253a50d0473ddf3b34ec
7
+ data.tar.gz: 2df50c6580e2ebed48cc1e4a9001cd94588f5cd23bfd80f451166a5ce9d6d1ecf6db4301dab7e5eddaaea67af5cf5e85e81fd6ff985800fb1738fb2dba8340b0
@@ -4,10 +4,14 @@ CHANGELOG](http://keepachangelog.com/) for how to update this file. This project
4
4
  adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
6
  ## [Unreleased]
7
+ ### Added
8
+ - Added `before_notify` hooks to be defined, this allows setting up of multiple
9
+ hooks which will be invoked with a `notice` before a `notice` is sent. Each
10
+ `before_notify` hook MUST be a `callable` (lambda, Proc etc,) with an arity of 1.
11
+ - Added the ability to halt notices in callbacks using `notice.halt!`
7
12
 
8
- ## [3.3.1] - 2018-08-02
9
13
  ### Fixed
10
- - Fix synchronous throttling in shoryuken
14
+ - Ignore SIGTERM SignalExceptions.
11
15
 
12
16
  ## [3.3.0] - 2018-01-29
13
17
  ### Changed
@@ -127,6 +127,11 @@ module Honeybadger
127
127
 
128
128
  notice = Notice.new(config, opts)
129
129
 
130
+ config.before_notify_hooks.each do |hook|
131
+ break if notice.halted?
132
+ with_error_handling { hook.call(notice) }
133
+ end
134
+
130
135
  unless notice.api_key =~ NOT_BLANK
131
136
  error { sprintf('Unable to send error report: API key is missing. id=%s', notice.id) }
132
137
  return false
@@ -137,6 +142,11 @@ module Honeybadger
137
142
  return false
138
143
  end
139
144
 
145
+ if notice.halted?
146
+ debug { 'halted notice feature=notices' }
147
+ return false
148
+ end
149
+
140
150
  info { sprintf('Reporting error id=%s', notice.id) }
141
151
 
142
152
  if opts[:sync]
@@ -381,6 +391,12 @@ module Honeybadger
381
391
  @worker = Worker.new(config)
382
392
  end
383
393
 
394
+ def with_error_handling
395
+ yield
396
+ rescue => ex
397
+ error { "Rescued an error in a before notify hook: #{ex.message}" }
398
+ end
399
+
384
400
  @instance = new(Config.new)
385
401
  end
386
402
  end
@@ -84,6 +84,10 @@ module Honeybadger
84
84
  self[:backtrace_filter]
85
85
  end
86
86
 
87
+ def before_notify_hooks
88
+ (ruby[:before_notify] || []).clone
89
+ end
90
+
87
91
  def exception_filter
88
92
  self[:exception_filter] = Proc.new if block_given?
89
93
  self[:exception_filter]
@@ -70,7 +70,7 @@ module Honeybadger
70
70
  end
71
71
 
72
72
  def logger
73
- get(:logger)
73
+ get(:logger) || config.logger
74
74
  end
75
75
 
76
76
  def backend=(backend)
@@ -78,7 +78,7 @@ module Honeybadger
78
78
  end
79
79
 
80
80
  def backend
81
- get(:backend)
81
+ get(:backend) || config.backend
82
82
  end
83
83
 
84
84
  def backtrace_filter
@@ -86,6 +86,16 @@ module Honeybadger
86
86
  get(:backtrace_filter)
87
87
  end
88
88
 
89
+ def before_notify(action = nil, &block)
90
+ (hash[:before_notify] ||= []).tap do |before_notify_hooks|
91
+ if action && validate_before_action(action)
92
+ before_notify_hooks << action
93
+ elsif block_given? && validate_before_action(block)
94
+ before_notify_hooks << block
95
+ end
96
+ end
97
+ end
98
+
89
99
  def exception_filter
90
100
  hash[:exception_filter] = Proc.new if block_given?
91
101
  get(:exception_filter)
@@ -95,6 +105,28 @@ module Honeybadger
95
105
  hash[:exception_fingerprint] = Proc.new if block_given?
96
106
  get(:exception_fingerprint)
97
107
  end
108
+
109
+ private
110
+
111
+ def validate_before_action(action)
112
+ if !action.respond_to?(:call)
113
+ logger.warn(
114
+ 'You attempted to add a before notify hook that does not respond ' \
115
+ 'to #call. We are discarding this hook so your intended behavior ' \
116
+ 'will not occur.'
117
+ )
118
+ false
119
+ elsif action.arity != 1
120
+ logger.warn(
121
+ 'You attempted to add a before notify hook that has an arity ' \
122
+ 'other than one. We are discarding this hook so your intended ' \
123
+ 'behavior will not occur.'
124
+ )
125
+ false
126
+ else
127
+ true
128
+ end
129
+ end
98
130
  end
99
131
  end
100
132
  end
@@ -107,8 +107,8 @@ module Honeybadger
107
107
  # Local variables are extracted from first frame of backtrace.
108
108
  attr_reader :local_variables
109
109
 
110
- # The API key used to deliver this notice.
111
- attr_reader :api_key
110
+ # Public: The API key used to deliver this notice.
111
+ attr_accessor :api_key
112
112
 
113
113
  # @api private
114
114
  # Cache project path substitutions for backtrace lines.
@@ -246,6 +246,19 @@ module Honeybadger
246
246
  ignore_by_origin? || ignore_by_class? || ignore_by_callbacks?
247
247
  end
248
248
 
249
+ # Halts the notice and the before_notify callback chain.
250
+ #
251
+ # Returns nothing.
252
+ def halt!
253
+ @halted ||= true
254
+ end
255
+
256
+ # @api private
257
+ # Determines if this notice will be discarded.
258
+ def halted?
259
+ !!@halted
260
+ end
261
+
249
262
  private
250
263
 
251
264
  attr_reader :config, :opts, :context, :stats, :now, :pid, :causes,
@@ -536,5 +549,6 @@ module Honeybadger
536
549
  @request.session
537
550
  end
538
551
  end
552
+
539
553
  end
540
554
  end
@@ -6,14 +6,16 @@ module Honeybadger
6
6
  module Shoryuken
7
7
  class Middleware
8
8
  def call(_worker, _queue, sqs_msg, body)
9
- begin
10
- yield
11
- rescue => e
12
- if attempt_threshold <= receive_count(sqs_msg)
13
- Honeybadger.notify(e, parameters: notification_params(body))
9
+ Honeybadger.flush do
10
+ begin
11
+ yield
12
+ rescue => e
13
+ if attempt_threshold <= receive_count(sqs_msg)
14
+ Honeybadger.notify(e, parameters: notification_params(body))
15
+ end
16
+
17
+ raise e
14
18
  end
15
-
16
- raise e
17
19
  end
18
20
  ensure
19
21
  Honeybadger.context.clear!
@@ -64,7 +64,7 @@ module Honeybadger
64
64
  # @api private
65
65
  def install_at_exit_callback
66
66
  at_exit do
67
- if $! && !$!.is_a?(SystemExit) && Honeybadger.config[:'exceptions.notify_at_exit']
67
+ if $! && !ignored_exception?($!) && Honeybadger.config[:'exceptions.notify_at_exit']
68
68
  Honeybadger.notify($!, component: 'at_exit', sync: true)
69
69
  end
70
70
 
@@ -85,4 +85,15 @@ module Honeybadger
85
85
  end
86
86
  WARNING
87
87
  end
88
+
89
+ private
90
+ # @api private
91
+ def ignored_exception?(exception)
92
+ exception.is_a?(SystemExit) ||
93
+ ( exception.is_a?(SignalException) &&
94
+ ( (exception.respond_to?(:signm) && exception.signm == "SIGTERM") ||
95
+ # jruby has a missing #signm implementation
96
+ ["TERM", "SIGTERM"].include?(exception.to_s) )
97
+ )
98
+ end
88
99
  end
@@ -1,4 +1,4 @@
1
1
  module Honeybadger
2
2
  # The current String Honeybadger version.
3
- VERSION = '3.3.1'.freeze
3
+ VERSION = '3.4.0.beta1'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: honeybadger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 3.4.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Honeybadger Industries LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-02 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Make managing application errors a more pleasant experience.
14
14
  email:
@@ -138,12 +138,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
138
  version: 2.1.0
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
- - - ">="
141
+ - - ">"
142
142
  - !ruby/object:Gem::Version
143
- version: '0'
143
+ version: 1.3.1
144
144
  requirements: []
145
145
  rubyforge_project:
146
- rubygems_version: 2.6.14
146
+ rubygems_version: 2.7.3
147
147
  signing_key:
148
148
  specification_version: 4
149
149
  summary: Error reports you can be happy about.