honeybadger 5.11.2 → 5.13.0

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: 813dfdf1a43afbda28fccbf5ca274be2885fc200dd8b2e321adb787d0f694ea3
4
- data.tar.gz: f795d061be6e757e59f756945a5e30a3660ea8989d28a4196f59aac86556e88e
3
+ metadata.gz: 02da7e28bdfb138d80a3e8e3e591d45383406fac1676ed04f0df139125e56247
4
+ data.tar.gz: 2c08c2e0e4e42ea9b7532c09f28f8d1c60a4944dab1e0d1ebc277becb58f8947
5
5
  SHA512:
6
- metadata.gz: f25e69a2e9307269cdee018c6ed02a852fd2974137e3074592d7aed6c11cb635cf278f4726478a3187e50f0e807fbbc5d7b4a8de007e02432a8f405e6e889a0b
7
- data.tar.gz: 0cf8de2539c8ce2f2e044ffd86e1db2d0ee6713aec7b6823036796a6431f0a769ee3458b9e20f673a542ccb264fe5d9d4b7254c7a2be603ddda981c57911eb5c
6
+ metadata.gz: cd07b8f3bfe423336690f00dc80addfb4fbda2db27bbcca0739204888b1565455ea09cbb6d5e643162f00c247ce09ff867e3eab0d71d7f59ca8d39bfc26164cd
7
+ data.tar.gz: 93e0ad66065c9be2c216e69a0d631effe6ba795ff90f328bf05a24bd2d45b60369e1cf3df4b0fc15478c7a73ec497a8661265bdb3daf52b39668117a7b123c9b
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Change Log
2
2
 
3
3
 
4
+ ## [5.13.0](https://github.com/honeybadger-io/honeybadger-ruby/compare/v5.12.0...v5.13.0) (2024-06-18)
5
+
6
+
7
+ ### Features
8
+
9
+ * add before_event hook for intercepting events ([#567](https://github.com/honeybadger-io/honeybadger-ruby/issues/567)) ([2f86728](https://github.com/honeybadger-io/honeybadger-ruby/commit/2f8672814af3b12b3bfbc775de63b7a34b5087ad))
10
+
11
+ ## [5.12.0](https://github.com/honeybadger-io/honeybadger-ruby/compare/v5.11.2...v5.12.0) (2024-06-17)
12
+
13
+
14
+ ### Features
15
+
16
+ * add --insights flag to install command ([#564](https://github.com/honeybadger-io/honeybadger-ruby/issues/564)) ([02a41c6](https://github.com/honeybadger-io/honeybadger-ruby/commit/02a41c67e4b33012057e4ae4c2bd23ca8c13c99b))
17
+
4
18
  ## [5.11.2](https://github.com/honeybadger-io/honeybadger-ruby/compare/v5.11.1...v5.11.2) (2024-06-12)
5
19
 
6
20
 
@@ -4,6 +4,7 @@ require 'honeybadger/version'
4
4
  require 'honeybadger/config'
5
5
  require 'honeybadger/context_manager'
6
6
  require 'honeybadger/notice'
7
+ require 'honeybadger/event'
7
8
  require 'honeybadger/plugin'
8
9
  require 'honeybadger/logging'
9
10
  require 'honeybadger/worker'
@@ -392,28 +393,21 @@ module Honeybadger
392
393
  def event(event_type, payload = {})
393
394
  init_events_worker
394
395
 
395
- ts = Time.now.utc.strftime("%FT%T.%LZ")
396
- merged = {ts: ts}
397
-
398
- if event_type.is_a?(String)
399
- merged[:event_type] = event_type
400
- else
401
- merged.merge!(Hash(event_type))
396
+ extra_payload = {}.tap do |p|
397
+ p[:request_id] = context_manager.get_request_id if context_manager.get_request_id
398
+ p[:hostname] = config[:hostname].to_s if config[:'events.attach_hostname']
402
399
  end
403
400
 
404
- if (request_id = context_manager.get_request_id)
405
- merged[:request_id] = request_id
406
- end
401
+ event = Event.new(event_type, extra_payload.merge(payload))
407
402
 
408
- if config[:'events.attach_hostname']
409
- merged[:hostname] = config[:hostname].to_s
403
+ config.before_event_hooks.each do |hook|
404
+ with_error_handling { hook.call(event) }
410
405
  end
411
406
 
412
- merged.merge!(Hash(payload))
413
-
414
- return if config.ignored_events.any? { |check| merged[:event_type]&.match?(check) }
407
+ return if config.ignored_events.any? { |check| event.event_type&.match?(check) }
408
+ return if event.halted?
415
409
 
416
- events_worker.push(merged)
410
+ events_worker.push(event.as_json)
417
411
  end
418
412
 
419
413
  # @api private
@@ -590,7 +584,7 @@ module Honeybadger
590
584
  def with_error_handling
591
585
  yield
592
586
  rescue => ex
593
- error { "Rescued an error in a before notify hook: #{ex.message}" }
587
+ error { "Rescued an error in a before hook: #{ex.message}" }
594
588
  end
595
589
 
596
590
  @instance = new(Config.new)
@@ -73,6 +73,10 @@ development_environments:
73
73
 
74
74
  # Enable verbose debug logging (useful for troubleshooting).
75
75
  debug: false
76
+
77
+ # Enable Honeybadger Insights
78
+ insights:
79
+ enabled: #{options["insights"]}
76
80
  CONFIG
77
81
  end
78
82
  end
@@ -48,6 +48,7 @@ WELCOME
48
48
  end
49
49
 
50
50
  desc 'install API_KEY', 'Install Honeybadger into a new project'
51
+ option :insights, type: :boolean, aliases: :'-i', default: false, desc: 'Enable Honeybadger Insights'
51
52
  def install(api_key)
52
53
  Install.new(options, api_key).run
53
54
  rescue => e
@@ -89,15 +89,27 @@ module Honeybadger
89
89
  def before_notify(action = nil, &block)
90
90
  hooks = Array(get(:before_notify)).dup
91
91
 
92
- if action && validate_before_action(action)
92
+ if action && validate_before_action(action, 'notify')
93
93
  hooks << action
94
- elsif block_given? && validate_before_action(block)
94
+ elsif block_given? && validate_before_action(block, 'notify')
95
95
  hooks << block
96
96
  end
97
97
 
98
98
  hash[:before_notify] = hooks
99
99
  end
100
100
 
101
+ def before_event(action = nil, &block)
102
+ hooks = Array(get(:before_event)).dup
103
+
104
+ if action && validate_before_action(action, 'event')
105
+ hooks << action
106
+ elsif block_given? && validate_before_action(block, 'event')
107
+ hooks << block
108
+ end
109
+
110
+ hash[:before_event] = hooks
111
+ end
112
+
101
113
  def backtrace_filter(&block)
102
114
  if block_given?
103
115
  logger.warn('DEPRECATED: backtrace_filter is deprecated. Please use before_notify instead. See https://docs.honeybadger.io/ruby/support/v4-upgrade#backtrace_filter')
@@ -127,17 +139,17 @@ module Honeybadger
127
139
 
128
140
  private
129
141
 
130
- def validate_before_action(action)
142
+ def validate_before_action(action, type)
131
143
  if !action.respond_to?(:call)
132
144
  logger.warn(
133
- 'You attempted to add a before notify hook that does not respond ' \
145
+ "You attempted to add a before #{type} hook that does not respond " \
134
146
  'to #call. We are discarding this hook so your intended behavior ' \
135
147
  'will not occur.'
136
148
  )
137
149
  false
138
150
  elsif action.arity != 1
139
151
  logger.warn(
140
- 'You attempted to add a before notify hook that has an arity ' \
152
+ "You attempted to add a before #{type} hook that has an arity " \
141
153
  'other than one. We are discarding this hook so your intended ' \
142
154
  'behavior will not occur.'
143
155
  )
@@ -92,6 +92,10 @@ module Honeybadger
92
92
  (ruby[:before_notify] || []).clone
93
93
  end
94
94
 
95
+ def before_event_hooks
96
+ (ruby[:before_event] || []).clone
97
+ end
98
+
95
99
  def exception_filter(&block)
96
100
  if block_given?
97
101
  warn('DEPRECATED: exception_filter is deprecated. Please use before_notify instead. See https://docs.honeybadger.io/ruby/support/v4-upgrade#exception_filter')
@@ -0,0 +1,56 @@
1
+ require 'forwardable'
2
+
3
+ module Honeybadger
4
+ class Event
5
+ extend Forwardable
6
+
7
+ # The timestamp of the event
8
+ attr_reader :ts
9
+
10
+ # The event_type of the event
11
+ attr_reader :event_type
12
+
13
+ # The payload data of the event
14
+ attr_reader :payload
15
+
16
+ def_delegator :payload, :[]
17
+
18
+ # @api private
19
+ def initialize(event_type_or_payload, payload={})
20
+ if event_type_or_payload.is_a?(String)
21
+ @event_type = event_type_or_payload
22
+ @payload = payload
23
+ elsif event_type_or_payload.is_a?(Hash)
24
+ @event_type = event_type_or_payload[:event_type] || event_type_or_payload["event_type"]
25
+ @payload = event_type_or_payload
26
+ end
27
+
28
+ @ts = payload[:ts] || Time.now.utc.strftime("%FT%T.%LZ")
29
+ @halted = false
30
+ end
31
+
32
+ # Halts the event and the before_event callback chain.
33
+ #
34
+ # Returns nothing.
35
+ def halt!
36
+ @halted ||= true
37
+ end
38
+
39
+ # @api private
40
+ # Determines if this event will be discarded.
41
+ def halted?
42
+ !!@halted
43
+ end
44
+
45
+ # @api private
46
+ # Template used to create JSON payload.
47
+ #
48
+ # @return [Hash] JSON representation of the event.
49
+ def as_json(*args)
50
+ payload.tap do |p|
51
+ p[:ts] = ts
52
+ p[:event_type] = event_type if event_type
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,4 +1,4 @@
1
1
  module Honeybadger
2
2
  # The current String Honeybadger version.
3
- VERSION = '5.11.2'.freeze
3
+ VERSION = '5.13.0'.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: 5.11.2
4
+ version: 5.13.0
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: 2024-06-12 00:00:00.000000000 Z
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Make managing application errors a more pleasant experience.
14
14
  email:
@@ -56,6 +56,7 @@ files:
56
56
  - lib/honeybadger/context_manager.rb
57
57
  - lib/honeybadger/conversions.rb
58
58
  - lib/honeybadger/counter.rb
59
+ - lib/honeybadger/event.rb
59
60
  - lib/honeybadger/events_worker.rb
60
61
  - lib/honeybadger/gauge.rb
61
62
  - lib/honeybadger/histogram.rb