sentry-raven 3.0.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/.craft.yml +15 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +32 -0
  4. data/.github/pull_request_template.md +16 -0
  5. data/.github/workflows/test.yml +92 -0
  6. data/.github/workflows/zeus_upload.yml +32 -0
  7. data/.gitignore +3 -0
  8. data/.rubocop.yml +50 -12
  9. data/.scripts/bump-version.sh +9 -0
  10. data/{changelog.md → CHANGELOG.md} +163 -1
  11. data/CONTRIBUTING.md +71 -0
  12. data/Gemfile +20 -25
  13. data/README.md +32 -16
  14. data/lib/raven/backtrace.rb +9 -5
  15. data/lib/raven/base.rb +6 -2
  16. data/lib/raven/breadcrumbs.rb +1 -1
  17. data/lib/raven/breadcrumbs/{activesupport.rb → active_support_logger.rb} +9 -3
  18. data/lib/raven/breadcrumbs/logger.rb +2 -92
  19. data/lib/raven/breadcrumbs/sentry_logger.rb +73 -0
  20. data/lib/raven/cli.rb +10 -21
  21. data/lib/raven/client.rb +9 -4
  22. data/lib/raven/configuration.rb +96 -10
  23. data/lib/raven/context.rb +13 -8
  24. data/lib/raven/core_ext/object/deep_dup.rb +57 -0
  25. data/lib/raven/core_ext/object/duplicable.rb +153 -0
  26. data/lib/raven/event.rb +27 -15
  27. data/lib/raven/helpers/deprecation_helper.rb +17 -0
  28. data/lib/raven/instance.rb +14 -4
  29. data/lib/raven/integrations/delayed_job.rb +15 -15
  30. data/lib/raven/integrations/rack-timeout.rb +7 -4
  31. data/lib/raven/integrations/rack.rb +18 -4
  32. data/lib/raven/integrations/rails.rb +13 -3
  33. data/lib/raven/integrations/rails/active_job.rb +6 -4
  34. data/lib/raven/integrations/rails/backtrace_cleaner.rb +29 -0
  35. data/lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb +2 -2
  36. data/lib/raven/integrations/sidekiq.rb +4 -78
  37. data/lib/raven/integrations/sidekiq/cleanup_middleware.rb +13 -0
  38. data/lib/raven/integrations/sidekiq/error_handler.rb +38 -0
  39. data/lib/raven/interface.rb +2 -2
  40. data/lib/raven/interfaces/stack_trace.rb +1 -1
  41. data/lib/raven/linecache.rb +5 -2
  42. data/lib/raven/logger.rb +3 -2
  43. data/lib/raven/processor/cookies.rb +16 -6
  44. data/lib/raven/processor/post_data.rb +2 -0
  45. data/lib/raven/processor/removecircularreferences.rb +3 -1
  46. data/lib/raven/processor/sanitizedata.rb +65 -17
  47. data/lib/raven/processor/utf8conversion.rb +2 -0
  48. data/lib/raven/transports.rb +4 -0
  49. data/lib/raven/transports/http.rb +5 -7
  50. data/lib/raven/utils/context_filter.rb +42 -0
  51. data/lib/raven/utils/exception_cause_chain.rb +1 -0
  52. data/lib/raven/utils/real_ip.rb +1 -1
  53. data/lib/raven/version.rb +2 -2
  54. data/lib/sentry-raven-without-integrations.rb +6 -1
  55. data/lib/sentry_raven_without_integrations.rb +1 -0
  56. data/sentry-ruby/.gitignore +11 -0
  57. data/sentry-ruby/.rspec +3 -0
  58. data/sentry-ruby/.travis.yml +6 -0
  59. data/sentry-ruby/CODE_OF_CONDUCT.md +74 -0
  60. data/sentry-ruby/Gemfile +9 -0
  61. data/sentry-ruby/LICENSE.txt +21 -0
  62. data/sentry-ruby/README.md +44 -0
  63. data/sentry-ruby/Rakefile +6 -0
  64. data/sentry-ruby/bin/console +14 -0
  65. data/sentry-ruby/bin/setup +8 -0
  66. data/sentry-ruby/examples/rails-6.0/.browserslistrc +1 -0
  67. data/sentry-ruby/examples/rails-6.0/.gitignore +35 -0
  68. data/sentry-ruby/examples/rails-6.0/Gemfile +58 -0
  69. data/sentry-ruby/examples/rails-6.0/README.md +23 -0
  70. data/sentry-ruby/examples/rails-6.0/Rakefile +6 -0
  71. data/sentry-ruby/examples/rails-6.0/app/assets/config/manifest.js +2 -0
  72. data/sentry-ruby/examples/rails-6.0/app/assets/images/.keep +0 -0
  73. data/sentry-ruby/examples/rails-6.0/app/assets/stylesheets/application.css +15 -0
  74. data/sentry-ruby/examples/rails-6.0/app/channels/application_cable/channel.rb +4 -0
  75. data/sentry-ruby/examples/rails-6.0/app/channels/application_cable/connection.rb +4 -0
  76. data/sentry-ruby/examples/rails-6.0/app/controllers/application_controller.rb +2 -0
  77. data/sentry-ruby/examples/rails-6.0/app/controllers/concerns/.keep +0 -0
  78. data/sentry-ruby/examples/rails-6.0/app/controllers/welcome_controller.rb +23 -0
  79. data/sentry-ruby/examples/rails-6.0/app/helpers/application_helper.rb +2 -0
  80. data/sentry-ruby/examples/rails-6.0/app/javascript/channels/consumer.js +6 -0
  81. data/sentry-ruby/examples/rails-6.0/app/javascript/channels/index.js +5 -0
  82. data/sentry-ruby/examples/rails-6.0/app/javascript/packs/application.js +17 -0
  83. data/sentry-ruby/examples/rails-6.0/app/jobs/application_job.rb +7 -0
  84. data/sentry-ruby/examples/rails-6.0/app/mailers/application_mailer.rb +4 -0
  85. data/sentry-ruby/examples/rails-6.0/app/models/application_record.rb +3 -0
  86. data/sentry-ruby/examples/rails-6.0/app/models/concerns/.keep +0 -0
  87. data/sentry-ruby/examples/rails-6.0/app/views/layouts/application.html.erb +15 -0
  88. data/sentry-ruby/examples/rails-6.0/app/views/layouts/mailer.html.erb +13 -0
  89. data/sentry-ruby/examples/rails-6.0/app/views/layouts/mailer.text.erb +1 -0
  90. data/sentry-ruby/examples/rails-6.0/app/views/welcome/report_demo.html.erb +22 -0
  91. data/sentry-ruby/examples/rails-6.0/app/views/welcome/view_error.html.erb +1 -0
  92. data/sentry-ruby/examples/rails-6.0/app/workers/error_worker.rb +7 -0
  93. data/sentry-ruby/examples/rails-6.0/babel.config.js +72 -0
  94. data/sentry-ruby/examples/rails-6.0/bin/bundle +114 -0
  95. data/sentry-ruby/examples/rails-6.0/bin/rails +9 -0
  96. data/sentry-ruby/examples/rails-6.0/bin/rake +9 -0
  97. data/sentry-ruby/examples/rails-6.0/bin/setup +36 -0
  98. data/sentry-ruby/examples/rails-6.0/bin/spring +17 -0
  99. data/sentry-ruby/examples/rails-6.0/bin/webpack +18 -0
  100. data/sentry-ruby/examples/rails-6.0/bin/webpack-dev-server +18 -0
  101. data/sentry-ruby/examples/rails-6.0/bin/yarn +11 -0
  102. data/sentry-ruby/examples/rails-6.0/config.ru +5 -0
  103. data/sentry-ruby/examples/rails-6.0/config/application.rb +28 -0
  104. data/sentry-ruby/examples/rails-6.0/config/boot.rb +4 -0
  105. data/sentry-ruby/examples/rails-6.0/config/cable.yml +10 -0
  106. data/sentry-ruby/examples/rails-6.0/config/credentials.yml.enc +1 -0
  107. data/sentry-ruby/examples/rails-6.0/config/database.yml +25 -0
  108. data/sentry-ruby/examples/rails-6.0/config/environment.rb +5 -0
  109. data/sentry-ruby/examples/rails-6.0/config/environments/development.rb +62 -0
  110. data/sentry-ruby/examples/rails-6.0/config/environments/production.rb +112 -0
  111. data/sentry-ruby/examples/rails-6.0/config/environments/test.rb +48 -0
  112. data/sentry-ruby/examples/rails-6.0/config/initializers/application_controller_renderer.rb +8 -0
  113. data/sentry-ruby/examples/rails-6.0/config/initializers/assets.rb +14 -0
  114. data/sentry-ruby/examples/rails-6.0/config/initializers/backtrace_silencers.rb +7 -0
  115. data/sentry-ruby/examples/rails-6.0/config/initializers/content_security_policy.rb +30 -0
  116. data/sentry-ruby/examples/rails-6.0/config/initializers/cookies_serializer.rb +5 -0
  117. data/sentry-ruby/examples/rails-6.0/config/initializers/filter_parameter_logging.rb +4 -0
  118. data/sentry-ruby/examples/rails-6.0/config/initializers/inflections.rb +16 -0
  119. data/sentry-ruby/examples/rails-6.0/config/initializers/mime_types.rb +4 -0
  120. data/sentry-ruby/examples/rails-6.0/config/initializers/wrap_parameters.rb +14 -0
  121. data/sentry-ruby/examples/rails-6.0/config/locales/en.yml +33 -0
  122. data/sentry-ruby/examples/rails-6.0/config/puma.rb +38 -0
  123. data/sentry-ruby/examples/rails-6.0/config/routes.rb +10 -0
  124. data/sentry-ruby/examples/rails-6.0/config/spring.rb +6 -0
  125. data/sentry-ruby/examples/rails-6.0/config/storage.yml +34 -0
  126. data/sentry-ruby/examples/rails-6.0/config/webpack/development.js +5 -0
  127. data/sentry-ruby/examples/rails-6.0/config/webpack/environment.js +3 -0
  128. data/sentry-ruby/examples/rails-6.0/config/webpack/production.js +5 -0
  129. data/sentry-ruby/examples/rails-6.0/config/webpack/test.js +5 -0
  130. data/sentry-ruby/examples/rails-6.0/config/webpacker.yml +96 -0
  131. data/sentry-ruby/examples/rails-6.0/db/seeds.rb +7 -0
  132. data/sentry-ruby/examples/rails-6.0/lib/assets/.keep +0 -0
  133. data/sentry-ruby/examples/rails-6.0/lib/tasks/.keep +0 -0
  134. data/sentry-ruby/examples/rails-6.0/package.json +15 -0
  135. data/sentry-ruby/examples/rails-6.0/postcss.config.js +12 -0
  136. data/sentry-ruby/examples/rails-6.0/public/404.html +67 -0
  137. data/sentry-ruby/examples/rails-6.0/public/422.html +67 -0
  138. data/sentry-ruby/examples/rails-6.0/public/500.html +66 -0
  139. data/sentry-ruby/examples/rails-6.0/public/apple-touch-icon-precomposed.png +0 -0
  140. data/sentry-ruby/examples/rails-6.0/public/apple-touch-icon.png +0 -0
  141. data/sentry-ruby/examples/rails-6.0/public/favicon.ico +0 -0
  142. data/sentry-ruby/examples/rails-6.0/public/robots.txt +1 -0
  143. data/sentry-ruby/examples/rails-6.0/storage/.keep +0 -0
  144. data/sentry-ruby/examples/rails-6.0/test/application_system_test_case.rb +5 -0
  145. data/sentry-ruby/examples/rails-6.0/test/channels/application_cable/connection_test.rb +11 -0
  146. data/sentry-ruby/examples/rails-6.0/test/controllers/.keep +0 -0
  147. data/sentry-ruby/examples/rails-6.0/test/fixtures/.keep +0 -0
  148. data/sentry-ruby/examples/rails-6.0/test/fixtures/files/.keep +0 -0
  149. data/sentry-ruby/examples/rails-6.0/test/helpers/.keep +0 -0
  150. data/sentry-ruby/examples/rails-6.0/test/integration/.keep +0 -0
  151. data/sentry-ruby/examples/rails-6.0/test/mailers/.keep +0 -0
  152. data/sentry-ruby/examples/rails-6.0/test/models/.keep +0 -0
  153. data/sentry-ruby/examples/rails-6.0/test/system/.keep +0 -0
  154. data/sentry-ruby/examples/rails-6.0/test/test_helper.rb +13 -0
  155. data/sentry-ruby/examples/rails-6.0/vendor/.keep +0 -0
  156. data/sentry-ruby/examples/rails-6.0/yarn.lock +7508 -0
  157. data/sentry-ruby/lib/sentry.rb +16 -0
  158. data/sentry-ruby/lib/sentry/backtrace.rb +128 -0
  159. data/sentry-ruby/lib/sentry/client.rb +162 -0
  160. data/sentry-ruby/lib/sentry/client/state.rb +40 -0
  161. data/sentry-ruby/lib/sentry/configuration.rb +533 -0
  162. data/sentry-ruby/lib/sentry/event.rb +209 -0
  163. data/sentry-ruby/lib/sentry/interface.rb +31 -0
  164. data/sentry-ruby/lib/sentry/interfaces/exception.rb +15 -0
  165. data/sentry-ruby/lib/sentry/interfaces/http.rb +16 -0
  166. data/sentry-ruby/lib/sentry/interfaces/message.rb +18 -0
  167. data/sentry-ruby/lib/sentry/interfaces/single_exception.rb +14 -0
  168. data/sentry-ruby/lib/sentry/interfaces/stack_trace.rb +69 -0
  169. data/sentry-ruby/lib/sentry/linecache.rb +44 -0
  170. data/sentry-ruby/lib/sentry/logger.rb +20 -0
  171. data/sentry-ruby/lib/sentry/transports.rb +19 -0
  172. data/sentry-ruby/lib/sentry/transports/dummy.rb +16 -0
  173. data/sentry-ruby/lib/sentry/transports/http.rb +66 -0
  174. data/sentry-ruby/lib/sentry/transports/stdout.rb +20 -0
  175. data/sentry-ruby/lib/sentry/utils/deep_merge.rb +22 -0
  176. data/sentry-ruby/lib/sentry/utils/exception_cause_chain.rb +20 -0
  177. data/sentry-ruby/lib/sentry/version.rb +3 -0
  178. data/sentry-ruby/sentry-ruby.gemspec +26 -0
  179. data/sentry-ruby/spec/sentry/backtrace_spec.rb +38 -0
  180. data/sentry-ruby/spec/sentry/client_spec.rb +443 -0
  181. data/sentry-ruby/spec/sentry/configuration_spec.rb +400 -0
  182. data/sentry-ruby/spec/sentry/event_spec.rb +238 -0
  183. data/sentry-ruby/spec/sentry/interface_spec.rb +38 -0
  184. data/sentry-ruby/spec/sentry/interfaces/stack_trace_spec.rb +11 -0
  185. data/sentry-ruby/spec/sentry/linecache_spec.rb +40 -0
  186. data/sentry-ruby/spec/sentry/transports/http_spec.rb +57 -0
  187. data/sentry-ruby/spec/sentry/transports/stdout_spec.rb +11 -0
  188. data/sentry-ruby/spec/sentry_spec.rb +9 -0
  189. data/sentry-ruby/spec/spec_helper.rb +49 -0
  190. data/sentry-ruby/spec/support/linecache.txt +6 -0
  191. metadata +155 -5
  192. data/.travis.yml +0 -43
@@ -0,0 +1,73 @@
1
+ require 'logger'
2
+
3
+ module Raven
4
+ module Breadcrumbs
5
+ module SentryLogger
6
+ LEVELS = {
7
+ ::Logger::DEBUG => 'debug',
8
+ ::Logger::INFO => 'info',
9
+ ::Logger::WARN => 'warn',
10
+ ::Logger::ERROR => 'error',
11
+ ::Logger::FATAL => 'fatal'
12
+ }.freeze
13
+
14
+ def add(*args)
15
+ add_breadcrumb(*args)
16
+ super
17
+ end
18
+
19
+ def add_breadcrumb(severity, message = nil, progname = nil)
20
+ message = progname if message.nil? # see Ruby's Logger docs for why
21
+ return if ignored_logger?(progname)
22
+ return if message.nil? || message == ""
23
+
24
+ # some loggers will add leading/trailing space as they (incorrectly, mind you)
25
+ # think of logging as a shortcut to std{out,err}
26
+ message = message.to_s.strip
27
+
28
+ last_crumb = Raven.breadcrumbs.peek
29
+ # try to avoid dupes from logger broadcasts
30
+ if last_crumb.nil? || last_crumb.message != message
31
+ Raven.breadcrumbs.record do |crumb|
32
+ crumb.level = Raven::Breadcrumbs::SentryLogger::LEVELS.fetch(severity, nil)
33
+ crumb.category = progname || 'logger'
34
+ crumb.message = message
35
+ crumb.type =
36
+ if severity >= 3
37
+ "error"
38
+ else
39
+ crumb.level
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def ignored_logger?(progname)
48
+ progname == "sentry" ||
49
+ Raven.configuration.exclude_loggers.include?(progname)
50
+ end
51
+ end
52
+ module OldBreadcrumbsSentryLogger
53
+ def self.included(base)
54
+ base.class_eval do
55
+ include Raven::Breadcrumbs::SentryLogger
56
+ alias_method :add_without_raven, :add
57
+ alias_method :add, :add_with_raven
58
+ end
59
+ end
60
+
61
+ def add_with_raven(*args)
62
+ add_breadcrumb(*args)
63
+ add_without_raven(*args)
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ Raven.safely_prepend(
70
+ "Breadcrumbs::SentryLogger",
71
+ :from => Raven,
72
+ :to => ::Logger
73
+ )
@@ -1,6 +1,6 @@
1
1
  module Raven
2
2
  class CLI
3
- def self.test(dsn = nil, silent = false, config = nil) # rubocop:disable all
3
+ def self.test(dsn = nil, silent = false, config = nil)
4
4
  config ||= Raven.configuration
5
5
 
6
6
  config.logger = if silent
@@ -18,7 +18,7 @@ module Raven
18
18
 
19
19
  # wipe out env settings to ensure we send the event
20
20
  unless config.capture_allowed?
21
- env_name = config.environments.pop || 'production'
21
+ env_name = config.environments.last || 'production'
22
22
  config.current_environment = env_name
23
23
  end
24
24
 
@@ -29,31 +29,20 @@ module Raven
29
29
 
30
30
  begin
31
31
  1 / 0
32
- rescue ZeroDivisionError => exception
33
- evt = instance.capture_exception(exception)
32
+ rescue ZeroDivisionError => e
33
+ evt = instance.capture_exception(e)
34
34
  end
35
35
 
36
- if evt && !(evt.is_a? Thread)
37
- if evt.is_a? Hash
38
- instance.logger.debug "-> event ID: #{evt[:event_id]}"
39
- else
40
- instance.logger.debug "-> event ID: #{evt.id}"
41
- end
42
- elsif evt # async configuration
43
- if evt.value.is_a? Hash
44
- instance.logger.debug "-> event ID: #{evt.value[:event_id]}"
45
- else
46
- instance.logger.debug "-> event ID: #{evt.value.id}"
47
- end
36
+ if evt
37
+ instance.logger.debug "-> event ID: #{evt.id}"
38
+ instance.logger.debug ""
39
+ instance.logger.debug "Done!"
40
+ evt
48
41
  else
49
42
  instance.logger.debug ""
50
43
  instance.logger.debug "An error occurred while attempting to send the event."
51
- exit 1
44
+ false
52
45
  end
53
-
54
- instance.logger.debug ""
55
- instance.logger.debug "Done!"
56
- evt
57
46
  end
58
47
  end
59
48
  end
@@ -1,14 +1,17 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'base64'
3
4
  require 'json'
4
5
  require 'zlib'
5
6
 
7
+ require "raven/transports"
8
+
6
9
  module Raven
7
10
  # Encodes events and sends them to the Sentry server.
8
11
  class Client
9
- PROTOCOL_VERSION = '5'.freeze
10
- USER_AGENT = "raven-ruby/#{Raven::VERSION}".freeze
11
- CONTENT_TYPE = 'application/json'.freeze
12
+ PROTOCOL_VERSION = '5'
13
+ USER_AGENT = "raven-ruby/#{Raven::VERSION}"
14
+ CONTENT_TYPE = 'application/json'
12
15
 
13
16
  attr_accessor :configuration
14
17
 
@@ -120,7 +123,9 @@ module Raven
120
123
  configuration.logger.warn "Not sending event due to previous failure(s)."
121
124
  end
122
125
  configuration.logger.warn("Failed to submit event: #{get_log_message(event)}")
123
- configuration.transport_failure_callback.call(event) if configuration.transport_failure_callback
126
+
127
+ # configuration.transport_failure_callback can be false & nil
128
+ configuration.transport_failure_callback.call(event, e) if configuration.transport_failure_callback # rubocop:disable Style/SafeNavigation
124
129
  end
125
130
  end
126
131
 
@@ -12,6 +12,11 @@ module Raven
12
12
  attr_reader :async
13
13
  alias async? async
14
14
 
15
+ # An array of breadcrumbs loggers to be used. Available options are:
16
+ # - :sentry_logger
17
+ # - :active_support_logger
18
+ attr_reader :breadcrumbs_logger
19
+
15
20
  # Number of lines of code context to capture, or nil for none
16
21
  attr_accessor :context_lines
17
22
 
@@ -83,7 +88,7 @@ module Raven
83
88
  attr_accessor :public_key
84
89
 
85
90
  # Turns on ActiveSupport breadcrumbs integration
86
- attr_accessor :rails_activesupport_breadcrumbs
91
+ attr_reader :rails_activesupport_breadcrumbs
87
92
 
88
93
  # Rails catches exceptions in the ActionDispatch::ShowExceptions or
89
94
  # ActionDispatch::DebugExceptions middlewares, depending on the environment.
@@ -118,6 +123,19 @@ module Raven
118
123
  # Otherwise, can be one of "http", "https", or "dummy"
119
124
  attr_accessor :scheme
120
125
 
126
+ # a proc/lambda that takes an array of stack traces
127
+ # it'll be used to silence (reduce) backtrace of the exception
128
+ #
129
+ # for example:
130
+ #
131
+ # ```ruby
132
+ # Raven.configuration.backtrace_cleanup_callback = lambda do |backtrace|
133
+ # Rails.backtrace_cleaner.clean(backtrace)
134
+ # end
135
+ # ```
136
+ #
137
+ attr_accessor :backtrace_cleanup_callback
138
+
121
139
  # Secret key for authentication with the Sentry server
122
140
  # If you provide a DSN, this will be set automatically.
123
141
  #
@@ -172,16 +190,35 @@ module Raven
172
190
  # Errors object - an Array that contains error messages. See #
173
191
  attr_reader :errors
174
192
 
193
+ # the dsn value, whether it's set via `config.dsn=` or `ENV["SENTRY_DSN"]`
194
+ attr_reader :dsn
195
+
196
+ # Array of rack env parameters to be included in the event sent to sentry.
197
+ attr_accessor :rack_env_whitelist
198
+
199
+ # Most of these errors generate 4XX responses. In general, Sentry clients
200
+ # only automatically report 5xx responses.
175
201
  IGNORE_DEFAULT = [
176
202
  'AbstractController::ActionNotFound',
203
+ 'ActionController::BadRequest',
177
204
  'ActionController::InvalidAuthenticityToken',
205
+ 'ActionController::InvalidCrossOriginRequest',
206
+ 'ActionController::MethodNotAllowed',
207
+ 'ActionController::NotImplemented',
208
+ 'ActionController::ParameterMissing',
178
209
  'ActionController::RoutingError',
179
210
  'ActionController::UnknownAction',
211
+ 'ActionController::UnknownFormat',
212
+ 'ActionController::UnknownHttpMethod',
213
+ 'ActionDispatch::Http::Parameters::ParseError',
214
+ 'ActionView::MissingTemplate',
215
+ 'ActiveJob::DeserializationError', # Can cause infinite loops
180
216
  'ActiveRecord::RecordNotFound',
181
217
  'CGI::Session::CookieStore::TamperedWithCookie',
182
218
  'Mongoid::Errors::DocumentNotFound',
183
- 'Sinatra::NotFound',
184
- 'ActiveJob::DeserializationError'
219
+ 'Rack::QueryParser::InvalidParameterError',
220
+ 'Rack::QueryParser::ParameterTypeError',
221
+ 'Sinatra::NotFound'
185
222
  ].freeze
186
223
 
187
224
  # Note the order - we have to remove circular references and bad characters
@@ -198,11 +235,20 @@ module Raven
198
235
  HEROKU_DYNO_METADATA_MESSAGE = "You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\
199
236
  "release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`".freeze
200
237
 
238
+ RACK_ENV_WHITELIST_DEFAULT = %w(
239
+ REMOTE_ADDR
240
+ SERVER_NAME
241
+ SERVER_PORT
242
+ ).freeze
243
+
201
244
  LOG_PREFIX = "** [Raven] ".freeze
202
245
  MODULE_SEPARATOR = "::".freeze
203
246
 
247
+ AVAILABLE_BREADCRUMBS_LOGGERS = [:sentry_logger, :active_support_logger].freeze
248
+
204
249
  def initialize
205
250
  self.async = false
251
+ self.breadcrumbs_logger = []
206
252
  self.context_lines = 3
207
253
  self.current_environment = current_environment_from_env
208
254
  self.encoding = 'gzip'
@@ -215,7 +261,8 @@ module Raven
215
261
  self.open_timeout = 1
216
262
  self.processors = DEFAULT_PROCESSORS.dup
217
263
  self.project_root = detect_project_root
218
- self.rails_activesupport_breadcrumbs = false
264
+ @rails_activesupport_breadcrumbs = false
265
+
219
266
  self.rails_report_rescued_exceptions = true
220
267
  self.release = detect_release
221
268
  self.sample_rate = 1.0
@@ -232,10 +279,14 @@ module Raven
232
279
  self.timeout = 2
233
280
  self.transport_failure_callback = false
234
281
  self.before_send = false
282
+ self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
235
283
  end
236
284
 
237
285
  def server=(value)
238
286
  return if value.nil?
287
+
288
+ @dsn = value
289
+
239
290
  uri = URI.parse(value)
240
291
  uri_path = uri.path.split('/')
241
292
 
@@ -253,13 +304,14 @@ module Raven
253
304
 
254
305
  # For anyone who wants to read the base server string
255
306
  @server = "#{scheme}://#{host}"
256
- @server << ":#{port}" unless port == { 'http' => 80, 'https' => 443 }[scheme]
257
- @server << path
307
+ @server += ":#{port}" unless port == { 'http' => 80, 'https' => 443 }[scheme]
308
+ @server += path
258
309
  end
259
310
  alias dsn= server=
260
311
 
261
312
  def encoding=(encoding)
262
313
  raise(Error, 'Unsupported encoding') unless %w(gzip json).include? encoding
314
+
263
315
  @encoding = encoding
264
316
  end
265
317
 
@@ -267,13 +319,32 @@ module Raven
267
319
  unless value == false || value.respond_to?(:call)
268
320
  raise(ArgumentError, "async must be callable (or false to disable)")
269
321
  end
322
+
270
323
  @async = value
271
324
  end
272
325
 
326
+ def breadcrumbs_logger=(logger)
327
+ loggers =
328
+ if logger.is_a?(Array)
329
+ logger
330
+ else
331
+ unless AVAILABLE_BREADCRUMBS_LOGGERS.include?(logger)
332
+ raise Raven::Error, "Unsupported breadcrumbs logger. Supported loggers: #{AVAILABLE_BREADCRUMBS_LOGGERS}"
333
+ end
334
+
335
+ Array(logger)
336
+ end
337
+
338
+ require "raven/breadcrumbs/sentry_logger" if loggers.include?(:sentry_logger)
339
+
340
+ @breadcrumbs_logger = logger
341
+ end
342
+
273
343
  def transport_failure_callback=(value)
274
344
  unless value == false || value.respond_to?(:call)
275
345
  raise(ArgumentError, "transport_failure_callback must be callable (or false to disable)")
276
346
  end
347
+
277
348
  @transport_failure_callback = value
278
349
  end
279
350
 
@@ -281,6 +352,7 @@ module Raven
281
352
  unless value == false || value.respond_to?(:call)
282
353
  raise ArgumentError, "should_capture must be callable (or false to disable)"
283
354
  end
355
+
284
356
  @should_capture = value
285
357
  end
286
358
 
@@ -288,6 +360,7 @@ module Raven
288
360
  unless value == false || value.respond_to?(:call)
289
361
  raise ArgumentError, "before_send must be callable (or false to disable)"
290
362
  end
363
+
291
364
  @before_send = value
292
365
  end
293
366
 
@@ -323,6 +396,11 @@ module Raven
323
396
  Backtrace::Line.instance_variable_set(:@in_app_pattern, nil) # blow away cache
324
397
  end
325
398
 
399
+ def rails_activesupport_breadcrumbs=(val)
400
+ DeprecationHelper.deprecate_old_breadcrumbs_configuration(:active_support_logger)
401
+ @rails_activesupport_breadcrumbs = val
402
+ end
403
+
326
404
  def exception_class_allowed?(exc)
327
405
  if exc.is_a?(Raven::Error)
328
406
  # Try to prevent error reporting loops
@@ -336,6 +414,10 @@ module Raven
336
414
  end
337
415
  end
338
416
 
417
+ def enabled_in_current_env?
418
+ environments.empty? || environments.include?(current_environment)
419
+ end
420
+
339
421
  private
340
422
 
341
423
  def detect_project_root
@@ -351,8 +433,8 @@ module Raven
351
433
  detect_release_from_git ||
352
434
  detect_release_from_capistrano ||
353
435
  detect_release_from_heroku
354
- rescue => ex
355
- logger.error "Error detecting release: #{ex.message}"
436
+ rescue => e
437
+ logger.error "Error detecting release: #{e.message}"
356
438
  end
357
439
 
358
440
  def excluded_exception?(incoming_exception)
@@ -417,19 +499,22 @@ module Raven
417
499
  end
418
500
 
419
501
  def capture_in_current_environment?
420
- return true unless environments.any? && !environments.include?(current_environment)
502
+ return true if enabled_in_current_env?
503
+
421
504
  @errors << "Not configured to send/capture in environment '#{current_environment}'"
422
505
  false
423
506
  end
424
507
 
425
508
  def capture_allowed_by_callback?(message_or_exc)
426
- return true if !should_capture || message_or_exc.nil? || should_capture.call(*[message_or_exc])
509
+ return true if !should_capture || message_or_exc.nil? || should_capture.call(message_or_exc)
510
+
427
511
  @errors << "should_capture returned false"
428
512
  false
429
513
  end
430
514
 
431
515
  def valid?
432
516
  return true if %w(server host path public_key project_id).all? { |k| public_send(k) }
517
+
433
518
  if server
434
519
  %w(server host path public_key project_id).map do |key|
435
520
  @errors << "No #{key} specified" unless public_send(key)
@@ -442,6 +527,7 @@ module Raven
442
527
 
443
528
  def sample_allowed?
444
529
  return true if sample_rate == 1.0
530
+
445
531
  if Random::DEFAULT.rand >= sample_rate
446
532
  @errors << "Excluded by random sample"
447
533
  false
@@ -1,4 +1,5 @@
1
1
  require 'rbconfig'
2
+ require 'etc'
2
3
 
3
4
  module Raven
4
5
  class Context
@@ -24,18 +25,22 @@ module Raven
24
25
 
25
26
  class << self
26
27
  def os_context
27
- @os_context ||= {
28
- :name => Raven.sys_command("uname -s") || RbConfig::CONFIG["host_os"],
29
- :version => Raven.sys_command("uname -v"),
30
- :build => Raven.sys_command("uname -r"),
31
- :kernel_version => Raven.sys_command("uname -a") || Raven.sys_command("ver") # windows
32
- }
28
+ @os_context ||=
29
+ begin
30
+ uname = Etc.uname
31
+ {
32
+ name: uname[:sysname] || RbConfig::CONFIG["host_os"],
33
+ version: uname[:version],
34
+ build: uname[:release],
35
+ kernel_version: uname[:version]
36
+ }
37
+ end
33
38
  end
34
39
 
35
40
  def runtime_context
36
41
  @runtime_context ||= {
37
- :name => RbConfig::CONFIG["ruby_install_name"],
38
- :version => Raven.sys_command("ruby -v")
42
+ name: RbConfig::CONFIG["ruby_install_name"],
43
+ version: RUBY_DESCRIPTION || Raven.sys_command("ruby -v")
39
44
  }
40
45
  end
41
46
  end