sentry-raven 2.7.4 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. checksums.yaml +5 -5
  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 -1
  8. data/.gitmodules +0 -3
  9. data/.rubocop.yml +50 -12
  10. data/.scripts/bump-version.sh +9 -0
  11. data/{changelog.md → CHANGELOG.md} +238 -1
  12. data/CONTRIBUTING.md +71 -0
  13. data/Gemfile +21 -26
  14. data/README.md +42 -22
  15. data/lib/raven/backtrace.rb +9 -5
  16. data/lib/raven/base.rb +8 -3
  17. data/lib/raven/breadcrumbs.rb +1 -1
  18. data/lib/raven/breadcrumbs/{activesupport.rb → active_support_logger.rb} +9 -3
  19. data/lib/raven/breadcrumbs/logger.rb +2 -92
  20. data/lib/raven/breadcrumbs/sentry_logger.rb +73 -0
  21. data/lib/raven/cli.rb +10 -21
  22. data/lib/raven/client.rb +37 -11
  23. data/lib/raven/configuration.rb +141 -20
  24. data/lib/raven/context.rb +13 -8
  25. data/lib/raven/core_ext/object/deep_dup.rb +57 -0
  26. data/lib/raven/core_ext/object/duplicable.rb +153 -0
  27. data/lib/raven/event.rb +29 -37
  28. data/lib/raven/helpers/deprecation_helper.rb +17 -0
  29. data/lib/raven/instance.rb +30 -8
  30. data/lib/raven/integrations/delayed_job.rb +16 -16
  31. data/lib/raven/integrations/rack-timeout.rb +7 -4
  32. data/lib/raven/integrations/rack.rb +19 -5
  33. data/lib/raven/integrations/rails.rb +13 -3
  34. data/lib/raven/integrations/rails/active_job.rb +11 -7
  35. data/lib/raven/integrations/rails/backtrace_cleaner.rb +29 -0
  36. data/lib/raven/integrations/rails/controller_transaction.rb +1 -1
  37. data/lib/raven/integrations/rails/overrides/debug_exceptions_catcher.rb +2 -2
  38. data/lib/raven/integrations/sidekiq.rb +4 -78
  39. data/lib/raven/integrations/sidekiq/cleanup_middleware.rb +13 -0
  40. data/lib/raven/integrations/sidekiq/error_handler.rb +38 -0
  41. data/lib/raven/interface.rb +2 -2
  42. data/lib/raven/interfaces/stack_trace.rb +1 -1
  43. data/lib/raven/linecache.rb +5 -2
  44. data/lib/raven/logger.rb +3 -2
  45. data/lib/raven/processor/cookies.rb +16 -6
  46. data/lib/raven/processor/post_data.rb +2 -0
  47. data/lib/raven/processor/removecircularreferences.rb +3 -1
  48. data/lib/raven/processor/sanitizedata.rb +65 -17
  49. data/lib/raven/processor/utf8conversion.rb +3 -1
  50. data/lib/raven/transports.rb +4 -0
  51. data/lib/raven/transports/http.rb +5 -7
  52. data/lib/raven/transports/stdout.rb +20 -0
  53. data/lib/raven/utils/context_filter.rb +42 -0
  54. data/lib/raven/utils/exception_cause_chain.rb +20 -0
  55. data/lib/raven/utils/real_ip.rb +1 -1
  56. data/lib/raven/version.rb +2 -2
  57. data/lib/sentry-raven-without-integrations.rb +6 -1
  58. data/lib/sentry_raven_without_integrations.rb +1 -0
  59. data/sentry-raven.gemspec +3 -4
  60. data/sentry-ruby/.gitignore +11 -0
  61. data/sentry-ruby/.rspec +3 -0
  62. data/sentry-ruby/.travis.yml +6 -0
  63. data/sentry-ruby/CODE_OF_CONDUCT.md +74 -0
  64. data/sentry-ruby/Gemfile +9 -0
  65. data/sentry-ruby/LICENSE.txt +21 -0
  66. data/sentry-ruby/README.md +44 -0
  67. data/sentry-ruby/Rakefile +6 -0
  68. data/sentry-ruby/bin/console +14 -0
  69. data/sentry-ruby/bin/setup +8 -0
  70. data/sentry-ruby/examples/rails-6.0/.browserslistrc +1 -0
  71. data/sentry-ruby/examples/rails-6.0/.gitignore +35 -0
  72. data/sentry-ruby/examples/rails-6.0/Gemfile +58 -0
  73. data/sentry-ruby/examples/rails-6.0/README.md +23 -0
  74. data/sentry-ruby/examples/rails-6.0/Rakefile +6 -0
  75. data/sentry-ruby/examples/rails-6.0/app/assets/config/manifest.js +2 -0
  76. data/sentry-ruby/examples/rails-6.0/app/assets/images/.keep +0 -0
  77. data/sentry-ruby/examples/rails-6.0/app/assets/stylesheets/application.css +15 -0
  78. data/sentry-ruby/examples/rails-6.0/app/channels/application_cable/channel.rb +4 -0
  79. data/sentry-ruby/examples/rails-6.0/app/channels/application_cable/connection.rb +4 -0
  80. data/sentry-ruby/examples/rails-6.0/app/controllers/application_controller.rb +2 -0
  81. data/sentry-ruby/examples/rails-6.0/app/controllers/concerns/.keep +0 -0
  82. data/sentry-ruby/examples/rails-6.0/app/controllers/welcome_controller.rb +23 -0
  83. data/sentry-ruby/examples/rails-6.0/app/helpers/application_helper.rb +2 -0
  84. data/sentry-ruby/examples/rails-6.0/app/javascript/channels/consumer.js +6 -0
  85. data/sentry-ruby/examples/rails-6.0/app/javascript/channels/index.js +5 -0
  86. data/sentry-ruby/examples/rails-6.0/app/javascript/packs/application.js +17 -0
  87. data/sentry-ruby/examples/rails-6.0/app/jobs/application_job.rb +7 -0
  88. data/sentry-ruby/examples/rails-6.0/app/mailers/application_mailer.rb +4 -0
  89. data/sentry-ruby/examples/rails-6.0/app/models/application_record.rb +3 -0
  90. data/sentry-ruby/examples/rails-6.0/app/models/concerns/.keep +0 -0
  91. data/sentry-ruby/examples/rails-6.0/app/views/layouts/application.html.erb +15 -0
  92. data/sentry-ruby/examples/rails-6.0/app/views/layouts/mailer.html.erb +13 -0
  93. data/sentry-ruby/examples/rails-6.0/app/views/layouts/mailer.text.erb +1 -0
  94. data/sentry-ruby/examples/rails-6.0/app/views/welcome/report_demo.html.erb +22 -0
  95. data/sentry-ruby/examples/rails-6.0/app/views/welcome/view_error.html.erb +1 -0
  96. data/sentry-ruby/examples/rails-6.0/app/workers/error_worker.rb +7 -0
  97. data/sentry-ruby/examples/rails-6.0/babel.config.js +72 -0
  98. data/sentry-ruby/examples/rails-6.0/bin/bundle +114 -0
  99. data/sentry-ruby/examples/rails-6.0/bin/rails +9 -0
  100. data/sentry-ruby/examples/rails-6.0/bin/rake +9 -0
  101. data/sentry-ruby/examples/rails-6.0/bin/setup +36 -0
  102. data/sentry-ruby/examples/rails-6.0/bin/spring +17 -0
  103. data/sentry-ruby/examples/rails-6.0/bin/webpack +18 -0
  104. data/sentry-ruby/examples/rails-6.0/bin/webpack-dev-server +18 -0
  105. data/sentry-ruby/examples/rails-6.0/bin/yarn +11 -0
  106. data/sentry-ruby/examples/rails-6.0/config.ru +5 -0
  107. data/sentry-ruby/examples/rails-6.0/config/application.rb +28 -0
  108. data/sentry-ruby/examples/rails-6.0/config/boot.rb +4 -0
  109. data/sentry-ruby/examples/rails-6.0/config/cable.yml +10 -0
  110. data/sentry-ruby/examples/rails-6.0/config/credentials.yml.enc +1 -0
  111. data/sentry-ruby/examples/rails-6.0/config/database.yml +25 -0
  112. data/sentry-ruby/examples/rails-6.0/config/environment.rb +5 -0
  113. data/sentry-ruby/examples/rails-6.0/config/environments/development.rb +62 -0
  114. data/sentry-ruby/examples/rails-6.0/config/environments/production.rb +112 -0
  115. data/sentry-ruby/examples/rails-6.0/config/environments/test.rb +48 -0
  116. data/sentry-ruby/examples/rails-6.0/config/initializers/application_controller_renderer.rb +8 -0
  117. data/sentry-ruby/examples/rails-6.0/config/initializers/assets.rb +14 -0
  118. data/sentry-ruby/examples/rails-6.0/config/initializers/backtrace_silencers.rb +7 -0
  119. data/sentry-ruby/examples/rails-6.0/config/initializers/content_security_policy.rb +30 -0
  120. data/sentry-ruby/examples/rails-6.0/config/initializers/cookies_serializer.rb +5 -0
  121. data/sentry-ruby/examples/rails-6.0/config/initializers/filter_parameter_logging.rb +4 -0
  122. data/sentry-ruby/examples/rails-6.0/config/initializers/inflections.rb +16 -0
  123. data/sentry-ruby/examples/rails-6.0/config/initializers/mime_types.rb +4 -0
  124. data/sentry-ruby/examples/rails-6.0/config/initializers/wrap_parameters.rb +14 -0
  125. data/sentry-ruby/examples/rails-6.0/config/locales/en.yml +33 -0
  126. data/sentry-ruby/examples/rails-6.0/config/puma.rb +38 -0
  127. data/sentry-ruby/examples/rails-6.0/config/routes.rb +10 -0
  128. data/sentry-ruby/examples/rails-6.0/config/spring.rb +6 -0
  129. data/sentry-ruby/examples/rails-6.0/config/storage.yml +34 -0
  130. data/sentry-ruby/examples/rails-6.0/config/webpack/development.js +5 -0
  131. data/sentry-ruby/examples/rails-6.0/config/webpack/environment.js +3 -0
  132. data/sentry-ruby/examples/rails-6.0/config/webpack/production.js +5 -0
  133. data/sentry-ruby/examples/rails-6.0/config/webpack/test.js +5 -0
  134. data/sentry-ruby/examples/rails-6.0/config/webpacker.yml +96 -0
  135. data/sentry-ruby/examples/rails-6.0/db/seeds.rb +7 -0
  136. data/sentry-ruby/examples/rails-6.0/lib/assets/.keep +0 -0
  137. data/sentry-ruby/examples/rails-6.0/lib/tasks/.keep +0 -0
  138. data/sentry-ruby/examples/rails-6.0/package.json +15 -0
  139. data/sentry-ruby/examples/rails-6.0/postcss.config.js +12 -0
  140. data/sentry-ruby/examples/rails-6.0/public/404.html +67 -0
  141. data/sentry-ruby/examples/rails-6.0/public/422.html +67 -0
  142. data/sentry-ruby/examples/rails-6.0/public/500.html +66 -0
  143. data/sentry-ruby/examples/rails-6.0/public/apple-touch-icon-precomposed.png +0 -0
  144. data/sentry-ruby/examples/rails-6.0/public/apple-touch-icon.png +0 -0
  145. data/sentry-ruby/examples/rails-6.0/public/favicon.ico +0 -0
  146. data/sentry-ruby/examples/rails-6.0/public/robots.txt +1 -0
  147. data/sentry-ruby/examples/rails-6.0/storage/.keep +0 -0
  148. data/sentry-ruby/examples/rails-6.0/test/application_system_test_case.rb +5 -0
  149. data/sentry-ruby/examples/rails-6.0/test/channels/application_cable/connection_test.rb +11 -0
  150. data/sentry-ruby/examples/rails-6.0/test/controllers/.keep +0 -0
  151. data/sentry-ruby/examples/rails-6.0/test/fixtures/.keep +0 -0
  152. data/sentry-ruby/examples/rails-6.0/test/fixtures/files/.keep +0 -0
  153. data/sentry-ruby/examples/rails-6.0/test/helpers/.keep +0 -0
  154. data/sentry-ruby/examples/rails-6.0/test/integration/.keep +0 -0
  155. data/sentry-ruby/examples/rails-6.0/test/mailers/.keep +0 -0
  156. data/sentry-ruby/examples/rails-6.0/test/models/.keep +0 -0
  157. data/sentry-ruby/examples/rails-6.0/test/system/.keep +0 -0
  158. data/sentry-ruby/examples/rails-6.0/test/test_helper.rb +13 -0
  159. data/sentry-ruby/examples/rails-6.0/vendor/.keep +0 -0
  160. data/sentry-ruby/examples/rails-6.0/yarn.lock +7508 -0
  161. data/sentry-ruby/lib/sentry.rb +16 -0
  162. data/sentry-ruby/lib/sentry/backtrace.rb +128 -0
  163. data/sentry-ruby/lib/sentry/client.rb +162 -0
  164. data/sentry-ruby/lib/sentry/client/state.rb +40 -0
  165. data/sentry-ruby/lib/sentry/configuration.rb +533 -0
  166. data/sentry-ruby/lib/sentry/event.rb +209 -0
  167. data/sentry-ruby/lib/sentry/interface.rb +31 -0
  168. data/sentry-ruby/lib/sentry/interfaces/exception.rb +15 -0
  169. data/sentry-ruby/lib/sentry/interfaces/http.rb +16 -0
  170. data/sentry-ruby/lib/sentry/interfaces/message.rb +18 -0
  171. data/sentry-ruby/lib/sentry/interfaces/single_exception.rb +14 -0
  172. data/sentry-ruby/lib/sentry/interfaces/stack_trace.rb +69 -0
  173. data/sentry-ruby/lib/sentry/linecache.rb +44 -0
  174. data/sentry-ruby/lib/sentry/logger.rb +20 -0
  175. data/sentry-ruby/lib/sentry/transports.rb +19 -0
  176. data/sentry-ruby/lib/sentry/transports/dummy.rb +16 -0
  177. data/sentry-ruby/lib/sentry/transports/http.rb +66 -0
  178. data/sentry-ruby/lib/sentry/transports/stdout.rb +20 -0
  179. data/sentry-ruby/lib/sentry/utils/deep_merge.rb +22 -0
  180. data/sentry-ruby/lib/sentry/utils/exception_cause_chain.rb +20 -0
  181. data/sentry-ruby/lib/sentry/version.rb +3 -0
  182. data/sentry-ruby/sentry-ruby.gemspec +26 -0
  183. data/sentry-ruby/spec/sentry/backtrace_spec.rb +38 -0
  184. data/sentry-ruby/spec/sentry/client_spec.rb +443 -0
  185. data/sentry-ruby/spec/sentry/configuration_spec.rb +400 -0
  186. data/sentry-ruby/spec/sentry/event_spec.rb +238 -0
  187. data/sentry-ruby/spec/sentry/interface_spec.rb +38 -0
  188. data/sentry-ruby/spec/sentry/interfaces/stack_trace_spec.rb +11 -0
  189. data/sentry-ruby/spec/sentry/linecache_spec.rb +40 -0
  190. data/sentry-ruby/spec/sentry/transports/http_spec.rb +57 -0
  191. data/sentry-ruby/spec/sentry/transports/stdout_spec.rb +11 -0
  192. data/sentry-ruby/spec/sentry_spec.rb +9 -0
  193. data/sentry-ruby/spec/spec_helper.rb +49 -0
  194. data/sentry-ruby/spec/support/linecache.txt +6 -0
  195. metadata +160 -31
  196. data/.travis.yml +0 -47
  197. data/docs/Makefile +0 -130
  198. data/docs/breadcrumbs.rst +0 -51
  199. data/docs/conf.py +0 -228
  200. data/docs/config.rst +0 -260
  201. data/docs/context.rst +0 -141
  202. data/docs/index.rst +0 -113
  203. data/docs/install.rst +0 -40
  204. data/docs/integrations/heroku.rst +0 -11
  205. data/docs/integrations/index.rst +0 -59
  206. data/docs/integrations/puma.rst +0 -30
  207. data/docs/integrations/rack.rst +0 -27
  208. data/docs/integrations/rails.rst +0 -62
  209. data/docs/make.bat +0 -155
  210. data/docs/processors.rst +0 -124
  211. data/docs/sentry-doc-config.json +0 -31
  212. data/docs/usage.rst +0 -176
@@ -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
+ )
data/lib/raven/cli.rb CHANGED
@@ -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
data/lib/raven/client.rb CHANGED
@@ -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
 
@@ -18,9 +21,15 @@ module Raven
18
21
  @state = ClientState.new
19
22
  end
20
23
 
21
- def send_event(event)
24
+ def send_event(event, hint = nil)
22
25
  return false unless configuration.sending_allowed?(event)
23
26
 
27
+ event = configuration.before_send.call(event, hint) if configuration.before_send
28
+ if event.nil?
29
+ configuration.logger.info "Discarded event because before_send returned nil"
30
+ return
31
+ end
32
+
24
33
  # Convert to hash
25
34
  event = event.to_hash
26
35
 
@@ -29,7 +38,8 @@ module Raven
29
38
  return
30
39
  end
31
40
 
32
- configuration.logger.info "Sending event #{event[:event_id]} to Sentry"
41
+ event_id = event[:event_id] || event['event_id']
42
+ configuration.logger.info "Sending event #{event_id} to Sentry"
33
43
 
34
44
  content_type, encoded_data = encode(event)
35
45
 
@@ -50,6 +60,8 @@ module Raven
50
60
  case configuration.scheme
51
61
  when 'http', 'https'
52
62
  Transports::HTTP.new(configuration)
63
+ when 'stdout'
64
+ Transports::Stdout.new(configuration)
53
65
  when 'dummy'
54
66
  Transports::Dummy.new(configuration)
55
67
  else
@@ -71,8 +83,20 @@ module Raven
71
83
  end
72
84
  end
73
85
 
86
+ def get_message_from_exception(event)
87
+ (
88
+ event &&
89
+ event[:exception] &&
90
+ event[:exception][:values] &&
91
+ event[:exception][:values][0] &&
92
+ event[:exception][:values][0][:type] &&
93
+ event[:exception][:values][0][:value] &&
94
+ "#{event[:exception][:values][0][:type]}: #{event[:exception][:values][0][:value]}"
95
+ )
96
+ end
97
+
74
98
  def get_log_message(event)
75
- (event && event[:message]) || '<no message value>'
99
+ (event && event[:message]) || (event && event['message']) || get_message_from_exception(event) || '<no message value>'
76
100
  end
77
101
 
78
102
  def generate_auth_header
@@ -92,14 +116,16 @@ module Raven
92
116
  end
93
117
 
94
118
  def failed_send(e, event)
95
- @state.failure
96
119
  if e # exception was raised
97
- configuration.logger.error "Unable to record event with remote Sentry server (#{e.class} - #{e.message}):\n#{e.backtrace[0..10].join("\n")}"
120
+ @state.failure
121
+ configuration.logger.warn "Unable to record event with remote Sentry server (#{e.class} - #{e.message}):\n#{e.backtrace[0..10].join("\n")}"
98
122
  else
99
- configuration.logger.error "Not sending event due to previous failure(s)."
123
+ configuration.logger.warn "Not sending event due to previous failure(s)."
100
124
  end
101
- configuration.logger.error("Failed to submit event: #{get_log_message(event)}")
102
- configuration.transport_failure_callback.call(event) if configuration.transport_failure_callback
125
+ configuration.logger.warn("Failed to submit event: #{get_log_message(event)}")
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
103
129
  end
104
130
  end
105
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
 
@@ -31,6 +36,10 @@ module Raven
31
36
  # You should probably append to this rather than overwrite it.
32
37
  attr_accessor :excluded_exceptions
33
38
 
39
+ # Boolean to check nested exceptions when deciding if to exclude. Defaults to false
40
+ attr_accessor :inspect_exception_causes_for_exclusion
41
+ alias inspect_exception_causes_for_exclusion? inspect_exception_causes_for_exclusion
42
+
34
43
  # DSN component - set automatically if DSN provided
35
44
  attr_accessor :host
36
45
 
@@ -79,7 +88,7 @@ module Raven
79
88
  attr_accessor :public_key
80
89
 
81
90
  # Turns on ActiveSupport breadcrumbs integration
82
- attr_accessor :rails_activesupport_breadcrumbs
91
+ attr_reader :rails_activesupport_breadcrumbs
83
92
 
84
93
  # Rails catches exceptions in the ActionDispatch::ShowExceptions or
85
94
  # ActionDispatch::DebugExceptions middlewares, depending on the environment.
@@ -114,6 +123,19 @@ module Raven
114
123
  # Otherwise, can be one of "http", "https", or "dummy"
115
124
  attr_accessor :scheme
116
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
+
117
139
  # Secret key for authentication with the Sentry server
118
140
  # If you provide a DSN, this will be set automatically.
119
141
  #
@@ -156,19 +178,47 @@ module Raven
156
178
  # E.g. lambda { |event| Thread.new { MyJobProcessor.send_email(event) } }
157
179
  attr_reader :transport_failure_callback
158
180
 
181
+ # Optional Proc, called before sending an event to the server/
182
+ # E.g.: lambda { |event, hint| event }
183
+ # E.g.: lambda { |event, hint| nil }
184
+ # E.g.: lambda { |event, hint|
185
+ # event[:message] = 'a'
186
+ # event
187
+ # }
188
+ attr_reader :before_send
189
+
159
190
  # Errors object - an Array that contains error messages. See #
160
191
  attr_reader :errors
161
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.
162
201
  IGNORE_DEFAULT = [
163
202
  'AbstractController::ActionNotFound',
203
+ 'ActionController::BadRequest',
164
204
  'ActionController::InvalidAuthenticityToken',
205
+ 'ActionController::InvalidCrossOriginRequest',
206
+ 'ActionController::MethodNotAllowed',
207
+ 'ActionController::NotImplemented',
208
+ 'ActionController::ParameterMissing',
165
209
  'ActionController::RoutingError',
166
210
  'ActionController::UnknownAction',
211
+ 'ActionController::UnknownFormat',
212
+ 'ActionController::UnknownHttpMethod',
213
+ 'ActionDispatch::Http::Parameters::ParseError',
214
+ 'ActionView::MissingTemplate',
215
+ 'ActiveJob::DeserializationError', # Can cause infinite loops
167
216
  'ActiveRecord::RecordNotFound',
168
217
  'CGI::Session::CookieStore::TamperedWithCookie',
169
218
  'Mongoid::Errors::DocumentNotFound',
170
- 'Sinatra::NotFound',
171
- 'ActiveJob::DeserializationError'
219
+ 'Rack::QueryParser::InvalidParameterError',
220
+ 'Rack::QueryParser::ParameterTypeError',
221
+ 'Sinatra::NotFound'
172
222
  ].freeze
173
223
 
174
224
  # Note the order - we have to remove circular references and bad characters
@@ -182,23 +232,37 @@ module Raven
182
232
  Raven::Processor::HTTPHeaders
183
233
  ].freeze
184
234
 
235
+ HEROKU_DYNO_METADATA_MESSAGE = "You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\
236
+ "release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`".freeze
237
+
238
+ RACK_ENV_WHITELIST_DEFAULT = %w(
239
+ REMOTE_ADDR
240
+ SERVER_NAME
241
+ SERVER_PORT
242
+ ).freeze
243
+
185
244
  LOG_PREFIX = "** [Raven] ".freeze
186
245
  MODULE_SEPARATOR = "::".freeze
187
246
 
247
+ AVAILABLE_BREADCRUMBS_LOGGERS = [:sentry_logger, :active_support_logger].freeze
248
+
188
249
  def initialize
189
250
  self.async = false
251
+ self.breadcrumbs_logger = []
190
252
  self.context_lines = 3
191
253
  self.current_environment = current_environment_from_env
192
254
  self.encoding = 'gzip'
193
255
  self.environments = []
194
256
  self.exclude_loggers = []
195
257
  self.excluded_exceptions = IGNORE_DEFAULT.dup
258
+ self.inspect_exception_causes_for_exclusion = false
196
259
  self.linecache = ::Raven::LineCache.new
197
260
  self.logger = ::Raven::Logger.new(STDOUT)
198
261
  self.open_timeout = 1
199
262
  self.processors = DEFAULT_PROCESSORS.dup
200
263
  self.project_root = detect_project_root
201
- self.rails_activesupport_breadcrumbs = false
264
+ @rails_activesupport_breadcrumbs = false
265
+
202
266
  self.rails_report_rescued_exceptions = true
203
267
  self.release = detect_release
204
268
  self.sample_rate = 1.0
@@ -214,10 +278,15 @@ module Raven
214
278
  self.tags = {}
215
279
  self.timeout = 2
216
280
  self.transport_failure_callback = false
281
+ self.before_send = false
282
+ self.rack_env_whitelist = RACK_ENV_WHITELIST_DEFAULT
217
283
  end
218
284
 
219
285
  def server=(value)
220
286
  return if value.nil?
287
+
288
+ @dsn = value
289
+
221
290
  uri = URI.parse(value)
222
291
  uri_path = uri.path.split('/')
223
292
 
@@ -235,13 +304,14 @@ module Raven
235
304
 
236
305
  # For anyone who wants to read the base server string
237
306
  @server = "#{scheme}://#{host}"
238
- @server << ":#{port}" unless port == { 'http' => 80, 'https' => 443 }[scheme]
239
- @server << path
307
+ @server += ":#{port}" unless port == { 'http' => 80, 'https' => 443 }[scheme]
308
+ @server += path
240
309
  end
241
310
  alias dsn= server=
242
311
 
243
312
  def encoding=(encoding)
244
313
  raise(Error, 'Unsupported encoding') unless %w(gzip json).include? encoding
314
+
245
315
  @encoding = encoding
246
316
  end
247
317
 
@@ -249,13 +319,32 @@ module Raven
249
319
  unless value == false || value.respond_to?(:call)
250
320
  raise(ArgumentError, "async must be callable (or false to disable)")
251
321
  end
322
+
252
323
  @async = value
253
324
  end
254
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
+
255
343
  def transport_failure_callback=(value)
256
344
  unless value == false || value.respond_to?(:call)
257
345
  raise(ArgumentError, "transport_failure_callback must be callable (or false to disable)")
258
346
  end
347
+
259
348
  @transport_failure_callback = value
260
349
  end
261
350
 
@@ -263,9 +352,18 @@ module Raven
263
352
  unless value == false || value.respond_to?(:call)
264
353
  raise ArgumentError, "should_capture must be callable (or false to disable)"
265
354
  end
355
+
266
356
  @should_capture = value
267
357
  end
268
358
 
359
+ def before_send=(value)
360
+ unless value == false || value.respond_to?(:call)
361
+ raise ArgumentError, "before_send must be callable (or false to disable)"
362
+ end
363
+
364
+ @before_send = value
365
+ end
366
+
269
367
  # Allows config options to be read like a hash
270
368
  #
271
369
  # @param [Symbol] option Key for a given attribute
@@ -298,6 +396,11 @@ module Raven
298
396
  Backtrace::Line.instance_variable_set(:@in_app_pattern, nil) # blow away cache
299
397
  end
300
398
 
399
+ def rails_activesupport_breadcrumbs=(val)
400
+ DeprecationHelper.deprecate_old_breadcrumbs_configuration(:active_support_logger)
401
+ @rails_activesupport_breadcrumbs = val
402
+ end
403
+
301
404
  def exception_class_allowed?(exc)
302
405
  if exc.is_a?(Raven::Error)
303
406
  # Try to prevent error reporting loops
@@ -311,6 +414,10 @@ module Raven
311
414
  end
312
415
  end
313
416
 
417
+ def enabled_in_current_env?
418
+ environments.empty? || environments.include?(current_environment)
419
+ end
420
+
314
421
  private
315
422
 
316
423
  def detect_project_root
@@ -322,21 +429,32 @@ module Raven
322
429
  end
323
430
 
324
431
  def detect_release
325
- detect_release_from_git ||
432
+ detect_release_from_env ||
433
+ detect_release_from_git ||
326
434
  detect_release_from_capistrano ||
327
435
  detect_release_from_heroku
328
- rescue => ex
329
- logger.error "Error detecting release: #{ex.message}"
436
+ rescue => e
437
+ logger.error "Error detecting release: #{e.message}"
330
438
  end
331
439
 
332
- def excluded_exception?(exc)
333
- excluded_exceptions.any? { |x| get_exception_class(x) === exc }
440
+ def excluded_exception?(incoming_exception)
441
+ excluded_exceptions.any? do |excluded_exception|
442
+ matches_exception?(get_exception_class(excluded_exception), incoming_exception)
443
+ end
334
444
  end
335
445
 
336
446
  def get_exception_class(x)
337
447
  x.is_a?(Module) ? x : qualified_const_get(x)
338
448
  end
339
449
 
450
+ def matches_exception?(excluded_exception_class, incoming_exception)
451
+ if inspect_exception_causes_for_exclusion?
452
+ Raven::Utils::ExceptionCauseChain.exception_to_array(incoming_exception).any? { |cause| excluded_exception_class === cause }
453
+ else
454
+ excluded_exception_class === incoming_exception
455
+ end
456
+ end
457
+
340
458
  # In Ruby <2.0 const_get can't lookup "SomeModule::SomeClass" in one go
341
459
  def qualified_const_get(x)
342
460
  x = x.to_s
@@ -352,7 +470,7 @@ module Raven
352
470
  def detect_release_from_heroku
353
471
  return unless running_on_heroku?
354
472
  return if ENV['CI']
355
- logger.warn(heroku_dyno_metadata_message) && return unless ENV['HEROKU_SLUG_COMMIT']
473
+ logger.warn(HEROKU_DYNO_METADATA_MESSAGE) && return unless ENV['HEROKU_SLUG_COMMIT']
356
474
 
357
475
  ENV['HEROKU_SLUG_COMMIT']
358
476
  end
@@ -361,11 +479,6 @@ module Raven
361
479
  File.directory?("/etc/heroku")
362
480
  end
363
481
 
364
- def heroku_dyno_metadata_message
365
- "You are running on Heroku but haven't enabled Dyno Metadata. For Sentry's "\
366
- "release detection to work correctly, please run `heroku labs:enable runtime-dyno-metadata`"
367
- end
368
-
369
482
  def detect_release_from_capistrano
370
483
  revision_file = File.join(project_root, 'REVISION')
371
484
  revision_log = File.join(project_root, '..', 'revisions.log')
@@ -381,20 +494,27 @@ module Raven
381
494
  Raven.sys_command("git rev-parse --short HEAD") if File.directory?(".git")
382
495
  end
383
496
 
497
+ def detect_release_from_env
498
+ ENV['SENTRY_RELEASE']
499
+ end
500
+
384
501
  def capture_in_current_environment?
385
- return true unless environments.any? && !environments.include?(current_environment)
502
+ return true if enabled_in_current_env?
503
+
386
504
  @errors << "Not configured to send/capture in environment '#{current_environment}'"
387
505
  false
388
506
  end
389
507
 
390
508
  def capture_allowed_by_callback?(message_or_exc)
391
- 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
+
392
511
  @errors << "should_capture returned false"
393
512
  false
394
513
  end
395
514
 
396
515
  def valid?
397
516
  return true if %w(server host path public_key project_id).all? { |k| public_send(k) }
517
+
398
518
  if server
399
519
  %w(server host path public_key project_id).map do |key|
400
520
  @errors << "No #{key} specified" unless public_send(key)
@@ -407,6 +527,7 @@ module Raven
407
527
 
408
528
  def sample_allowed?
409
529
  return true if sample_rate == 1.0
530
+
410
531
  if Random::DEFAULT.rand >= sample_rate
411
532
  @errors << "Excluded by random sample"
412
533
  false
@@ -423,7 +544,7 @@ module Raven
423
544
  end
424
545
 
425
546
  def current_environment_from_env
426
- ENV['SENTRY_CURRENT_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
547
+ ENV['SENTRY_CURRENT_ENV'] || ENV['SENTRY_ENVIRONMENT'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'default'
427
548
  end
428
549
 
429
550
  def server_name_from_env