airbrake-ruby 2.9.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/airbrake-ruby.rb +40 -18
  3. data/lib/airbrake-ruby/async_sender.rb +0 -6
  4. data/lib/airbrake-ruby/backtrace.rb +0 -10
  5. data/lib/airbrake-ruby/code_hunk.rb +0 -4
  6. data/lib/airbrake-ruby/config.rb +23 -22
  7. data/lib/airbrake-ruby/config/validator.rb +0 -10
  8. data/lib/airbrake-ruby/file_cache.rb +0 -6
  9. data/lib/airbrake-ruby/filter_chain.rb +0 -5
  10. data/lib/airbrake-ruby/filters/context_filter.rb +1 -0
  11. data/lib/airbrake-ruby/filters/dependency_filter.rb +31 -0
  12. data/lib/airbrake-ruby/filters/exception_attributes_filter.rb +45 -0
  13. data/lib/airbrake-ruby/filters/gem_root_filter.rb +2 -3
  14. data/lib/airbrake-ruby/filters/keys_blacklist.rb +1 -2
  15. data/lib/airbrake-ruby/filters/keys_filter.rb +9 -14
  16. data/lib/airbrake-ruby/filters/keys_whitelist.rb +0 -2
  17. data/lib/airbrake-ruby/filters/root_directory_filter.rb +2 -3
  18. data/lib/airbrake-ruby/filters/system_exit_filter.rb +2 -3
  19. data/lib/airbrake-ruby/filters/thread_filter.rb +2 -4
  20. data/lib/airbrake-ruby/nested_exception.rb +0 -2
  21. data/lib/airbrake-ruby/notice.rb +6 -44
  22. data/lib/airbrake-ruby/notifier.rb +4 -40
  23. data/lib/airbrake-ruby/promise.rb +0 -6
  24. data/lib/airbrake-ruby/response.rb +0 -4
  25. data/lib/airbrake-ruby/sync_sender.rb +0 -4
  26. data/lib/airbrake-ruby/version.rb +1 -3
  27. data/spec/airbrake_spec.rb +71 -140
  28. data/spec/async_sender_spec.rb +9 -0
  29. data/spec/config_spec.rb +4 -0
  30. data/spec/filters/dependency_filter_spec.rb +16 -0
  31. data/spec/filters/exception_attributes_filter_spec.rb +65 -0
  32. data/spec/filters/keys_whitelist_spec.rb +17 -23
  33. data/spec/notice_spec.rb +111 -69
  34. data/spec/notifier_spec.rb +304 -495
  35. data/spec/response_spec.rb +82 -0
  36. data/spec/sync_sender_spec.rb +31 -14
  37. metadata +10 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a9ac80f76081013e1f710824cbe72291d26bda5
4
- data.tar.gz: a665035c27cdbbdea9cb7bef43b43931be5266f9
3
+ metadata.gz: 706d644022c1c9c99dc3e01584d0e405411d2159
4
+ data.tar.gz: 56b17f05ad9e78e0579e20a58dfbeef86e35ec54
5
5
  SHA512:
6
- metadata.gz: bc673d309a343d6b15d533e1feb4e202fcc1bb3ca31f2ef79e9af257fedd831614874c0efcfd32b88155a28448cd04affa4117567843972f594fe7a4dda77a80
7
- data.tar.gz: 9e92da2e216c266de65d35c309eed96791eadd6f7e89aca0ebd9e643e49630970b0c41e7da94f15e31cafd65c7f6131668b1a7b41174a44caad94a15eaf665a9
6
+ metadata.gz: 8ee8b4959b41efcc3687f16a5d6ec145644bb8b28b5e3b9fd18dbb9eb729a712708cf082b0afdd0f1ccf12b150974dda5563a535b1a3229e1d8e0ecbd7df7f8b
7
+ data.tar.gz: dbfbf97c9f39401e42d2cd00438616432e1acf9d87a07742c0aa7b405691debd2289b955779fa76dd5dd86f5656043538e25791af06c040100f07672d5399ad8
@@ -24,12 +24,13 @@ require 'airbrake-ruby/filters/system_exit_filter'
24
24
  require 'airbrake-ruby/filters/root_directory_filter'
25
25
  require 'airbrake-ruby/filters/thread_filter'
26
26
  require 'airbrake-ruby/filters/context_filter'
27
+ require 'airbrake-ruby/filters/exception_attributes_filter'
28
+ require 'airbrake-ruby/filters/dependency_filter'
27
29
  require 'airbrake-ruby/filter_chain'
28
30
  require 'airbrake-ruby/notifier'
29
31
  require 'airbrake-ruby/code_hunk'
30
32
  require 'airbrake-ruby/file_cache'
31
33
 
32
- ##
33
34
  # This module defines the Airbrake API. The user is meant to interact with
34
35
  # Airbrake via its public class methods. Before using the library, you must to
35
36
  # {configure} the default notifier.
@@ -64,44 +65,73 @@ require 'airbrake-ruby/file_cache'
64
65
  # @see Airbrake::Notifier
65
66
  # @since v1.0.0
66
67
  module Airbrake
67
- ##
68
68
  # The general error that this library uses when it wants to raise.
69
69
  Error = Class.new(StandardError)
70
70
 
71
- ##
72
71
  # @return [String] the label to be prepended to the log output
73
72
  LOG_LABEL = '**Airbrake:'.freeze
74
73
 
75
- ##
76
74
  # @return [Boolean] true if current Ruby is Ruby 2.0.*. The result is used
77
75
  # for special cases where we need to work around older implementations
78
76
  RUBY_20 = RUBY_VERSION.start_with?('2.0')
79
77
 
80
- ##
81
78
  # @return [Boolean] true if current Ruby is JRuby. The result is used for
82
79
  # special cases where we need to work around older implementations
83
80
  JRUBY = (RUBY_ENGINE == 'jruby')
84
81
 
85
- ##
82
+ # @!macro see_public_api_method
83
+ # @see Airbrake.$0
84
+
85
+ # NilNotifier is a no-op notifier, which mimics +Airbrake::Notifier+ and
86
+ # serves only for the purpose of making the library API easier to use.
87
+ #
88
+ # @since 2.1.0
89
+ class NilNotifier
90
+ # @macro see_public_api_method
91
+ def notify(_exception, _params = {}, &block); end
92
+
93
+ # @macro see_public_api_method
94
+ def notify_sync(_exception, _params = {}, &block); end
95
+
96
+ # @macro see_public_api_method
97
+ def add_filter(_filter = nil, &_block); end
98
+
99
+ # @macro see_public_api_method
100
+ def build_notice(_exception, _params = {}); end
101
+
102
+ # @macro see_public_api_method
103
+ def close; end
104
+
105
+ # @macro see_public_api_method
106
+ def create_deploy(_deploy_params); end
107
+
108
+ # @macro see_public_api_method
109
+ def configured?
110
+ false
111
+ end
112
+
113
+ # @macro see_public_api_method
114
+ def merge_context(_context); end
115
+ end
116
+
86
117
  # A Hash that holds all notifiers. The keys of the Hash are notifier
87
118
  # names, the values are Airbrake::Notifier instances. If a notifier is not
88
119
  # assigned to the hash, then it returns a null object (NilNotifier).
89
120
  @notifiers = Hash.new(NilNotifier.new)
90
121
 
91
122
  class << self
92
- ##
93
123
  # Retrieves configured notifiers.
94
124
  #
95
125
  # @example
96
126
  # Airbrake[:my_notifier].notify('oops')
97
127
  #
98
- # @return [Airbrake::Notifier, nil]
128
+ # @param [Symbol] notifier_name the name of the notifier you want to use
129
+ # @return [Airbrake::Notifier, NilClass]
99
130
  # @since v1.8.0
100
131
  def [](notifier_name)
101
132
  @notifiers[notifier_name]
102
133
  end
103
134
 
104
- ##
105
135
  # Configures a new +notifier+ with the given name. If the name is not given,
106
136
  # configures the default notifier.
107
137
  #
@@ -138,14 +168,12 @@ module Airbrake
138
168
  end
139
169
  end
140
170
 
141
- ##
142
171
  # @return [Boolean] true if the notifier was configured, false otherwise
143
172
  # @since 2.3.0
144
173
  def configured?
145
174
  @notifiers[:default].configured?
146
175
  end
147
176
 
148
- ##
149
177
  # Sends an exception to Airbrake asynchronously.
150
178
  #
151
179
  # @example Sending an exception
@@ -171,7 +199,6 @@ module Airbrake
171
199
  @notifiers[:default].notify(exception, params, &block)
172
200
  end
173
201
 
174
- ##
175
202
  # Sends an exception to Airbrake synchronously.
176
203
  #
177
204
  # @example
@@ -192,7 +219,6 @@ module Airbrake
192
219
  @notifiers[:default].notify_sync(exception, params, &block)
193
220
  end
194
221
 
195
- ##
196
222
  # Runs a callback before {.notify} or {.notify_sync} kicks in. This is
197
223
  # useful if you want to ignore specific notices or filter the data the
198
224
  # notice contains.
@@ -222,7 +248,6 @@ module Airbrake
222
248
  @notifiers[:default].add_filter(filter, &block)
223
249
  end
224
250
 
225
- ##
226
251
  # Builds an Airbrake notice. This is useful, if you want to add or modify a
227
252
  # value only for a specific notice. When you're done modifying the notice,
228
253
  # send it with {.notify} or {.notify_sync}.
@@ -241,7 +266,6 @@ module Airbrake
241
266
  @notifiers[:default].build_notice(exception, params)
242
267
  end
243
268
 
244
- ##
245
269
  # Makes the notifier a no-op, which means you cannot use the {.notify} and
246
270
  # {.notify_sync} methods anymore. It also stops the notifier's worker
247
271
  # threads.
@@ -255,7 +279,6 @@ module Airbrake
255
279
  @notifiers[:default].close
256
280
  end
257
281
 
258
- ##
259
282
  # Pings the Airbrake Deploy API endpoint about the occurred deploy. This
260
283
  # method is used by the airbrake gem for various integrations.
261
284
  #
@@ -270,7 +293,6 @@ module Airbrake
270
293
  @notifiers[:default].create_deploy(deploy_params)
271
294
  end
272
295
 
273
- ##
274
296
  # Merges +context+ with the current context.
275
297
  #
276
298
  # The context will be attached to the notice object upon a notify call and
@@ -287,7 +309,7 @@ module Airbrake
287
309
  # Airbrake.notify('fruitception')
288
310
  # end
289
311
  #
290
- # def load_veggies
312
+ # def load_veggies(veggies)
291
313
  # Airbrake.merge_context(veggies: veggies)
292
314
  # end
293
315
  #
@@ -1,5 +1,4 @@
1
1
  module Airbrake
2
- ##
3
2
  # Responsible for sending notices to Airbrake asynchronously. The class
4
3
  # supports an unlimited number of worker threads and an unlimited queue size
5
4
  # (both values are configurable).
@@ -8,7 +7,6 @@ module Airbrake
8
7
  # @api private
9
8
  # @since v1.0.0
10
9
  class AsyncSender
11
- ##
12
10
  # @param [Airbrake::Config] config
13
11
  def initialize(config)
14
12
  @config = config
@@ -20,7 +18,6 @@ module Airbrake
20
18
  @pid = nil
21
19
  end
22
20
 
23
- ##
24
21
  # Asynchronously sends a notice to Airbrake.
25
22
  #
26
23
  # @param [Airbrake::Notice] notice A notice that was generated by the
@@ -33,7 +30,6 @@ module Airbrake
33
30
  promise
34
31
  end
35
32
 
36
- ##
37
33
  # Closes the instance making it a no-op (it shut downs all worker
38
34
  # threads). Before closing, waits on all unsent notices to be sent.
39
35
  #
@@ -57,14 +53,12 @@ module Airbrake
57
53
  @config.logger.debug("#{LOG_LABEL} closed")
58
54
  end
59
55
 
60
- ##
61
56
  # Checks whether the sender is closed and thus usable.
62
57
  # @return [Boolean]
63
58
  def closed?
64
59
  @closed
65
60
  end
66
61
 
67
- ##
68
62
  # Checks if an active sender has any workers. A sender doesn't have any
69
63
  # workers only in two cases: when it was closed or when all workers
70
64
  # crashed. An *active* sender doesn't have any workers only when something
@@ -1,5 +1,4 @@
1
1
  module Airbrake
2
- ##
3
2
  # Represents a cross-Ruby backtrace from exceptions (including JRuby Java
4
3
  # exceptions). Provides information about stack frames (such as line number,
5
4
  # file and method) in convenient for Airbrake format.
@@ -15,7 +14,6 @@ module Airbrake
15
14
  # @since v1.0.0
16
15
  module Backtrace
17
16
  module Patterns
18
- ##
19
17
  # @return [Regexp] the pattern that matches standard Ruby stack frames,
20
18
  # such as ./spec/notice_spec.rb:43:in `block (3 levels) in <top (required)>'
21
19
  RUBY = %r{\A
@@ -26,7 +24,6 @@ module Airbrake
26
24
  `(?<function>.*)' # Matches "`block (3 levels) in <top (required)>'"
27
25
  \z}x
28
26
 
29
- ##
30
27
  # @return [Regexp] the pattern that matches JRuby Java stack frames, such
31
28
  # as org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
32
29
  JAVA = %r{\A
@@ -44,7 +41,6 @@ module Airbrake
44
41
  \)
45
42
  \z}x
46
43
 
47
- ##
48
44
  # @return [Regexp] the pattern that tries to assume what a generic stack
49
45
  # frame might look like, when exception's backtrace is set manually.
50
46
  GENERIC = %r{\A
@@ -59,7 +55,6 @@ module Airbrake
59
55
  )? # ... or nothing
60
56
  \z}x
61
57
 
62
- ##
63
58
  # @return [Regexp] the pattern that matches exceptions from PL/SQL such as
64
59
  # ORA-06512: at "STORE.LI_LICENSES_PACK", line 1945
65
60
  # @note This is raised by https://github.com/kubo/ruby-oci8
@@ -74,7 +69,6 @@ module Airbrake
74
69
  )
75
70
  \z/x
76
71
 
77
- ##
78
72
  # @return [Regexp] the pattern that matches CoffeeScript backtraces
79
73
  # usually coming from Rails & ExecJS
80
74
  EXECJS = /\A
@@ -90,17 +84,14 @@ module Airbrake
90
84
  )
91
85
  \z/x
92
86
 
93
- ##
94
87
  # @return [Regexp] +EXECJS+ pattern without named captures and
95
88
  # uncommon frames
96
89
  EXECJS_SIMPLIFIED = /\A.+ \(.+:\d+:\d+\)\z/
97
90
  end
98
91
 
99
- ##
100
92
  # @return [Integer] how many first frames should include code hunks
101
93
  CODE_FRAME_LIMIT = 10
102
94
 
103
- ##
104
95
  # Parses an exception's backtrace.
105
96
  #
106
97
  # @param [Exception] exception The exception, which contains a backtrace to
@@ -111,7 +102,6 @@ module Airbrake
111
102
  parse_backtrace(config, exception)
112
103
  end
113
104
 
114
- ##
115
105
  # Checks whether the given exception was generated by JRuby's VM.
116
106
  #
117
107
  # @param [Exception] exception
@@ -1,14 +1,11 @@
1
1
  module Airbrake
2
- ##
3
2
  # Represents a small hunk of code consisting of a base line and a couple lines
4
3
  # around it
5
4
  # @api private
6
5
  class CodeHunk
7
- ##
8
6
  # @return [Integer] the maximum length of a line
9
7
  MAX_LINE_LEN = 200
10
8
 
11
- ##
12
9
  # @return [Integer] how many lines should be read around the base line
13
10
  NLINES = 2
14
11
 
@@ -16,7 +13,6 @@ module Airbrake
16
13
  @config = config
17
14
  end
18
15
 
19
- ##
20
16
  # @param [String] file The file to read
21
17
  # @param [Integer] line The base line in the file
22
18
  # @return [Hash{Integer=>String}, nil] lines of code around the base line
@@ -1,84 +1,88 @@
1
1
  module Airbrake
2
- ##
3
2
  # Represents the Airbrake config. A config contains all the options that you
4
3
  # can use to configure an Airbrake instance.
5
4
  #
6
5
  # @api private
7
6
  # @since v1.0.0
8
7
  class Config
9
- ##
10
8
  # @return [Integer] the project identificator. This value *must* be set.
9
+ # @api public
11
10
  attr_accessor :project_id
12
11
 
13
- ##
14
12
  # @return [String] the project key. This value *must* be set.
13
+ # @api public
15
14
  attr_accessor :project_key
16
15
 
17
- ##
18
16
  # @return [Hash] the proxy parameters such as (:host, :port, :user and
19
17
  # :password)
18
+ # @api public
20
19
  attr_accessor :proxy
21
20
 
22
- ##
23
21
  # @return [Logger] the default logger used for debug output
22
+ # @api public
24
23
  attr_reader :logger
25
24
 
26
- ##
27
25
  # @return [String] the version of the user's application
26
+ # @api public
28
27
  attr_accessor :app_version
29
28
 
30
- ##
29
+ # @return [Hash{String=>String}] arbitrary versions that your app wants to
30
+ # track
31
+ # @api public
32
+ # @since v2.10.0
33
+ attr_accessor :versions
34
+
31
35
  # @return [Integer] the max number of notices that can be queued up
36
+ # @api public
32
37
  attr_accessor :queue_size
33
38
 
34
- ##
35
39
  # @return [Integer] the number of worker threads that process the notice
36
40
  # queue
41
+ # @api public
37
42
  attr_accessor :workers
38
43
 
39
- ##
40
44
  # @return [String] the host, which provides the API endpoint to which
41
45
  # exceptions should be sent
46
+ # @api public
42
47
  attr_accessor :host
43
48
 
44
- ##
45
49
  # @return [String, Pathname] the working directory of your project
50
+ # @api public
46
51
  attr_accessor :root_directory
47
52
 
48
- ##
49
53
  # @return [String, Symbol] the environment the application is running in
54
+ # @api public
50
55
  attr_accessor :environment
51
56
 
52
- ##
53
57
  # @return [Array<String,Symbol,Regexp>] the array of environments that
54
58
  # forbids sending exceptions when the application is running in them.
55
59
  # Other possible environments not listed in the array will allow sending
56
60
  # occurring exceptions.
61
+ # @api public
57
62
  attr_accessor :ignore_environments
58
63
 
59
- ##
60
64
  # @return [Integer] The HTTP timeout in seconds.
65
+ # @api public
61
66
  attr_accessor :timeout
62
67
 
63
- ##
64
68
  # @return [Array<String, Symbol, Regexp>] the keys, which should be
65
69
  # filtered
70
+ # @api public
66
71
  # @since 1.2.0
67
72
  attr_accessor :blacklist_keys
68
73
 
69
- ##
70
74
  # @return [Array<String, Symbol, Regexp>] the keys, which shouldn't be
71
75
  # filtered
76
+ # @api public
72
77
  # @since 1.2.0
73
78
  attr_accessor :whitelist_keys
74
79
 
75
- ##
76
80
  # @return [Boolean] true if the library should attach code hunks to each
77
81
  # frame in a backtrace, false otherwise
82
+ # @api public
78
83
  # @since v2.5.0
79
84
  attr_accessor :code_hunks
80
85
 
81
- ##
82
86
  # @param [Hash{Symbol=>Object}] user_config the hash to be used to build the
83
87
  # config
84
88
  def initialize(user_config = {})
@@ -108,10 +112,11 @@ module Airbrake
108
112
  Dir.pwd
109
113
  )
110
114
 
115
+ self.versions = {}
116
+
111
117
  merge(user_config)
112
118
  end
113
119
 
114
- ##
115
120
  # The full URL to the Airbrake Notice API. Based on the +:host+ option.
116
121
  # @return [URI] the endpoint address
117
122
  def endpoint
@@ -123,14 +128,12 @@ module Airbrake
123
128
  end
124
129
  end
125
130
 
126
- ##
127
131
  # Sets the logger. Never allows to assign `nil` as the logger.
128
132
  # @return [Logger] the logger
129
133
  def logger=(logger)
130
134
  @logger = logger || @logger
131
135
  end
132
136
 
133
- ##
134
137
  # Merges the given +config_hash+ with itself.
135
138
  #
136
139
  # @example
@@ -142,7 +145,6 @@ module Airbrake
142
145
  self
143
146
  end
144
147
 
145
- ##
146
148
  # @return [Boolean] true if the config meets the requirements, false
147
149
  # otherwise
148
150
  def valid?
@@ -159,7 +161,6 @@ module Airbrake
159
161
  @validator.error_message
160
162
  end
161
163
 
162
- ##
163
164
  # @return [Boolean] true if the config ignores current environment, false
164
165
  # otherwise
165
166
  def ignored_environment?