raygun4ruby 3.2.3 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +18 -18
  3. data/.rspec +1 -1
  4. data/.travis.yml +20 -20
  5. data/CHANGELOG.md +127 -124
  6. data/Gemfile +4 -4
  7. data/LICENSE.txt +22 -22
  8. data/README.md +420 -420
  9. data/Rakefile +27 -27
  10. data/examples/sinatras_raygun.rb +17 -17
  11. data/lib/generators/raygun/install_generator.rb +26 -26
  12. data/lib/raygun.rb +179 -179
  13. data/lib/raygun/affected_user.rb +59 -59
  14. data/lib/raygun/breadcrumbs.rb +34 -34
  15. data/lib/raygun/breadcrumbs/breadcrumb.rb +34 -34
  16. data/lib/raygun/breadcrumbs/store.rb +86 -86
  17. data/lib/raygun/client.rb +305 -305
  18. data/lib/raygun/configuration.rb +194 -194
  19. data/lib/raygun/error.rb +10 -10
  20. data/lib/raygun/javascript_tracker.rb +42 -42
  21. data/lib/raygun/middleware/breadcrumbs_store_initializer.rb +19 -19
  22. data/lib/raygun/middleware/javascript_exception_tracking.rb +32 -32
  23. data/lib/raygun/middleware/rack_exception_interceptor.rb +18 -18
  24. data/lib/raygun/middleware/rails_insert_affected_user.rb +26 -26
  25. data/lib/raygun/railtie.rb +39 -39
  26. data/lib/raygun/services/apply_whitelist_filter_to_payload.rb +27 -27
  27. data/lib/raygun/sidekiq.rb +71 -70
  28. data/lib/raygun/testable.rb +22 -22
  29. data/lib/raygun/version.rb +3 -3
  30. data/lib/raygun4ruby.rb +1 -1
  31. data/lib/resque/failure/raygun.rb +25 -25
  32. data/lib/tasks/raygun.tasks +7 -7
  33. data/raygun4ruby.gemspec +45 -45
  34. data/spec/dummy/.gitignore +17 -17
  35. data/spec/dummy/Gemfile +47 -47
  36. data/spec/dummy/README.rdoc +28 -28
  37. data/spec/dummy/Rakefile +6 -6
  38. data/spec/dummy/app/assets/config/manifest.js +2 -2
  39. data/spec/dummy/app/assets/javascripts/application.js +13 -13
  40. data/spec/dummy/app/assets/stylesheets/application.css +15 -15
  41. data/spec/dummy/app/controllers/application_controller.rb +5 -5
  42. data/spec/dummy/app/controllers/home_controller.rb +4 -4
  43. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  44. data/spec/dummy/app/views/home/index.html.erb +3 -3
  45. data/spec/dummy/app/views/home/index.json.erb +1 -1
  46. data/spec/dummy/app/views/layouts/application.html.erb +14 -14
  47. data/spec/dummy/bin/bundle +3 -3
  48. data/spec/dummy/bin/rails +9 -9
  49. data/spec/dummy/bin/rake +9 -9
  50. data/spec/dummy/bin/setup +29 -29
  51. data/spec/dummy/bin/spring +17 -17
  52. data/spec/dummy/config.ru +4 -4
  53. data/spec/dummy/config/application.rb +26 -26
  54. data/spec/dummy/config/boot.rb +3 -3
  55. data/spec/dummy/config/database.yml +25 -25
  56. data/spec/dummy/config/environment.rb +5 -5
  57. data/spec/dummy/config/environments/development.rb +41 -41
  58. data/spec/dummy/config/environments/production.rb +79 -79
  59. data/spec/dummy/config/environments/test.rb +42 -42
  60. data/spec/dummy/config/initializers/assets.rb +11 -11
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -3
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  64. data/spec/dummy/config/initializers/inflections.rb +16 -16
  65. data/spec/dummy/config/initializers/mime_types.rb +4 -4
  66. data/spec/dummy/config/initializers/session_store.rb +3 -3
  67. data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +10 -10
  68. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  69. data/spec/dummy/config/locales/en.yml +23 -23
  70. data/spec/dummy/config/routes.rb +58 -58
  71. data/spec/dummy/config/secrets.yml +22 -22
  72. data/spec/dummy/db/seeds.rb +7 -7
  73. data/spec/dummy/public/404.html +67 -67
  74. data/spec/dummy/public/422.html +67 -67
  75. data/spec/dummy/public/500.html +66 -66
  76. data/spec/dummy/public/robots.txt +5 -5
  77. data/spec/dummy/test/test_helper.rb +10 -10
  78. data/spec/features/javascript_spec.rb +48 -48
  79. data/spec/rails_helper.rb +4 -4
  80. data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -171
  81. data/spec/raygun/breadcrumbs/store_spec.rb +170 -170
  82. data/spec/raygun/raygun_spec.rb +47 -47
  83. data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
  84. data/spec/spec_helper.rb +24 -24
  85. data/spec/support/fake_logger.rb +17 -17
  86. data/test/integration/client_test.rb +19 -19
  87. data/test/test_helper.rb +72 -72
  88. data/test/unit/affected_user_test.rb +136 -136
  89. data/test/unit/client_test.rb +792 -792
  90. data/test/unit/configuration_test.rb +206 -206
  91. data/test/unit/raygun_test.rb +25 -25
  92. data/test/unit/resque_failure_test.rb +24 -24
  93. data/test/unit/sidekiq_failure_test.rb +32 -32
  94. metadata +7 -7
@@ -1,19 +1,19 @@
1
- module Raygun
2
- module Middleware
3
- class BreadcrumbsStoreInitializer
4
- def initialize(app)
5
- @app = app
6
- end
7
-
8
- def call(env)
9
- Breadcrumbs::Store.initialize
10
-
11
- begin
12
- @app.call(env)
13
- ensure
14
- Breadcrumbs::Store.clear
15
- end
16
- end
17
- end
18
- end
19
- end
1
+ module Raygun
2
+ module Middleware
3
+ class BreadcrumbsStoreInitializer
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ Breadcrumbs::Store.initialize
10
+
11
+ begin
12
+ @app.call(env)
13
+ ensure
14
+ Breadcrumbs::Store.clear
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,32 +1,32 @@
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? && 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,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
+ 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,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,39 @@
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
+ end
35
+
36
+ rake_tasks do
37
+ load "tasks/raygun.tasks"
38
+ end
39
+ 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,70 +1,71 @@
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
- }
28
- if correlation_id = exception.instance_variable_get(:@__raygun_correlation_id)
29
- data.merge!(correlation_id: correlation_id)
30
- end
31
- ::Raygun.track_exception(
32
- exception,
33
- data,
34
- user
35
- )
36
- end
37
-
38
- # Extracts affected user information out of a Sidekiq worker class
39
- def self.affected_user(context_hash)
40
- job = context_hash[:job]
41
-
42
- return if job.nil? || job['class'].nil? || !Module.const_defined?(job['class'])
43
-
44
- worker_class = Module.const_get(job['class'])
45
- affected_user_method = Raygun.configuration.affected_user_method
46
-
47
- return if worker_class.nil? || !worker_class.respond_to?(affected_user_method)
48
-
49
- worker_class.send(affected_user_method, job['args'])
50
- rescue => e
51
- return unless Raygun.configuration.failsafe_logger
52
-
53
- failsafe_log("Problem in sidekiq affected user tracking: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}")
54
-
55
- nil
56
- end
57
- end
58
- end
59
-
60
- if Sidekiq::VERSION < '3'
61
- Sidekiq.configure_server do |config|
62
- config.server_middleware do |chain|
63
- chain.add Raygun::SidekiqMiddleware
64
- end
65
- end
66
- else
67
- Sidekiq.configure_server do |config|
68
- config.error_handlers << Raygun::SidekiqReporter
69
- end
70
- end
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