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
data/lib/raven/context.rb CHANGED
@@ -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
@@ -0,0 +1,57 @@
1
+ require 'raven/core_ext/object/duplicable'
2
+
3
+ #########################################
4
+ # This file was copied from Rails 5.2 #
5
+ #########################################
6
+
7
+ class Object
8
+ # Returns a deep copy of object if it's duplicable. If it's
9
+ # not duplicable, returns +self+.
10
+ #
11
+ # object = Object.new
12
+ # dup = object.deep_dup
13
+ # dup.instance_variable_set(:@a, 1)
14
+ #
15
+ # object.instance_variable_defined?(:@a) # => false
16
+ # dup.instance_variable_defined?(:@a) # => true
17
+ def deep_dup
18
+ duplicable? ? dup : self
19
+ end
20
+ end
21
+
22
+ class Array
23
+ # Returns a deep copy of array.
24
+ #
25
+ # array = [1, [2, 3]]
26
+ # dup = array.deep_dup
27
+ # dup[1][2] = 4
28
+ #
29
+ # array[1][2] # => nil
30
+ # dup[1][2] # => 4
31
+ def deep_dup
32
+ map(&:deep_dup)
33
+ end
34
+ end
35
+
36
+ class Hash
37
+ # Returns a deep copy of hash.
38
+ #
39
+ # hash = { a: { b: 'b' } }
40
+ # dup = hash.deep_dup
41
+ # dup[:a][:c] = 'c'
42
+ #
43
+ # hash[:a][:c] # => nil
44
+ # dup[:a][:c] # => "c"
45
+ def deep_dup
46
+ hash = dup
47
+ each_pair do |key, value|
48
+ if key.frozen? && ::String === key
49
+ hash[key] = value.deep_dup
50
+ else
51
+ hash.delete(key)
52
+ hash[key.deep_dup] = value.deep_dup
53
+ end
54
+ end
55
+ hash
56
+ end
57
+ end
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ #########################################
4
+ # This file was copied from Rails 5.2 #
5
+ #########################################
6
+
7
+ #--
8
+ # Most objects are cloneable, but not all. For example you can't dup methods:
9
+ #
10
+ # method(:puts).dup # => TypeError: allocator undefined for Method
11
+ #
12
+ # Classes may signal their instances are not duplicable removing +dup+/+clone+
13
+ # or raising exceptions from them. So, to dup an arbitrary object you normally
14
+ # use an optimistic approach and are ready to catch an exception, say:
15
+ #
16
+ # arbitrary_object.dup rescue object
17
+ #
18
+ # Rails dups objects in a few critical spots where they are not that arbitrary.
19
+ # That rescue is very expensive (like 40 times slower than a predicate), and it
20
+ # is often triggered.
21
+ #
22
+ # That's why we hardcode the following cases and check duplicable? instead of
23
+ # using that rescue idiom.
24
+ #++
25
+ class Object
26
+ # Can you safely dup this object?
27
+ #
28
+ # False for method objects;
29
+ # true otherwise.
30
+ def duplicable?
31
+ true
32
+ end
33
+ end
34
+
35
+ class NilClass
36
+ begin
37
+ nil.dup
38
+ rescue TypeError
39
+ # +nil+ is not duplicable:
40
+ #
41
+ # nil.duplicable? # => false
42
+ # nil.dup # => TypeError: can't dup NilClass
43
+ def duplicable?
44
+ false
45
+ end
46
+ end
47
+ end
48
+
49
+ class FalseClass
50
+ begin
51
+ false.dup
52
+ rescue TypeError
53
+ # +false+ is not duplicable:
54
+ #
55
+ # false.duplicable? # => false
56
+ # false.dup # => TypeError: can't dup FalseClass
57
+ def duplicable?
58
+ false
59
+ end
60
+ end
61
+ end
62
+
63
+ class TrueClass
64
+ begin
65
+ true.dup
66
+ rescue TypeError
67
+ # +true+ is not duplicable:
68
+ #
69
+ # true.duplicable? # => false
70
+ # true.dup # => TypeError: can't dup TrueClass
71
+ def duplicable?
72
+ false
73
+ end
74
+ end
75
+ end
76
+
77
+ class Symbol
78
+ begin
79
+ :symbol.dup # Ruby 2.4.x.
80
+ "symbol_from_string".to_sym.dup # Some symbols can't `dup` in Ruby 2.4.0.
81
+ rescue TypeError
82
+ # Symbols are not duplicable:
83
+ #
84
+ # :my_symbol.duplicable? # => false
85
+ # :my_symbol.dup # => TypeError: can't dup Symbol
86
+ def duplicable?
87
+ false
88
+ end
89
+ end
90
+ end
91
+
92
+ class Numeric
93
+ begin
94
+ 1.dup
95
+ rescue TypeError
96
+ # Numbers are not duplicable:
97
+ #
98
+ # 3.duplicable? # => false
99
+ # 3.dup # => TypeError: can't dup Integer
100
+ def duplicable?
101
+ false
102
+ end
103
+ end
104
+ end
105
+
106
+ require "bigdecimal"
107
+ class BigDecimal
108
+ # BigDecimals are duplicable:
109
+ #
110
+ # BigDecimal("1.2").duplicable? # => true
111
+ # BigDecimal("1.2").dup # => #<BigDecimal:...,'0.12E1',18(18)>
112
+ def duplicable?
113
+ true
114
+ end
115
+ end
116
+
117
+ class Method
118
+ # Methods are not duplicable:
119
+ #
120
+ # method(:puts).duplicable? # => false
121
+ # method(:puts).dup # => TypeError: allocator undefined for Method
122
+ def duplicable?
123
+ false
124
+ end
125
+ end
126
+
127
+ class Complex
128
+ begin
129
+ Complex(1).dup
130
+ rescue TypeError
131
+ # Complexes are not duplicable:
132
+ #
133
+ # Complex(1).duplicable? # => false
134
+ # Complex(1).dup # => TypeError: can't copy Complex
135
+ def duplicable?
136
+ false
137
+ end
138
+ end
139
+ end
140
+
141
+ class Rational
142
+ begin
143
+ Rational(1).dup
144
+ rescue TypeError
145
+ # Rationals are not duplicable:
146
+ #
147
+ # Rational(1).duplicable? # => false
148
+ # Rational(1).dup # => TypeError: can't copy Rational
149
+ def duplicable?
150
+ false
151
+ end
152
+ end
153
+ end
data/lib/raven/event.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'socket'
3
4
  require 'securerandom'
4
5
 
@@ -7,6 +8,7 @@ module Raven
7
8
  # See Sentry server default limits at
8
9
  # https://github.com/getsentry/sentry/blob/master/src/sentry/conf/server.py
9
10
  MAX_MESSAGE_SIZE_IN_BYTES = 1024 * 8
11
+ REQUIRED_OPTION_KEYS = [:configuration, :context, :breadcrumbs].freeze
10
12
 
11
13
  SDK = { "name" => "raven-ruby", "version" => Raven::VERSION }.freeze
12
14
 
@@ -18,7 +20,7 @@ module Raven
18
20
 
19
21
  attr_reader :level, :timestamp, :time_spent
20
22
 
21
- def initialize(init = {})
23
+ def initialize(options)
22
24
  # Set some simple default values
23
25
  self.id = SecureRandom.uuid.delete("-")
24
26
  self.timestamp = Time.now.utc
@@ -35,11 +37,17 @@ module Raven
35
37
  self.runtime = {} # TODO: contexts
36
38
  self.tags = {} # TODO: contexts
37
39
 
38
- copy_initial_state
40
+ unless REQUIRED_OPTION_KEYS.all? { |key| options.key?(key) }
41
+ raise "you much provide configuration, context, and breadcrumbs when initializing a Raven::Event"
42
+ end
43
+
44
+ self.configuration = options[:configuration]
45
+ self.context = options[:context]
46
+ self.breadcrumbs = options[:breadcrumbs]
39
47
 
40
48
  # Allow attributes to be set on the event at initialization
41
49
  yield self if block_given?
42
- init.each_pair { |key, val| public_send("#{key}=", val) unless val.nil? }
50
+ options.each_pair { |key, val| public_send("#{key}=", val) unless val.nil? }
43
51
 
44
52
  set_core_attributes_from_configuration
45
53
  set_core_attributes_from_context
@@ -55,14 +63,10 @@ module Raven
55
63
  end
56
64
  options = Raven::Utils::DeepMergeHash.deep_merge(exception_context, options)
57
65
 
58
- configuration = options[:configuration] || Raven.configuration
59
- return unless configuration.exception_class_allowed?(exc)
66
+ return unless options[:configuration].exception_class_allowed?(exc)
60
67
 
61
68
  new(options) do |evt|
62
- evt.message = "#{exc.class}: #{exc.message}"
63
-
64
69
  evt.add_exception_interface(exc)
65
-
66
70
  yield evt if block
67
71
  end
68
72
  end
@@ -79,11 +83,21 @@ module Raven
79
83
  end
80
84
 
81
85
  def message
82
- @interfaces[:logentry] && @interfaces[:logentry].unformatted_message
86
+ @interfaces[:logentry]&.unformatted_message
83
87
  end
84
88
 
85
89
  def message=(args)
86
- message, params = *args
90
+ if args.is_a?(Array)
91
+ message, params = args[0], args[0..-1]
92
+ else
93
+ message = args
94
+ end
95
+
96
+ unless message.is_a?(String)
97
+ configuration.logger.debug("You're passing a non-string message")
98
+ message = message.to_s
99
+ end
100
+
87
101
  interface(:message) do |int|
88
102
  int.message = message.byteslice(0...MAX_MESSAGE_SIZE_IN_BYTES) # Messages limited to 10kb
89
103
  int.params = params
@@ -99,12 +113,13 @@ module Raven
99
113
  end
100
114
 
101
115
  def level=(new_level) # needed to meet the Sentry spec
102
- @level = new_level == "warn" || new_level == :warn ? :warning : new_level
116
+ @level = new_level.to_s == "warn" ? :warning : new_level
103
117
  end
104
118
 
105
119
  def interface(name, value = nil, &block)
106
120
  int = Interface.registered[name]
107
121
  raise(Error, "Unknown interface: #{name}") unless int
122
+
108
123
  @interfaces[int.sentry_alias] = int.new(value, &block) if value || block
109
124
  @interfaces[int.sentry_alias]
110
125
  end
@@ -139,7 +154,7 @@ module Raven
139
154
 
140
155
  def add_exception_interface(exc)
141
156
  interface(:exception) do |exc_int|
142
- exceptions = exception_chain_to_array(exc)
157
+ exceptions = Raven::Utils::ExceptionCauseChain.exception_to_array(exc).reverse
143
158
  backtraces = Set.new
144
159
  exc_int.values = exceptions.map do |e|
145
160
  SingleExceptionInterface.new do |int|
@@ -160,7 +175,7 @@ module Raven
160
175
  end
161
176
 
162
177
  def stacktrace_interface_from(backtrace)
163
- Backtrace.parse(backtrace).lines.reverse.each_with_object([]) do |line, memo|
178
+ Backtrace.parse(backtrace, { configuration: configuration }).lines.reverse.each_with_object([]) do |line, memo|
164
179
  frame = StacktraceInterface::Frame.new
165
180
  frame.abs_path = line.file if line.file
166
181
  frame.function = line.method if line.method
@@ -187,12 +202,6 @@ module Raven
187
202
 
188
203
  private
189
204
 
190
- def copy_initial_state
191
- self.configuration = Raven.configuration
192
- self.breadcrumbs = Raven.breadcrumbs
193
- self.context = Raven.context
194
- end
195
-
196
205
  def set_core_attributes_from_configuration
197
206
  self.server_name ||= configuration.server_name
198
207
  self.release ||= configuration.release
@@ -231,24 +240,7 @@ module Raven
231
240
  end
232
241
 
233
242
  def async_json_processors
234
- [
235
- Raven::Processor::RemoveCircularReferences,
236
- Raven::Processor::UTF8Conversion
237
- ].map { |v| v.new(self) }
238
- end
239
-
240
- def exception_chain_to_array(exc)
241
- if exc.respond_to?(:cause) && exc.cause
242
- exceptions = [exc]
243
- while exc.cause
244
- exc = exc.cause
245
- break if exceptions.any? { |e| e.object_id == exc.object_id }
246
- exceptions << exc
247
- end
248
- exceptions.reverse!
249
- else
250
- [exc]
251
- end
243
+ configuration.processors.map { |v| v.new(self) }
252
244
  end
253
245
 
254
246
  def list_gem_specs
@@ -0,0 +1,17 @@
1
+ module DeprecationHelper
2
+ def self.deprecate_dasherized_filename(correct_filename)
3
+ warn "[Deprecation Warning] Dasherized filename \"#{correct_filename.gsub('_', '-')}\" is deprecated and will be removed in 4.0; use \"#{correct_filename}\" instead" # rubocop:disable Style/LineLength
4
+ end
5
+
6
+ def self.deprecate_old_breadcrumbs_configuration(logger)
7
+ deprecated_usage =
8
+ if logger == :sentry_logger
9
+ "require \"raven/breadcrumbs/logger\""
10
+ else
11
+ "Raven.configuration.rails_activesupport_breadcrumbs = true"
12
+ end
13
+ recommended_usage = "Raven.configuration.breadcrumbs_logger = :#{logger}"
14
+
15
+ warn "[Deprecation Warning] The way you enable breadcrumbs logger (#{deprecated_usage}) is deprecated and will be removed in 4.0; use '#{recommended_usage}' instead" # rubocop:disable Style/LineLength
16
+ end
17
+ end
@@ -50,7 +50,9 @@ module Raven
50
50
 
51
51
  # Tell the log that the client is good to go
52
52
  def report_status
53
+ return unless configuration.enabled_in_current_env?
53
54
  return if configuration.silence_ready
55
+
54
56
  if configuration.capture_allowed?
55
57
  logger.info "Raven #{VERSION} ready to catch errors"
56
58
  else
@@ -75,10 +77,10 @@ module Raven
75
77
  # Send an event to the configured Sentry server
76
78
  #
77
79
  # @example
78
- # evt = Raven::Event.new(:message => "An error")
80
+ # evt = Raven::Event.new(:message => "An errore)
79
81
  # Raven.send_event(evt)
80
- def send_event(event)
81
- client.send_event(event)
82
+ def send_event(event, hint = nil)
83
+ client.send_event(event, hint)
82
84
  end
83
85
 
84
86
  # Capture and process any exceptions from the given block.
@@ -109,21 +111,24 @@ module Raven
109
111
  end
110
112
 
111
113
  message_or_exc = obj.is_a?(String) ? "message" : "exception"
114
+ options = options.deep_dup
112
115
  options[:configuration] = configuration
113
116
  options[:context] = context
114
- if (evt = Event.send("from_" + message_or_exc, obj, options))
117
+ options[:breadcrumbs] = breadcrumbs
118
+
119
+ if evt = Event.send("from_" + message_or_exc, obj, options)
115
120
  yield evt if block_given?
116
121
  if configuration.async?
117
122
  begin
118
123
  # We have to convert to a JSON-like hash, because background job
119
124
  # processors (esp ActiveJob) may not like weird types in the event hash
120
125
  configuration.async.call(evt.to_json_compatible)
121
- rescue => ex
122
- logger.error("async event sending failed: #{ex.message}")
123
- send_event(evt)
126
+ rescue => e
127
+ logger.error("async event sending failed: #{e.message}")
128
+ send_event(evt, make_hint(obj))
124
129
  end
125
130
  else
126
- send_event(evt)
131
+ send_event(evt, make_hint(obj))
127
132
  end
128
133
  Thread.current["sentry_#{object_id}_last_event_id".to_sym] = evt.id
129
134
  evt
@@ -171,7 +176,12 @@ module Raven
171
176
  # @example
172
177
  # Raven.user_context('id' => 1, 'email' => 'foo@example.com')
173
178
  def user_context(options = nil)
179
+ original_user_context = context.user
174
180
  context.user = options || {}
181
+ yield if block_given?
182
+ context.user
183
+ ensure
184
+ context.user = original_user_context if block_given?
175
185
  end
176
186
 
177
187
  # Bind tags context. Merges with existing context (if any).
@@ -183,6 +193,10 @@ module Raven
183
193
  # Raven.tags_context('my_custom_tag' => 'tag_value')
184
194
  def tags_context(options = nil)
185
195
  context.tags.merge!(options || {})
196
+ yield if block_given?
197
+ context.tags
198
+ ensure
199
+ context.tags.delete_if { |k, _| options.keys.include? k } if block_given?
186
200
  end
187
201
 
188
202
  # Bind extra context. Merges with existing context (if any).
@@ -194,6 +208,10 @@ module Raven
194
208
  # Raven.extra_context('my_custom_data' => 'value')
195
209
  def extra_context(options = nil)
196
210
  context.extra.merge!(options || {})
211
+ yield if block_given?
212
+ context.extra
213
+ ensure
214
+ context.extra.delete_if { |k, _| options.keys.include? k } if block_given?
197
215
  end
198
216
 
199
217
  def rack_context(env)
@@ -217,5 +235,9 @@ module Raven
217
235
  end
218
236
  end
219
237
  end
238
+
239
+ def make_hint(obj)
240
+ obj.is_a?(String) ? { :exception => nil, :message => obj } : { :exception => obj, :message => nil }
241
+ end
220
242
  end
221
243
  end