raygun4ruby 3.2.6 → 4.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (232) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +48 -0
  3. data/.gitignore +22 -21
  4. data/.rspec +1 -1
  5. data/Appraisals +19 -0
  6. data/CHANGELOG.md +169 -133
  7. data/Gemfile +4 -4
  8. data/LICENSE.txt +22 -22
  9. data/README.md +424 -420
  10. data/Rakefile +32 -27
  11. data/examples/sinatras_raygun.rb +17 -17
  12. data/gemfiles/rails_6.gemfile +9 -0
  13. data/gemfiles/rails_7.gemfile +10 -0
  14. data/gemfiles/rails_7_sidekiq_6.gemfile +10 -0
  15. data/lib/generators/raygun/install_generator.rb +26 -26
  16. data/lib/raygun/affected_user.rb +59 -59
  17. data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -34
  18. data/lib/raygun/breadcrumbs/store.rb +86 -86
  19. data/lib/raygun/breadcrumbs.rb +34 -34
  20. data/lib/raygun/client.rb +313 -308
  21. data/lib/raygun/configuration.rb +197 -194
  22. data/lib/raygun/demo_exception.rb +22 -22
  23. data/lib/raygun/error.rb +10 -10
  24. data/lib/raygun/error_subscriber.rb +21 -0
  25. data/lib/raygun/javascript_tracker.rb +42 -42
  26. data/lib/raygun/middleware/breadcrumbs_store_initializer.rb +19 -19
  27. data/lib/raygun/middleware/javascript_exception_tracking.rb +40 -32
  28. data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -18
  29. data/lib/raygun/middleware/rails_insert_affected_user.rb +26 -26
  30. data/lib/raygun/railtie.rb +47 -39
  31. data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
  32. data/lib/raygun/sidekiq.rb +51 -71
  33. data/lib/raygun/version.rb +3 -3
  34. data/lib/raygun.rb +197 -179
  35. data/lib/raygun4ruby.rb +1 -1
  36. data/lib/resque/failure/raygun.rb +25 -25
  37. data/lib/tasks/raygun.tasks +7 -7
  38. data/raygun4ruby.gemspec +43 -45
  39. data/spec/features/javascript_spec.rb +48 -48
  40. data/spec/rails_applications/6.1.4/Gemfile +56 -0
  41. data/spec/{dummy/README.rdoc → rails_applications/6.1.4/README.md} +24 -28
  42. data/spec/{dummy → rails_applications/6.1.4}/Rakefile +6 -6
  43. data/spec/rails_applications/6.1.4/app/assets/config/manifest.js +2 -0
  44. data/spec/{dummy → rails_applications/6.1.4}/app/assets/images/.keep +0 -0
  45. data/spec/{dummy → rails_applications/6.1.4}/app/assets/stylesheets/application.css +15 -15
  46. data/spec/rails_applications/6.1.4/app/channels/application_cable/channel.rb +4 -0
  47. data/spec/rails_applications/6.1.4/app/channels/application_cable/connection.rb +4 -0
  48. data/spec/rails_applications/6.1.4/app/controllers/application_controller.rb +2 -0
  49. data/spec/{dummy → rails_applications/6.1.4}/app/controllers/concerns/.keep +0 -0
  50. data/spec/{dummy → rails_applications/6.1.4}/app/controllers/home_controller.rb +4 -4
  51. data/spec/{dummy → rails_applications/6.1.4}/app/helpers/application_helper.rb +2 -2
  52. data/spec/rails_applications/6.1.4/app/javascript/channels/consumer.js +6 -0
  53. data/spec/rails_applications/6.1.4/app/javascript/channels/index.js +5 -0
  54. data/spec/rails_applications/6.1.4/app/javascript/packs/application.js +13 -0
  55. data/spec/rails_applications/6.1.4/app/jobs/application_job.rb +7 -0
  56. data/spec/rails_applications/6.1.4/app/mailers/application_mailer.rb +4 -0
  57. data/spec/rails_applications/6.1.4/app/models/application_record.rb +3 -0
  58. data/spec/{dummy/app/mailers → rails_applications/6.1.4/app/models/concerns}/.keep +0 -0
  59. data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.html.erb +3 -3
  60. data/spec/{dummy → rails_applications/6.1.4}/app/views/home/index.json.erb +1 -1
  61. data/spec/rails_applications/6.1.4/app/views/layouts/application.html.erb +13 -0
  62. data/spec/rails_applications/6.1.4/app/views/layouts/mailer.html.erb +13 -0
  63. data/spec/rails_applications/6.1.4/app/views/layouts/mailer.text.erb +1 -0
  64. data/spec/rails_applications/6.1.4/bin/rails +5 -0
  65. data/spec/rails_applications/6.1.4/bin/rake +5 -0
  66. data/spec/rails_applications/6.1.4/bin/setup +36 -0
  67. data/spec/rails_applications/6.1.4/bin/spring +14 -0
  68. data/spec/rails_applications/6.1.4/bin/yarn +17 -0
  69. data/spec/rails_applications/6.1.4/config/application.rb +22 -0
  70. data/spec/rails_applications/6.1.4/config/boot.rb +3 -0
  71. data/spec/rails_applications/6.1.4/config/cable.yml +10 -0
  72. data/spec/rails_applications/6.1.4/config/credentials.yml.enc +1 -0
  73. data/spec/{dummy → rails_applications/6.1.4}/config/database.yml +25 -25
  74. data/spec/{dummy → rails_applications/6.1.4}/config/environment.rb +5 -5
  75. data/spec/rails_applications/6.1.4/config/environments/development.rb +76 -0
  76. data/spec/rails_applications/6.1.4/config/environments/production.rb +120 -0
  77. data/spec/rails_applications/6.1.4/config/environments/test.rb +60 -0
  78. data/spec/rails_applications/6.1.4/config/initializers/application_controller_renderer.rb +8 -0
  79. data/spec/rails_applications/6.1.4/config/initializers/assets.rb +14 -0
  80. data/spec/rails_applications/6.1.4/config/initializers/backtrace_silencers.rb +8 -0
  81. data/spec/rails_applications/6.1.4/config/initializers/content_security_policy.rb +30 -0
  82. data/spec/{dummy → rails_applications/6.1.4}/config/initializers/cookies_serializer.rb +5 -3
  83. data/spec/{dummy → rails_applications/6.1.4}/config/initializers/filter_parameter_logging.rb +6 -4
  84. data/spec/{dummy → rails_applications/6.1.4}/config/initializers/inflections.rb +16 -16
  85. data/spec/{dummy → rails_applications/6.1.4}/config/initializers/mime_types.rb +4 -4
  86. data/spec/rails_applications/6.1.4/config/initializers/permissions_policy.rb +11 -0
  87. data/spec/{dummy → rails_applications/6.1.4}/config/initializers/wrap_parameters.rb +14 -14
  88. data/spec/{dummy → rails_applications/6.1.4}/config/locales/en.yml +33 -23
  89. data/spec/rails_applications/6.1.4/config/master.key +1 -0
  90. data/spec/rails_applications/6.1.4/config/puma.rb +43 -0
  91. data/spec/rails_applications/6.1.4/config/routes.rb +4 -0
  92. data/spec/rails_applications/6.1.4/config/spring.rb +6 -0
  93. data/spec/rails_applications/6.1.4/config/storage.yml +34 -0
  94. data/spec/{dummy → rails_applications/6.1.4}/config.ru +6 -4
  95. data/spec/rails_applications/6.1.4/db/seeds.rb +7 -0
  96. data/spec/{dummy → rails_applications/6.1.4}/db/test.sqlite3 +0 -0
  97. data/spec/{dummy/app/models → rails_applications/6.1.4/lib/assets}/.keep +0 -0
  98. data/spec/{dummy/app/models/concerns → rails_applications/6.1.4/lib/tasks}/.keep +0 -0
  99. data/spec/rails_applications/6.1.4/package.json +11 -0
  100. data/spec/{dummy → rails_applications/6.1.4}/public/404.html +67 -67
  101. data/spec/{dummy → rails_applications/6.1.4}/public/422.html +67 -67
  102. data/spec/{dummy → rails_applications/6.1.4}/public/500.html +66 -66
  103. data/spec/{dummy/lib/assets/.keep → rails_applications/6.1.4/public/apple-touch-icon-precomposed.png} +0 -0
  104. data/spec/{dummy/lib/tasks/.keep → rails_applications/6.1.4/public/apple-touch-icon.png} +0 -0
  105. data/spec/{dummy → rails_applications/6.1.4}/public/favicon.ico +0 -0
  106. data/spec/rails_applications/6.1.4/public/robots.txt +1 -0
  107. data/spec/{dummy/log → rails_applications/6.1.4/storage}/.keep +0 -0
  108. data/spec/rails_applications/7.1.3/.dockerignore +37 -0
  109. data/spec/rails_applications/7.1.3/.gitattributes +9 -0
  110. data/spec/rails_applications/7.1.3/.gitignore +35 -0
  111. data/spec/rails_applications/7.1.3/.ruby-version +1 -0
  112. data/spec/rails_applications/7.1.3/Dockerfile +62 -0
  113. data/spec/rails_applications/7.1.3/Gemfile +67 -0
  114. data/spec/rails_applications/7.1.3/README.md +24 -0
  115. data/spec/rails_applications/7.1.3/Rakefile +6 -0
  116. data/spec/rails_applications/7.1.3/app/assets/config/manifest.js +4 -0
  117. data/spec/{dummy/test/controllers → rails_applications/7.1.3/app/assets/images}/.keep +0 -0
  118. data/spec/rails_applications/7.1.3/app/assets/stylesheets/application.css +15 -0
  119. data/spec/rails_applications/7.1.3/app/channels/application_cable/channel.rb +4 -0
  120. data/spec/rails_applications/7.1.3/app/channels/application_cable/connection.rb +4 -0
  121. data/spec/rails_applications/7.1.3/app/controllers/application_controller.rb +2 -0
  122. data/spec/{dummy/test/fixtures → rails_applications/7.1.3/app/controllers/concerns}/.keep +0 -0
  123. data/spec/rails_applications/7.1.3/app/controllers/home_controller.rb +2 -0
  124. data/spec/rails_applications/7.1.3/app/helpers/application_helper.rb +2 -0
  125. data/spec/rails_applications/7.1.3/app/helpers/home_helper.rb +2 -0
  126. data/spec/rails_applications/7.1.3/app/javascript/application.js +3 -0
  127. data/spec/rails_applications/7.1.3/app/javascript/controllers/application.js +9 -0
  128. data/spec/rails_applications/7.1.3/app/javascript/controllers/hello_controller.js +7 -0
  129. data/spec/rails_applications/7.1.3/app/javascript/controllers/index.js +11 -0
  130. data/spec/rails_applications/7.1.3/app/jobs/application_job.rb +7 -0
  131. data/spec/rails_applications/7.1.3/app/mailers/application_mailer.rb +4 -0
  132. data/spec/rails_applications/7.1.3/app/models/application_record.rb +3 -0
  133. data/spec/{dummy/test/helpers → rails_applications/7.1.3/app/models/concerns}/.keep +0 -0
  134. data/spec/rails_applications/7.1.3/app/views/home/index.html.erb +3 -0
  135. data/spec/rails_applications/7.1.3/app/views/home/index.json.erb +1 -0
  136. data/spec/rails_applications/7.1.3/app/views/layouts/application.html.erb +16 -0
  137. data/spec/rails_applications/7.1.3/app/views/layouts/mailer.html.erb +13 -0
  138. data/spec/rails_applications/7.1.3/app/views/layouts/mailer.text.erb +1 -0
  139. data/spec/rails_applications/7.1.3/bin/bundle +109 -0
  140. data/spec/rails_applications/7.1.3/bin/docker-entrypoint +8 -0
  141. data/spec/rails_applications/7.1.3/bin/importmap +4 -0
  142. data/spec/rails_applications/7.1.3/bin/rails +4 -0
  143. data/spec/rails_applications/7.1.3/bin/rake +4 -0
  144. data/spec/rails_applications/7.1.3/bin/setup +33 -0
  145. data/spec/rails_applications/7.1.3/config/application.rb +27 -0
  146. data/spec/rails_applications/7.1.3/config/boot.rb +4 -0
  147. data/spec/rails_applications/7.1.3/config/cable.yml +11 -0
  148. data/spec/rails_applications/7.1.3/config/credentials.yml.enc +1 -0
  149. data/spec/rails_applications/7.1.3/config/database.yml +25 -0
  150. data/spec/rails_applications/7.1.3/config/environment.rb +5 -0
  151. data/spec/rails_applications/7.1.3/config/environments/development.rb +76 -0
  152. data/spec/rails_applications/7.1.3/config/environments/production.rb +97 -0
  153. data/spec/rails_applications/7.1.3/config/environments/test.rb +64 -0
  154. data/spec/rails_applications/7.1.3/config/importmap.rb +7 -0
  155. data/spec/rails_applications/7.1.3/config/initializers/assets.rb +12 -0
  156. data/spec/rails_applications/7.1.3/config/initializers/content_security_policy.rb +25 -0
  157. data/spec/rails_applications/7.1.3/config/initializers/filter_parameter_logging.rb +8 -0
  158. data/spec/rails_applications/7.1.3/config/initializers/inflections.rb +16 -0
  159. data/spec/rails_applications/7.1.3/config/initializers/permissions_policy.rb +13 -0
  160. data/spec/rails_applications/7.1.3/config/locales/en.yml +31 -0
  161. data/spec/rails_applications/7.1.3/config/puma.rb +35 -0
  162. data/spec/rails_applications/7.1.3/config/routes.rb +11 -0
  163. data/spec/rails_applications/7.1.3/config/storage.yml +34 -0
  164. data/spec/rails_applications/7.1.3/config.ru +6 -0
  165. data/spec/rails_applications/7.1.3/db/seeds.rb +9 -0
  166. data/spec/{dummy/test/integration → rails_applications/7.1.3/lib/assets}/.keep +0 -0
  167. data/spec/{dummy/test/mailers → rails_applications/7.1.3/lib/tasks}/.keep +0 -0
  168. data/spec/rails_applications/7.1.3/public/404.html +67 -0
  169. data/spec/rails_applications/7.1.3/public/422.html +67 -0
  170. data/spec/rails_applications/7.1.3/public/500.html +66 -0
  171. data/spec/{dummy/test/models/.keep → rails_applications/7.1.3/public/apple-touch-icon-precomposed.png} +0 -0
  172. data/spec/{dummy/vendor/assets/javascripts/.keep → rails_applications/7.1.3/public/apple-touch-icon.png} +0 -0
  173. data/spec/{dummy/vendor/assets/stylesheets/.keep → rails_applications/7.1.3/public/favicon.ico} +0 -0
  174. data/spec/rails_applications/7.1.3/public/robots.txt +1 -0
  175. data/spec/rails_applications/7.1.3/storage/.keep +0 -0
  176. data/spec/rails_applications/7.1.3/test/application_system_test_case.rb +5 -0
  177. data/spec/rails_applications/7.1.3/test/channels/application_cable/connection_test.rb +13 -0
  178. data/spec/rails_applications/7.1.3/test/controllers/.keep +0 -0
  179. data/spec/rails_applications/7.1.3/test/controllers/home_controller_test.rb +7 -0
  180. data/spec/rails_applications/7.1.3/test/fixtures/files/.keep +0 -0
  181. data/spec/rails_applications/7.1.3/test/helpers/.keep +0 -0
  182. data/spec/rails_applications/7.1.3/test/integration/.keep +0 -0
  183. data/spec/rails_applications/7.1.3/test/mailers/.keep +0 -0
  184. data/spec/rails_applications/7.1.3/test/models/.keep +0 -0
  185. data/spec/rails_applications/7.1.3/test/system/.keep +0 -0
  186. data/spec/rails_applications/7.1.3/test/test_helper.rb +15 -0
  187. data/spec/rails_applications/7.1.3/vendor/.keep +0 -0
  188. data/spec/rails_applications/7.1.3/vendor/javascript/.keep +0 -0
  189. data/spec/rails_helper.rb +8 -4
  190. data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -171
  191. data/spec/raygun/breadcrumbs/store_spec.rb +170 -170
  192. data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
  193. data/spec/spec_helper.rb +24 -24
  194. data/spec/support/fake_logger.rb +17 -17
  195. data/test/integration/client_test.rb +19 -19
  196. data/test/rails_helper.rb +6 -0
  197. data/test/test_helper.rb +76 -72
  198. data/test/unit/affected_user_test.rb +136 -136
  199. data/test/unit/client_test.rb +812 -812
  200. data/test/unit/configuration_test.rb +202 -206
  201. data/test/unit/error_subscriber_test.rb +43 -0
  202. data/test/unit/raygun_test.rb +106 -25
  203. data/test/unit/resque_failure_test.rb +27 -24
  204. data/test/unit/sidekiq_failure_test.rb +42 -32
  205. metadata +186 -125
  206. data/.travis.yml +0 -20
  207. data/spec/dummy/.gitignore +0 -17
  208. data/spec/dummy/Gemfile +0 -47
  209. data/spec/dummy/app/assets/config/manifest.js +0 -3
  210. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  211. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  212. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  213. data/spec/dummy/bin/bundle +0 -3
  214. data/spec/dummy/bin/rails +0 -9
  215. data/spec/dummy/bin/rake +0 -9
  216. data/spec/dummy/bin/setup +0 -29
  217. data/spec/dummy/bin/spring +0 -17
  218. data/spec/dummy/config/application.rb +0 -26
  219. data/spec/dummy/config/boot.rb +0 -3
  220. data/spec/dummy/config/environments/development.rb +0 -41
  221. data/spec/dummy/config/environments/production.rb +0 -79
  222. data/spec/dummy/config/environments/test.rb +0 -42
  223. data/spec/dummy/config/initializers/assets.rb +0 -11
  224. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  225. data/spec/dummy/config/initializers/session_store.rb +0 -3
  226. data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +0 -10
  227. data/spec/dummy/config/routes.rb +0 -58
  228. data/spec/dummy/config/secrets.yml +0 -22
  229. data/spec/dummy/db/seeds.rb +0 -7
  230. data/spec/dummy/public/robots.txt +0 -5
  231. data/spec/dummy/test/test_helper.rb +0 -10
  232. data/spec/raygun/raygun_spec.rb +0 -47
@@ -1,32 +1,40 @@
1
- module Raygun::Middleware
2
- class JavascriptExceptionTracking
3
- def initialize(app)
4
- @app = app
5
- end
6
-
7
- def call(env)
8
- status, headers, response = @app.call(env)
9
-
10
- # It's a html file, inject our JS
11
- if headers['Content-Type'] && headers['Content-Type'].include?('text/html')
12
- response = inject_javascript_to_response(response)
13
- end
14
-
15
- [status, headers, response]
16
- end
17
-
18
- def inject_javascript_to_response(response)
19
- if Raygun.configuration.js_api_key.present? && response.respond_to?('[]')
20
- response[0].gsub!('</head>', "#{js_tracker.head_html}</head>")
21
- response[0].gsub!('</body>', "#{js_tracker.body_html}</body>")
22
- end
23
-
24
- response
25
- end
26
-
27
- private
28
- def js_tracker
29
- @js_tracker = Raygun::JavaScriptTracker.new
30
- end
31
- end
32
- end
1
+ module Raygun::Middleware
2
+ class JavascriptExceptionTracking
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ status, headers, response = @app.call(env)
9
+
10
+ # It's a html file, inject our JS
11
+ if headers['Content-Type'] && headers['Content-Type'].include?('text/html')
12
+ response = inject_javascript_to_response(response)
13
+ end
14
+
15
+ [status, headers, response]
16
+ end
17
+
18
+ def inject_javascript_to_response(response)
19
+ if Raygun.configuration.js_api_key.present?
20
+ if response.respond_to?('[]')
21
+ response[0].gsub!('</head>', "#{js_tracker.head_html}</head>")
22
+ response[0].gsub!('</body>', "#{js_tracker.body_html}</body>")
23
+ end
24
+
25
+ if response.respond_to?(:body) # Rack::BodyProxy
26
+ body = response.body
27
+ body.gsub!('</head>', "#{js_tracker.head_html}</head>")
28
+ body.gsub!('</body>', "#{js_tracker.body_html}</body>")
29
+ end
30
+ end
31
+
32
+ response
33
+ end
34
+
35
+ private
36
+ def js_tracker
37
+ @js_tracker = Raygun::JavaScriptTracker.new
38
+ end
39
+ end
40
+ end
@@ -1,18 +1,18 @@
1
- module Raygun
2
- module Middleware
3
- class RackExceptionInterceptor
4
-
5
- def initialize(app)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- response = @app.call(env)
11
- rescue Exception => exception
12
- Raygun.track_exception(exception, env) if Raygun.configured?
13
- raise exception
14
- end
15
-
16
- end
17
- end
18
- end
1
+ module Raygun
2
+ module Middleware
3
+ class RackExceptionInterceptor
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ @app.call(env)
11
+ rescue Exception => exception
12
+ Raygun.track_exception(exception, env) if Raygun.configured?
13
+ raise exception
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -1,26 +1,26 @@
1
- module Raygun
2
- module Middleware
3
- # Adapted from the Rollbar approach https://github.com/rollbar/rollbar-gem/blob/master/lib/rollbar/middleware/rails/rollbar_request_store.rb
4
- class RailsInsertAffectedUser
5
-
6
- def initialize(app)
7
- @app = app
8
- end
9
-
10
- def call(env)
11
- @app.call(env)
12
- rescue Exception => exception
13
- controller = env["action_controller.instance"]
14
- affected_user_method = Raygun.configuration.affected_user_method
15
-
16
- if controller && controller.respond_to?(affected_user_method, true)
17
- user = controller.send(affected_user_method)
18
-
19
- env["raygun.affected_user"] = Raygun::AffectedUser.information_hash(user)
20
- end
21
-
22
- raise exception
23
- end
24
- end
25
- end
26
- end
1
+ module Raygun
2
+ module Middleware
3
+ # Adapted from the Rollbar approach https://github.com/rollbar/rollbar-gem/blob/master/lib/rollbar/middleware/rails/rollbar_request_store.rb
4
+ class RailsInsertAffectedUser
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ @app.call(env)
12
+ rescue Exception => exception
13
+ controller = env["action_controller.instance"]
14
+ affected_user_method = Raygun.configuration.affected_user_method
15
+
16
+ if controller && controller.respond_to?(affected_user_method, true)
17
+ user = controller.send(affected_user_method)
18
+
19
+ env["raygun.affected_user"] = Raygun::AffectedUser.information_hash(user)
20
+ end
21
+
22
+ raise exception
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,39 +1,47 @@
1
- require "raygun/middleware/rails_insert_affected_user"
2
-
3
- class Raygun::Railtie < Rails::Railtie
4
- initializer "raygun.configure_rails_initialization" do |app|
5
-
6
- # Thanks Airbrake: See https://github.com/rails/rails/pull/8624
7
- middleware = if defined?(ActionDispatch::DebugExceptions)
8
- if Rails::VERSION::STRING >= "5"
9
- ActionDispatch::DebugExceptions
10
- else
11
- # Rails >= 3.2.0
12
- "ActionDispatch::DebugExceptions"
13
- end
14
- else
15
- # Rails < 3.2.0
16
- "ActionDispatch::ShowExceptions"
17
- end
18
-
19
- raygun_middleware = [
20
- Raygun::Middleware::RailsInsertAffectedUser,
21
- Raygun::Middleware::RackExceptionInterceptor,
22
- Raygun::Middleware::BreadcrumbsStoreInitializer,
23
- Raygun::Middleware::JavascriptExceptionTracking
24
- ]
25
- raygun_middleware = raygun_middleware.map(&:to_s) unless Rails::VERSION::STRING >= "5"
26
- raygun_middleware.each do |m|
27
- app.config.middleware.insert_after(middleware, m)
28
- end
29
- end
30
-
31
- config.to_prepare do
32
- Raygun.default_configuration.logger = Rails.logger
33
- Raygun.default_configuration.enable_reporting = Rails.env.production?
34
- end
35
-
36
- rake_tasks do
37
- load "tasks/raygun.tasks"
38
- end
39
- end
1
+ require "raygun/middleware/rails_insert_affected_user"
2
+
3
+ class Raygun::Railtie < Rails::Railtie
4
+ initializer "raygun.configure_rails_initialization" do |app|
5
+
6
+ # Thanks Airbrake: See https://github.com/rails/rails/pull/8624
7
+ middleware = if defined?(ActionDispatch::DebugExceptions)
8
+ if Rails::VERSION::STRING >= "5"
9
+ ActionDispatch::DebugExceptions
10
+ else
11
+ # Rails >= 3.2.0
12
+ "ActionDispatch::DebugExceptions"
13
+ end
14
+ else
15
+ # Rails < 3.2.0
16
+ "ActionDispatch::ShowExceptions"
17
+ end
18
+
19
+ raygun_middleware = [
20
+ Raygun::Middleware::RailsInsertAffectedUser,
21
+ Raygun::Middleware::RackExceptionInterceptor,
22
+ Raygun::Middleware::BreadcrumbsStoreInitializer,
23
+ Raygun::Middleware::JavascriptExceptionTracking
24
+ ]
25
+ raygun_middleware = raygun_middleware.map(&:to_s) unless Rails::VERSION::STRING >= "5"
26
+ raygun_middleware.each do |m|
27
+ app.config.middleware.insert_after(middleware, m)
28
+ end
29
+ end
30
+
31
+ config.to_prepare do
32
+ Raygun.default_configuration.logger = Rails.logger
33
+ Raygun.default_configuration.enable_reporting = Rails.env.production?
34
+
35
+ Raygun::Railtie.setup_error_subscriber
36
+ end
37
+
38
+ rake_tasks do
39
+ load "tasks/raygun.tasks"
40
+ end
41
+
42
+ def self.setup_error_subscriber
43
+ if ::Rails.version.to_f >= 7.0 && Raygun.configuration.register_rails_error_handler
44
+ Rails.error.subscribe(Raygun::ErrorSubscriber.new)
45
+ end
46
+ end
47
+ end
@@ -1,27 +1,27 @@
1
- module Raygun
2
- module Services
3
- class ApplyWhitelistFilterToPayload
4
- def call(whitelist, payload)
5
- filter_hash(whitelist, payload)
6
- end
7
-
8
- private
9
-
10
- def filter_hash(whitelist, hash)
11
- # dup the input so each level of the hash is dup'd
12
- # not just the top as dup isn't deep
13
- hash = hash.dup
14
-
15
- hash.each do |k, v|
16
- unless whitelist && (whitelist[k] || whitelist[k.to_sym])
17
- hash[k] = '[FILTERED]'
18
- end
19
-
20
- if v.is_a?(Hash) && whitelist[k].is_a?(Hash)
21
- hash[k] = filter_hash(whitelist[k], v)
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
1
+ module Raygun
2
+ module Services
3
+ class ApplyWhitelistFilterToPayload
4
+ def call(whitelist, payload)
5
+ filter_hash(whitelist, payload)
6
+ end
7
+
8
+ private
9
+
10
+ def filter_hash(whitelist, hash)
11
+ # dup the input so each level of the hash is dup'd
12
+ # not just the top as dup isn't deep
13
+ hash = hash.dup
14
+
15
+ hash.each do |k, v|
16
+ unless whitelist && (whitelist[k] || whitelist[k.to_sym])
17
+ hash[k] = '[FILTERED]'
18
+ end
19
+
20
+ if v.is_a?(Hash) && whitelist[k].is_a?(Hash)
21
+ hash[k] = filter_hash(whitelist[k], v)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,71 +1,51 @@
1
- # Adapted from Bugsnag code as per Sidekiq 2.x comment request
2
- #
3
- # SideKiq 2.x: https://github.com/mperham/sidekiq/blob/2-x/lib/sidekiq/exception_handler.rb
4
- # Bugsnag: https://github.com/bugsnag/bugsnag-ruby/blob/master/lib/bugsnag/sidekiq.rb
5
-
6
- module Raygun
7
-
8
- class SidekiqMiddleware # Used for Sidekiq 2.x only
9
- def call(worker, message, queue)
10
- begin
11
- yield
12
- rescue Exception => ex
13
- raise ex if [Interrupt, SystemExit, SignalException].include?(ex.class)
14
- SidekiqReporter.call(ex, worker: worker, message: message, queue: queue)
15
- raise ex
16
- end
17
- end
18
- end
19
-
20
- class SidekiqReporter
21
- def self.call(exception, context_hash)
22
- user = affected_user(context_hash)
23
- data = {
24
- custom_data: {
25
- sidekiq_context: context_hash
26
- },
27
- tags: ['sidekiq']
28
- }
29
- if correlation_id = exception.instance_variable_get(:@__raygun_correlation_id)
30
- data.merge!(correlation_id: correlation_id)
31
- end
32
- ::Raygun.track_exception(
33
- exception,
34
- data,
35
- user
36
- )
37
- end
38
-
39
- # Extracts affected user information out of a Sidekiq worker class
40
- def self.affected_user(context_hash)
41
- job = context_hash[:job]
42
-
43
- return if job.nil? || job['class'].nil? || !Module.const_defined?(job['class'])
44
-
45
- worker_class = Module.const_get(job['class'])
46
- affected_user_method = Raygun.configuration.affected_user_method
47
-
48
- return if worker_class.nil? || !worker_class.respond_to?(affected_user_method)
49
-
50
- worker_class.send(affected_user_method, job['args'])
51
- rescue => e
52
- return unless Raygun.configuration.failsafe_logger
53
-
54
- failsafe_log("Problem in sidekiq affected user tracking: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}")
55
-
56
- nil
57
- end
58
- end
59
- end
60
-
61
- if Sidekiq::VERSION < '3'
62
- Sidekiq.configure_server do |config|
63
- config.server_middleware do |chain|
64
- chain.add Raygun::SidekiqMiddleware
65
- end
66
- end
67
- else
68
- Sidekiq.configure_server do |config|
69
- config.error_handlers << Raygun::SidekiqReporter
70
- end
71
- end
1
+ # Adapted from Bugsnag code, and Sidekiq Erorr Handling instructions
2
+ #
3
+ # SideKiq: https://github.com/sidekiq/sidekiq/wiki/Error-Handling
4
+ # Bugsnag: https://github.com/bugsnag/bugsnag-ruby/blob/master/lib/bugsnag/sidekiq.rb
5
+
6
+ module Raygun
7
+
8
+ class SidekiqReporter
9
+ def self.call(exception, context_hash, config)
10
+ user = affected_user(context_hash)
11
+ data = {
12
+ custom_data: {
13
+ sidekiq_context: context_hash
14
+ },
15
+ tags: ['sidekiq']
16
+ }
17
+ if exception.instance_variable_defined?(:@__raygun_correlation_id) && correlation_id = exception.instance_variable_get(:@__raygun_correlation_id)
18
+ data.merge!(correlation_id: correlation_id)
19
+ end
20
+ ::Raygun.track_exception(
21
+ exception,
22
+ data,
23
+ user
24
+ )
25
+ end
26
+
27
+ # Extracts affected user information out of a Sidekiq worker class
28
+ def self.affected_user(context_hash)
29
+ job = context_hash[:job]
30
+
31
+ return if job.nil? || job['class'].nil? || !Module.const_defined?(job['class'])
32
+
33
+ worker_class = Module.const_get(job['class'])
34
+ affected_user_method = Raygun.configuration.affected_user_method
35
+
36
+ return if worker_class.nil? || !worker_class.respond_to?(affected_user_method)
37
+
38
+ worker_class.send(affected_user_method, job['args'])
39
+ rescue => e
40
+ return unless Raygun.configuration.failsafe_logger
41
+
42
+ failsafe_log("Problem in sidekiq affected user tracking: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}")
43
+
44
+ nil
45
+ end
46
+ end
47
+ end
48
+
49
+ Sidekiq.configure_server do |config|
50
+ config.error_handlers << Raygun::SidekiqReporter
51
+ end
@@ -1,3 +1,3 @@
1
- module Raygun
2
- VERSION = "3.2.6"
3
- end
1
+ module Raygun
2
+ VERSION = "4.0.0.pre"
3
+ end