bugsnag 6.12.0 → 6.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.buildkite/pipeline.yml +470 -0
  3. data/.rubocop.yml +55 -0
  4. data/.rubocop_todo.yml +530 -160
  5. data/CHANGELOG.md +67 -0
  6. data/CONTRIBUTING.md +1 -9
  7. data/Gemfile +14 -7
  8. data/TESTING.md +81 -0
  9. data/VERSION +1 -1
  10. data/docker-compose.yml +46 -0
  11. data/dockerfiles/Dockerfile.jruby-unit-tests +13 -0
  12. data/dockerfiles/Dockerfile.ruby-maze-runner +26 -0
  13. data/dockerfiles/Dockerfile.ruby-unit-tests +12 -0
  14. data/features/delayed_job.feature +6 -22
  15. data/features/fixtures/delayed_job/Dockerfile +2 -4
  16. data/features/fixtures/delayed_job/app/Gemfile +1 -1
  17. data/features/fixtures/delayed_job/app/Rakefile +18 -0
  18. data/features/fixtures/docker-compose.yml +28 -40
  19. data/features/fixtures/expected_breadcrumbs/active_job.json +9 -0
  20. data/features/fixtures/expected_breadcrumbs/mongo_failed.json +15 -0
  21. data/features/fixtures/expected_breadcrumbs/mongo_filtered_request.json +15 -0
  22. data/features/fixtures/expected_breadcrumbs/mongo_filtered_result.json +15 -0
  23. data/features/fixtures/expected_breadcrumbs/mongo_success.json +14 -0
  24. data/features/fixtures/expected_breadcrumbs/request.json +13 -0
  25. data/features/fixtures/expected_breadcrumbs/sql_with_bindings.json +12 -0
  26. data/features/fixtures/expected_breadcrumbs/sql_without_bindings.json +11 -0
  27. data/features/fixtures/plain/Dockerfile +2 -2
  28. data/features/fixtures/plain/app/app.rb +1 -3
  29. data/features/fixtures/plain/app/delivery/fork_threadpool.rb +3 -1
  30. data/features/fixtures/plain/app/unhandled/{Interrupt.rb → interrupt.rb} +0 -0
  31. data/features/fixtures/rack1/Dockerfile +2 -2
  32. data/features/fixtures/rack2/Dockerfile +2 -2
  33. data/features/fixtures/rails3/Dockerfile +2 -2
  34. data/features/fixtures/rails3/app/Gemfile +4 -0
  35. data/features/fixtures/rails3/app/config/initializers/bugsnag.rb +3 -2
  36. data/features/fixtures/rails4/Dockerfile +2 -5
  37. data/features/fixtures/rails4/app/config/initializers/bugsnag.rb +2 -1
  38. data/features/fixtures/rails5/Dockerfile +2 -2
  39. data/features/fixtures/rails5/app/Gemfile +3 -2
  40. data/features/fixtures/rails5/app/config/initializers/bugsnag.rb +2 -1
  41. data/features/fixtures/rails6/Dockerfile +2 -2
  42. data/features/fixtures/rails6/app/Gemfile +3 -2
  43. data/features/fixtures/rails6/app/app/controllers/mongo_controller.rb +22 -0
  44. data/features/fixtures/rails6/app/app/models/mongo_model.rb +6 -0
  45. data/features/fixtures/rails6/app/config/environments/development.rb +2 -0
  46. data/features/fixtures/rails6/app/config/environments/production.rb +1 -0
  47. data/features/fixtures/rails6/app/config/environments/rails_env.rb +1 -0
  48. data/features/fixtures/rails6/app/config/environments/test.rb +1 -0
  49. data/features/fixtures/rails6/app/config/initializers/bugsnag.rb +2 -1
  50. data/features/fixtures/rails6/app/config/mongoid.yml +23 -0
  51. data/features/fixtures/rails6/app/config/routes.rb +4 -0
  52. data/features/fixtures/resque/Dockerfile +2 -2
  53. data/features/fixtures/sidekiq/Dockerfile +5 -7
  54. data/features/fixtures/sidekiq/app/Gemfile +2 -1
  55. data/features/fixtures/sidekiq/app/Rakefile.rb +14 -0
  56. data/features/fixtures/sinatra1/Dockerfile +2 -2
  57. data/features/fixtures/sinatra2/Dockerfile +2 -2
  58. data/features/plain_features/add_tab.feature +24 -97
  59. data/features/plain_features/app_type.feature +6 -25
  60. data/features/plain_features/app_version.feature +6 -25
  61. data/features/plain_features/auto_notify.feature +4 -20
  62. data/features/plain_features/delivery.feature +12 -60
  63. data/features/plain_features/exception_data.feature +24 -94
  64. data/features/plain_features/filters.feature +9 -43
  65. data/features/plain_features/handled_errors.feature +16 -78
  66. data/features/plain_features/ignore_classes.feature +5 -23
  67. data/features/plain_features/ignore_report.feature +6 -24
  68. data/features/plain_features/proxies.feature +13 -56
  69. data/features/plain_features/release_stages.feature +9 -40
  70. data/features/plain_features/report_api_key.feature +9 -35
  71. data/features/plain_features/report_severity.feature +8 -35
  72. data/features/plain_features/report_stack_frames.feature +24 -92
  73. data/features/plain_features/report_user.feature +23 -96
  74. data/features/plain_features/unhandled_errors.feature +17 -88
  75. data/features/rails_features/api_key.feature +12 -58
  76. data/features/rails_features/app_type.feature +13 -58
  77. data/features/rails_features/app_version.feature +19 -80
  78. data/features/rails_features/auto_capture_sessions.feature +31 -112
  79. data/features/rails_features/auto_notify.feature +28 -105
  80. data/features/rails_features/before_notify.feature +18 -83
  81. data/features/rails_features/breadcrumbs.feature +40 -137
  82. data/features/rails_features/handled.feature +18 -82
  83. data/features/rails_features/ignore_classes.feature +12 -51
  84. data/features/rails_features/meta_data_filters.feature +9 -33
  85. data/features/rails_features/mongo_breadcrumbs.feature +22 -96
  86. data/features/rails_features/project_root.feature +19 -84
  87. data/features/rails_features/release_stage.feature +20 -82
  88. data/features/rails_features/send_code.feature +13 -55
  89. data/features/rails_features/send_environment.feature +7 -33
  90. data/features/rails_features/unhandled.feature +6 -31
  91. data/features/rails_features/user_info.feature +27 -65
  92. data/features/sidekiq.feature +12 -79
  93. data/features/steps/ruby_notifier_steps.rb +59 -15
  94. data/features/support/env.rb +12 -45
  95. data/lib/bugsnag.rb +74 -21
  96. data/lib/bugsnag/breadcrumbs/breadcrumbs.rb +0 -2
  97. data/lib/bugsnag/breadcrumbs/validator.rb +0 -6
  98. data/lib/bugsnag/cleaner.rb +129 -60
  99. data/lib/bugsnag/configuration.rb +31 -2
  100. data/lib/bugsnag/helpers.rb +2 -4
  101. data/lib/bugsnag/integrations/que.rb +7 -4
  102. data/lib/bugsnag/integrations/railtie.rb +1 -1
  103. data/lib/bugsnag/middleware/discard_error_class.rb +30 -0
  104. data/lib/bugsnag/middleware/exception_meta_data.rb +15 -9
  105. data/lib/bugsnag/middleware/ignore_error_class.rb +2 -0
  106. data/lib/bugsnag/middleware/rack_request.rb +2 -4
  107. data/lib/bugsnag/report.rb +3 -13
  108. data/lib/bugsnag/stacktrace.rb +6 -10
  109. data/spec/breadcrumbs/breadcrumb_spec.rb +1 -1
  110. data/spec/breadcrumbs/validator_spec.rb +1 -26
  111. data/spec/bugsnag_spec.rb +2 -2
  112. data/spec/cleaner_spec.rb +202 -10
  113. data/spec/configuration_spec.rb +16 -1
  114. data/spec/fixtures/apps/rails-initializer-config/Gemfile +5 -1
  115. data/spec/fixtures/apps/rails-invalid-initializer-config/Gemfile +5 -1
  116. data/spec/fixtures/apps/rails-no-config/Gemfile +5 -1
  117. data/spec/helper_spec.rb +0 -31
  118. data/spec/integrations/logger_spec.rb +1 -1
  119. data/spec/integrations/rack_spec.rb +8 -6
  120. data/spec/integrations/rake_spec.rb +1 -1
  121. data/spec/report_spec.rb +324 -26
  122. data/spec/spec_helper.rb +6 -1
  123. data/spec/stacktrace_spec.rb +179 -72
  124. metadata +23 -7
  125. data/.travis.yml +0 -117
  126. data/features/plain_features/api_key.feature +0 -25
@@ -33,6 +33,7 @@ require "bugsnag/breadcrumbs/validator"
33
33
  require "bugsnag/breadcrumbs/breadcrumb"
34
34
  require "bugsnag/breadcrumbs/breadcrumbs"
35
35
 
36
+ # rubocop:todo Metrics/ModuleLength
36
37
  module Bugsnag
37
38
  LOCK = Mutex.new
38
39
  INTEGRATIONS = [:resque, :sidekiq, :mailman, :delayed_job, :shoryuken, :que, :mongo]
@@ -63,7 +64,7 @@ module Bugsnag
63
64
  auto_notify = false
64
65
  end
65
66
 
66
- return unless deliver_notification?(exception, auto_notify)
67
+ return unless should_deliver_notification?(exception, auto_notify)
67
68
 
68
69
  exception = NIL_EXCEPTION_DESCRIPTION if exception.nil?
69
70
 
@@ -71,6 +72,7 @@ module Bugsnag
71
72
 
72
73
  # If this is an auto_notify we yield the block before the any middleware is run
73
74
  yield(report) if block_given? && auto_notify
75
+
74
76
  if report.ignore?
75
77
  configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in auto_notify block")
76
78
  return
@@ -97,6 +99,7 @@ module Bugsnag
97
99
  # If this is not an auto_notify then the block was provided by the user. This should be the last
98
100
  # block that is run as it is the users "most specific" block.
99
101
  yield(report) if block_given? && !auto_notify
102
+
100
103
  if report.ignore?
101
104
  configuration.debug("Not notifying #{report.exceptions.last[:errorClass]} due to ignore being signified in user provided block")
102
105
  return
@@ -111,13 +114,7 @@ module Bugsnag
111
114
  report.severity_reason = initial_reason
112
115
  end
113
116
 
114
- # Deliver
115
- configuration.info("Notifying #{configuration.notify_endpoint} of #{report.exceptions.last[:errorClass]}")
116
- options = {:headers => report.headers}
117
- payload = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(report.as_json))
118
- Bugsnag::Delivery[configuration.delivery_method].deliver(configuration.notify_endpoint, payload, configuration, options)
119
- report_summary = report.summary
120
- leave_breadcrumb(report_summary[:error_class], report_summary, Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE, :auto)
117
+ deliver_notification(report)
121
118
  end
122
119
  end
123
120
 
@@ -147,6 +144,7 @@ module Bugsnag
147
144
  # Configuration getters
148
145
  ##
149
146
  # Returns the client's Configuration object, or creates one if not yet created.
147
+ # @return [Configuration]
150
148
  def configuration
151
149
  @configuration = nil unless defined?(@configuration)
152
150
  @configuration || LOCK.synchronize { @configuration ||= Bugsnag::Configuration.new }
@@ -211,27 +209,40 @@ module Bugsnag
211
209
  validator.validate(breadcrumb)
212
210
 
213
211
  # Skip if it's already invalid
214
- unless breadcrumb.ignore?
215
- # Run callbacks
216
- configuration.before_breadcrumb_callbacks.each do |c|
217
- c.arity > 0 ? c.call(breadcrumb) : c.call
218
- break if breadcrumb.ignore?
219
- end
212
+ return if breadcrumb.ignore?
220
213
 
221
- # Return early if ignored
222
- return if breadcrumb.ignore?
214
+ # Run callbacks
215
+ configuration.before_breadcrumb_callbacks.each do |c|
216
+ c.arity > 0 ? c.call(breadcrumb) : c.call
217
+ break if breadcrumb.ignore?
218
+ end
219
+
220
+ # Return early if ignored
221
+ return if breadcrumb.ignore?
223
222
 
224
- # Validate again in case of callback alteration
225
- validator.validate(breadcrumb)
223
+ # Validate again in case of callback alteration
224
+ validator.validate(breadcrumb)
226
225
 
227
- # Add to breadcrumbs buffer if still valid
228
- configuration.breadcrumbs << breadcrumb unless breadcrumb.ignore?
226
+ # Add to breadcrumbs buffer if still valid
227
+ configuration.breadcrumbs << breadcrumb unless breadcrumb.ignore?
228
+ end
229
+
230
+ ##
231
+ # Returns the client's Cleaner object, or creates one if not yet created.
232
+ #
233
+ # @api private
234
+ #
235
+ # @return [Cleaner]
236
+ def cleaner
237
+ @cleaner = nil unless defined?(@cleaner)
238
+ @cleaner || LOCK.synchronize do
239
+ @cleaner ||= Bugsnag::Cleaner.new(configuration)
229
240
  end
230
241
  end
231
242
 
232
243
  private
233
244
 
234
- def deliver_notification?(exception, auto_notify)
245
+ def should_deliver_notification?(exception, auto_notify)
235
246
  reason = abort_reason(exception, auto_notify)
236
247
  configuration.debug(reason) unless reason.nil?
237
248
  reason.nil?
@@ -249,6 +260,32 @@ module Bugsnag
249
260
  end
250
261
  end
251
262
 
263
+ ##
264
+ # Deliver the notification to Bugsnag
265
+ #
266
+ # @param report [Report]
267
+ # @return void
268
+ def deliver_notification(report)
269
+ configuration.info("Notifying #{configuration.notify_endpoint} of #{report.exceptions.last[:errorClass]}")
270
+
271
+ payload = report_to_json(report)
272
+ options = {:headers => report.headers}
273
+
274
+ Bugsnag::Delivery[configuration.delivery_method].deliver(
275
+ configuration.notify_endpoint,
276
+ payload,
277
+ configuration,
278
+ options
279
+ )
280
+
281
+ leave_breadcrumb(
282
+ report.summary[:error_class],
283
+ report.summary,
284
+ Bugsnag::Breadcrumbs::ERROR_BREADCRUMB_TYPE,
285
+ :auto
286
+ )
287
+ end
288
+
252
289
  # Check if the API key is valid and warn (once) if it is not
253
290
  def check_key_valid
254
291
  @key_warning = false unless defined?(@key_warning)
@@ -273,7 +310,23 @@ module Bugsnag
273
310
  raise ArgumentError, "The session endpoint cannot be modified without the notify endpoint"
274
311
  end
275
312
  end
313
+
314
+ ##
315
+ # Convert the Report object to JSON
316
+ #
317
+ # We ensure the report is safe to send by removing recursion, fixing
318
+ # encoding errors and redacting metadata according to "meta_data_filters"
319
+ #
320
+ # @param report [Report]
321
+ # @return string
322
+ def report_to_json(report)
323
+ cleaned = cleaner.clean_object(report.as_json)
324
+ trimmed = Bugsnag::Helpers.trim_if_needed(cleaned)
325
+
326
+ ::JSON.dump(trimmed)
327
+ end
276
328
  end
277
329
  end
330
+ # rubocop:enable Metrics/ModuleLength
278
331
 
279
332
  Bugsnag.load_integrations unless ENV["BUGSNAG_DISABLE_AUTOCONFIGURE"]
@@ -1,6 +1,4 @@
1
1
  module Bugsnag::Breadcrumbs
2
- MAX_NAME_LENGTH = 30
3
-
4
2
  VALID_BREADCRUMB_TYPES = [
5
3
  ERROR_BREADCRUMB_TYPE = "error",
6
4
  MANUAL_BREADCRUMB_TYPE = "manual",
@@ -15,12 +15,6 @@ module Bugsnag::Breadcrumbs
15
15
  #
16
16
  # @param breadcrumb [Bugsnag::Breadcrumbs::Breadcrumb] the breadcrumb to be validated
17
17
  def validate(breadcrumb)
18
- # Check name length
19
- if breadcrumb.name.size > Bugsnag::Breadcrumbs::MAX_NAME_LENGTH
20
- @configuration.debug("Breadcrumb name trimmed to length #{Bugsnag::Breadcrumbs::MAX_NAME_LENGTH}. Original name: #{breadcrumb.name}")
21
- breadcrumb.name = breadcrumb.name.slice(0...Bugsnag::Breadcrumbs::MAX_NAME_LENGTH)
22
- end
23
-
24
18
  # Check meta_data hash doesn't contain complex values
25
19
  breadcrumb.meta_data = breadcrumb.meta_data.select do |k, v|
26
20
  if valid_meta_data_type?(v)
@@ -1,20 +1,76 @@
1
1
  require 'uri'
2
2
 
3
3
  module Bugsnag
4
+ # @api private
4
5
  class Cleaner
5
- ENCODING_OPTIONS = {:invalid => :replace, :undef => :replace}.freeze
6
6
  FILTERED = '[FILTERED]'.freeze
7
7
  RECURSION = '[RECURSION]'.freeze
8
8
  OBJECT = '[OBJECT]'.freeze
9
9
  RAISED = '[RAISED]'.freeze
10
+ OBJECT_WITH_ID_AND_CLASS = '[OBJECT]: [Class]: %<class_name>s [ID]: %<id>d'.freeze
10
11
 
11
- def initialize(filters)
12
- @filters = Array(filters)
13
- @deep_filters = @filters.any? {|f| f.kind_of?(Regexp) && f.to_s.include?("\\.".freeze) }
12
+ ##
13
+ # @param configuration [Configuration]
14
+ def initialize(configuration)
15
+ @configuration = configuration
14
16
  end
15
17
 
16
- def clean_object(obj)
17
- traverse_object(obj, {}, nil)
18
+ def clean_object(object)
19
+ @deep_filters = deep_filters?
20
+
21
+ traverse_object(object, {}, nil)
22
+ end
23
+
24
+ ##
25
+ # @param url [String]
26
+ # @return [String]
27
+ def clean_url(url)
28
+ return url if @configuration.meta_data_filters.empty?
29
+
30
+ uri = URI(url)
31
+ return url unless uri.query
32
+
33
+ query_params = uri.query.split('&').map { |pair| pair.split('=') }
34
+ query_params.map! do |key, val|
35
+ if filters_match?(key)
36
+ "#{key}=#{FILTERED}"
37
+ else
38
+ "#{key}=#{val}"
39
+ end
40
+ end
41
+
42
+ uri.query = query_params.join('&')
43
+ uri.to_s
44
+ end
45
+
46
+ private
47
+
48
+ ##
49
+ # This method calculates whether we need to filter deeply or not; i.e. whether
50
+ # we should match both with and without 'request.params'
51
+ #
52
+ # This is cached on the instance variable '@deep_filters' for performance
53
+ # reasons
54
+ #
55
+ # @return [Boolean]
56
+ def deep_filters?
57
+ @configuration.meta_data_filters.any? do |filter|
58
+ filter.is_a?(Regexp) && filter.to_s.include?("\\.".freeze)
59
+ end
60
+ end
61
+
62
+ def clean_string(str)
63
+ if defined?(str.encoding) && defined?(Encoding::UTF_8)
64
+ if str.encoding == Encoding::UTF_8
65
+ str.valid_encoding? ? str : str.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8')
66
+ else
67
+ str.encode('utf-8', invalid: :replace, undef: :replace)
68
+ end
69
+ elsif defined?(Iconv)
70
+ Iconv.conv('UTF-8//IGNORE', 'UTF-8', str) || str
71
+ else
72
+ str
73
+ end
18
74
  end
19
75
 
20
76
  def traverse_object(obj, seen, scope)
@@ -29,11 +85,22 @@ module Bugsnag
29
85
  value = case obj
30
86
  when Hash
31
87
  clean_hash = {}
32
- obj.each do |k,v|
33
- if filters_match_deeply?(k, scope)
34
- clean_hash[k] = FILTERED
35
- else
36
- clean_hash[k] = traverse_object(v, seen, [scope, k].compact.join('.'))
88
+ obj.each do |k, v|
89
+ begin
90
+ current_scope = [scope, k].compact.join('.')
91
+
92
+ if filters_match_deeply?(k, current_scope)
93
+ clean_hash[k] = FILTERED
94
+ else
95
+ clean_hash[k] = traverse_object(v, seen, current_scope)
96
+ end
97
+ # If we get an error here, we assume the key needs to be filtered
98
+ # to avoid leaking things we shouldn't. We also remove the key itself
99
+ # because it may cause issues later e.g. when being converted to JSON
100
+ rescue StandardError
101
+ clean_hash[RAISED] = FILTERED
102
+ rescue SystemStackError
103
+ clean_hash[RECURSION] = FILTERED
37
104
  end
38
105
  end
39
106
  clean_hash
@@ -44,10 +111,23 @@ module Bugsnag
44
111
  when String
45
112
  clean_string(obj)
46
113
  else
47
- str = obj.to_s rescue RAISED
114
+ # guard against objects that raise or blow the stack when stringified
115
+ begin
116
+ str = obj.to_s
117
+ rescue StandardError
118
+ str = RAISED
119
+ rescue SystemStackError
120
+ str = RECURSION
121
+ end
122
+
48
123
  # avoid leaking potentially sensitive data from objects' #inspect output
49
124
  if str =~ /#<.*>/
50
- OBJECT
125
+ # Use id of the object if available
126
+ if obj.respond_to?(:id)
127
+ format(OBJECT_WITH_ID_AND_CLASS, class_name: obj.class, id: obj.id)
128
+ else
129
+ OBJECT
130
+ end
51
131
  else
52
132
  clean_string(str)
53
133
  end
@@ -57,67 +137,56 @@ module Bugsnag
57
137
  value
58
138
  end
59
139
 
60
- def clean_string(str)
61
- if defined?(str.encoding) && defined?(Encoding::UTF_8)
62
- if str.encoding == Encoding::UTF_8
63
- str.valid_encoding? ? str : str.encode('utf-16', ENCODING_OPTIONS).encode('utf-8')
140
+ ##
141
+ # @param key [String, #to_s]
142
+ # @return [Boolean]
143
+ def filters_match?(key)
144
+ str = key.to_s
145
+
146
+ @configuration.meta_data_filters.any? do |filter|
147
+ case filter
148
+ when Regexp
149
+ str.match(filter)
64
150
  else
65
- str.encode('utf-8', ENCODING_OPTIONS)
151
+ str.include?(filter.to_s)
66
152
  end
67
- elsif defined?(Iconv)
68
- Iconv.conv('UTF-8//IGNORE', 'UTF-8', str) || str
69
- else
70
- str
71
153
  end
72
154
  end
73
155
 
74
- def self.clean_object_encoding(obj)
75
- new(nil).clean_object(obj)
76
- end
156
+ ##
157
+ # If someone has a Rails filter like /^stuff\.secret/, it won't match
158
+ # "request.params.stuff.secret", so we try it both with and without the
159
+ # "request.params." bit.
160
+ #
161
+ # @param key [String, #to_s]
162
+ # @param scope [String]
163
+ # @return [Boolean]
164
+ def filters_match_deeply?(key, scope)
165
+ return false unless scope_should_be_filtered?(scope)
77
166
 
78
- def clean_url(url)
79
- return url if @filters.empty?
167
+ return true if filters_match?(key)
168
+ return false unless @deep_filters
80
169
 
81
- uri = URI(url)
82
- return url unless uri.query
170
+ return true if filters_match?(scope)
83
171
 
84
- query_params = uri.query.split('&').map { |pair| pair.split('=') }
85
- query_params.map! do |key, val|
86
- if filters_match?(key)
87
- "#{key}=#{FILTERED}"
172
+ @configuration.scopes_to_filter.any? do |scope_to_filter|
173
+ if scope.start_with?("#{scope_to_filter}.request.params.")
174
+ filters_match?(scope.sub("#{scope_to_filter}.request.params.", ''))
88
175
  else
89
- "#{key}=#{val}"
176
+ filters_match?(scope.sub("#{scope_to_filter}.", ''))
90
177
  end
91
178
  end
92
-
93
- uri.query = query_params.join('&')
94
- uri.to_s
95
179
  end
96
180
 
97
- private
98
-
99
- def filters_match?(key)
100
- str = key.to_s
101
-
102
- @filters.any? do |f|
103
- case f
104
- when Regexp
105
- str.match(f)
106
- else
107
- str.include?(f.to_s)
108
- end
181
+ ##
182
+ # Should the given scope be filtered?
183
+ #
184
+ # @param scope [String]
185
+ # @return [Boolean]
186
+ def scope_should_be_filtered?(scope)
187
+ @configuration.scopes_to_filter.any? do |scope_to_filter|
188
+ scope.start_with?("#{scope_to_filter}.")
109
189
  end
110
190
  end
111
-
112
- # If someone has a Rails filter like /^stuff\.secret/, it won't match "request.params.stuff.secret",
113
- # so we try it both with and without the "request.params." bit.
114
- def filters_match_deeply?(key, scope)
115
- return true if filters_match?(key)
116
- return false unless @deep_filters
117
-
118
- long = [scope, key].compact.join('.')
119
- short = long.sub(/^request\.params\./, '')
120
- filters_match?(long) || filters_match?(short)
121
- end
122
191
  end
123
192
  end
@@ -3,6 +3,7 @@ require "socket"
3
3
  require "logger"
4
4
  require "bugsnag/middleware_stack"
5
5
  require "bugsnag/middleware/callbacks"
6
+ require "bugsnag/middleware/discard_error_class"
6
7
  require "bugsnag/middleware/exception_meta_data"
7
8
  require "bugsnag/middleware/ignore_error_class"
8
9
  require "bugsnag/middleware/suggestion_data"
@@ -35,9 +36,12 @@ module Bugsnag
35
36
  attr_accessor :timeout
36
37
  attr_accessor :hostname
37
38
  attr_accessor :runtime_versions
38
- attr_accessor :ignore_classes
39
+ attr_accessor :discard_classes
39
40
  attr_accessor :auto_capture_sessions
40
- attr_accessor :track_sessions
41
+
42
+ ##
43
+ # @deprecated Use {#discard_classes} instead
44
+ attr_accessor :ignore_classes
41
45
 
42
46
  ##
43
47
  # @return [String] URL error notifications will be delivered to
@@ -64,6 +68,14 @@ module Bugsnag
64
68
  # @return [Integer] the maximum allowable amount of breadcrumbs per thread
65
69
  attr_reader :max_breadcrumbs
66
70
 
71
+ ##
72
+ # @return [Regexp] matching file paths out of project
73
+ attr_accessor :vendor_path
74
+
75
+ ##
76
+ # @return [Array]
77
+ attr_reader :scopes_to_filter
78
+
67
79
  API_KEY_REGEX = /[0-9a-f]{32}/i
68
80
  THREAD_LOCAL_NAME = "bugsnag_req_data"
69
81
 
@@ -82,6 +94,11 @@ module Bugsnag
82
94
 
83
95
  DEFAULT_MAX_BREADCRUMBS = 25
84
96
 
97
+ # Path to vendored code. Used to mark file paths as out of project.
98
+ DEFAULT_VENDOR_PATH = %r{^(vendor/|\.bundle/)}
99
+
100
+ DEFAULT_SCOPES_TO_FILTER = ['events.metaData', 'events.breadcrumbs.metaData'].freeze
101
+
85
102
  alias :track_sessions :auto_capture_sessions
86
103
  alias :track_sessions= :auto_capture_sessions=
87
104
 
@@ -93,6 +110,7 @@ module Bugsnag
93
110
  self.send_environment = false
94
111
  self.send_code = true
95
112
  self.meta_data_filters = Set.new(DEFAULT_META_DATA_FILTERS)
113
+ self.scopes_to_filter = DEFAULT_SCOPES_TO_FILTER
96
114
  self.hostname = default_hostname
97
115
  self.runtime_versions = {}
98
116
  self.runtime_versions["ruby"] = RUBY_VERSION
@@ -116,7 +134,10 @@ module Bugsnag
116
134
 
117
135
  # SystemExit and SignalException are common Exception types seen with
118
136
  # successful exits and are not automatically reported to Bugsnag
137
+ # TODO move these defaults into `discard_classes` when `ignore_classes`
138
+ # is removed
119
139
  self.ignore_classes = Set.new([SystemExit, SignalException])
140
+ self.discard_classes = Set.new([])
120
141
 
121
142
  # Read the API key from the environment
122
143
  self.api_key = ENV["BUGSNAG_API_KEY"]
@@ -126,6 +147,11 @@ module Bugsnag
126
147
  parse_proxy(proxy_uri)
127
148
  end
128
149
 
150
+ # Set up vendor_path regex to mark stacktrace file paths as out of project.
151
+ # Stacktrace lines that matches regex will be marked as "out of project"
152
+ # will only appear in the full trace.
153
+ self.vendor_path = DEFAULT_VENDOR_PATH
154
+
129
155
  # Set up logging
130
156
  self.logger = Logger.new(STDOUT)
131
157
  self.logger.level = Logger::INFO
@@ -136,6 +162,7 @@ module Bugsnag
136
162
  # Configure the bugsnag middleware stack
137
163
  self.internal_middleware = Bugsnag::MiddlewareStack.new
138
164
  self.internal_middleware.use Bugsnag::Middleware::ExceptionMetaData
165
+ self.internal_middleware.use Bugsnag::Middleware::DiscardErrorClass
139
166
  self.internal_middleware.use Bugsnag::Middleware::IgnoreErrorClass
140
167
  self.internal_middleware.use Bugsnag::Middleware::SuggestionData
141
168
  self.internal_middleware.use Bugsnag::Middleware::ClassifyError
@@ -293,6 +320,8 @@ module Bugsnag
293
320
 
294
321
  private
295
322
 
323
+ attr_writer :scopes_to_filter
324
+
296
325
  PROG_NAME = "[Bugsnag]"
297
326
 
298
327
  def default_hostname