raygun4ruby 3.1.1 → 3.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +18 -18
  3. data/.rspec +1 -1
  4. data/.travis.yml +20 -12
  5. data/CHANGELOG.md +127 -109
  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 -182
  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 -30
  16. data/lib/raygun/breadcrumbs/store.rb +86 -76
  17. data/lib/raygun/client.rb +305 -302
  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 -67
  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 -0
  35. data/spec/dummy/Gemfile +47 -0
  36. data/spec/dummy/README.rdoc +28 -0
  37. data/spec/dummy/Rakefile +6 -6
  38. data/spec/dummy/app/assets/config/manifest.js +3 -3
  39. data/spec/dummy/app/assets/images/.keep +0 -0
  40. data/spec/dummy/app/assets/javascripts/application.js +13 -15
  41. data/spec/dummy/app/assets/stylesheets/application.css +15 -15
  42. data/spec/dummy/app/controllers/application_controller.rb +5 -2
  43. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  44. data/spec/dummy/app/controllers/home_controller.rb +4 -4
  45. data/spec/dummy/app/helpers/application_helper.rb +2 -2
  46. data/spec/dummy/app/{assets/javascripts/channels → mailers}/.keep +0 -0
  47. data/spec/dummy/{storage → app/models}/.keep +0 -0
  48. data/spec/dummy/app/models/concerns/.keep +0 -0
  49. data/spec/dummy/app/views/home/index.html.erb +3 -3
  50. data/spec/dummy/app/views/home/index.json.erb +1 -1
  51. data/spec/dummy/app/views/layouts/application.html.erb +14 -15
  52. data/spec/dummy/bin/bundle +3 -3
  53. data/spec/dummy/bin/rails +9 -4
  54. data/spec/dummy/bin/rake +9 -4
  55. data/spec/dummy/bin/setup +29 -36
  56. data/spec/dummy/bin/spring +17 -0
  57. data/spec/dummy/config.ru +4 -5
  58. data/spec/dummy/config/application.rb +26 -18
  59. data/spec/dummy/config/boot.rb +3 -5
  60. data/spec/dummy/config/database.yml +25 -25
  61. data/spec/dummy/config/environment.rb +5 -5
  62. data/spec/dummy/config/environments/development.rb +41 -61
  63. data/spec/dummy/config/environments/production.rb +79 -94
  64. data/spec/dummy/config/environments/test.rb +42 -46
  65. data/spec/dummy/config/initializers/assets.rb +11 -14
  66. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -7
  67. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -5
  68. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -4
  69. data/spec/dummy/config/initializers/inflections.rb +16 -16
  70. data/spec/dummy/config/initializers/mime_types.rb +4 -4
  71. data/spec/dummy/config/initializers/session_store.rb +3 -0
  72. data/spec/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -14
  74. data/spec/dummy/config/locales/en.yml +23 -33
  75. data/spec/dummy/config/routes.rb +58 -3
  76. data/spec/dummy/config/secrets.yml +22 -0
  77. data/spec/dummy/db/seeds.rb +7 -0
  78. data/spec/dummy/db/test.sqlite3 +0 -0
  79. data/spec/dummy/lib/assets/.keep +0 -0
  80. data/spec/dummy/{public/apple-touch-icon-precomposed.png → lib/tasks/.keep} +0 -0
  81. data/spec/dummy/public/404.html +67 -67
  82. data/spec/dummy/public/422.html +67 -67
  83. data/spec/dummy/public/500.html +66 -66
  84. data/spec/dummy/public/favicon.ico +0 -0
  85. data/spec/dummy/public/robots.txt +5 -0
  86. data/spec/dummy/{public/apple-touch-icon.png → test/controllers/.keep} +0 -0
  87. data/spec/dummy/test/fixtures/.keep +0 -0
  88. data/spec/dummy/test/helpers/.keep +0 -0
  89. data/spec/dummy/test/integration/.keep +0 -0
  90. data/spec/dummy/test/mailers/.keep +0 -0
  91. data/spec/dummy/test/models/.keep +0 -0
  92. data/spec/dummy/test/test_helper.rb +10 -0
  93. data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
  94. data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
  95. data/spec/features/javascript_spec.rb +48 -48
  96. data/spec/rails_helper.rb +4 -4
  97. data/spec/raygun/breadcrumbs/breadcrumb_spec.rb +171 -134
  98. data/spec/raygun/breadcrumbs/store_spec.rb +170 -146
  99. data/spec/raygun/raygun_spec.rb +47 -47
  100. data/spec/services/apply_whitelist_filter_to_payload_spec.rb +251 -251
  101. data/spec/spec_helper.rb +24 -24
  102. data/spec/support/fake_logger.rb +17 -17
  103. data/test/integration/client_test.rb +19 -19
  104. data/test/test_helper.rb +72 -72
  105. data/test/unit/affected_user_test.rb +136 -136
  106. data/test/unit/client_test.rb +792 -790
  107. data/test/unit/configuration_test.rb +206 -206
  108. data/test/unit/raygun_test.rb +25 -25
  109. data/test/unit/resque_failure_test.rb +24 -24
  110. data/test/unit/sidekiq_failure_test.rb +32 -32
  111. metadata +42 -45
  112. data/spec/dummy/.ruby-version +0 -1
  113. data/spec/dummy/app/assets/javascripts/cable.js +0 -13
  114. data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
  115. data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
  116. data/spec/dummy/app/jobs/application_job.rb +0 -2
  117. data/spec/dummy/app/mailers/application_mailer.rb +0 -4
  118. data/spec/dummy/app/models/application_record.rb +0 -3
  119. data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
  120. data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
  121. data/spec/dummy/bin/update +0 -31
  122. data/spec/dummy/bin/yarn +0 -11
  123. data/spec/dummy/config/cable.yml +0 -10
  124. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
  125. data/spec/dummy/config/initializers/content_security_policy.rb +0 -25
  126. data/spec/dummy/config/puma.rb +0 -34
  127. data/spec/dummy/config/spring.rb +0 -6
  128. data/spec/dummy/config/storage.yml +0 -34
  129. data/spec/dummy/db/schema.rb +0 -15
  130. data/spec/dummy/package.json +0 -5
data/Rakefile CHANGED
@@ -1,27 +1,27 @@
1
- #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
3
-
4
- require "rake/testtask"
5
-
6
- namespace :test do
7
-
8
- desc "Test the basics of the adapter"
9
- Rake::TestTask.new(:units) do |t|
10
- t.test_files = FileList["test/unit/*_test.rb"]
11
- end
12
-
13
- desc "Run a test against the live API"
14
- Rake::TestTask.new(:integration) do |t|
15
- t.test_files = FileList["test/integration/*_test.rb"]
16
- end
17
-
18
- begin
19
- require 'rspec/core/rake_task'
20
-
21
- RSpec::Core::RakeTask.new(:spec)
22
-
23
- rescue LoadError
24
- end
25
- end
26
-
27
- task default: ["test:units", "test:spec"]
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rake/testtask"
5
+
6
+ namespace :test do
7
+
8
+ desc "Test the basics of the adapter"
9
+ Rake::TestTask.new(:units) do |t|
10
+ t.test_files = FileList["test/unit/*_test.rb"]
11
+ end
12
+
13
+ desc "Run a test against the live API"
14
+ Rake::TestTask.new(:integration) do |t|
15
+ t.test_files = FileList["test/integration/*_test.rb"]
16
+ end
17
+
18
+ begin
19
+ require 'rspec/core/rake_task'
20
+
21
+ RSpec::Core::RakeTask.new(:spec)
22
+
23
+ rescue LoadError
24
+ end
25
+ end
26
+
27
+ task default: ["test:units", "test:spec"]
@@ -1,18 +1,18 @@
1
- # NB: You'll need to install the 'sinatra' gem for this to work :)
2
- # $ gem install sinatra
3
- # $ ruby sinatras_raygun.rb
4
-
5
- require 'sinatra'
6
- require_relative '../lib/raygun4ruby'
7
-
8
- Raygun.setup do |config|
9
- config.api_key = YOUR_RAYGUN_API_KEY_HERE
10
- end
11
-
12
- use Raygun::RackExceptionInterceptor
13
-
14
- set :raise_errors, true
15
-
16
- get '/' do
17
- raise "This is an exception that will be sent to Raygun!"
1
+ # NB: You'll need to install the 'sinatra' gem for this to work :)
2
+ # $ gem install sinatra
3
+ # $ ruby sinatras_raygun.rb
4
+
5
+ require 'sinatra'
6
+ require_relative '../lib/raygun4ruby'
7
+
8
+ Raygun.setup do |config|
9
+ config.api_key = YOUR_RAYGUN_API_KEY_HERE
10
+ end
11
+
12
+ use Raygun::RackExceptionInterceptor
13
+
14
+ set :raise_errors, true
15
+
16
+ get '/' do
17
+ raise "This is an exception that will be sent to Raygun!"
18
18
  end
@@ -1,26 +1,26 @@
1
- module Raygun
2
- class InstallGenerator < Rails::Generators::Base
3
-
4
- argument :api_key
5
-
6
- desc "This generator creates a configuration file for the Raygun ruby adapter inside config/initializers"
7
- def create_configuration_file
8
- filter_parameters = if defined?(Rails)
9
- "config.filter_parameters = Rails.application.config.filter_parameters"
10
- else
11
- "config.filter_parameters = [ :password, :card_number, :cvv ] # don't forget to filter out sensitive parameters"
12
- end
13
- initializer "raygun.rb" do
14
- <<-EOS
15
- Raygun.setup do |config|
16
- config.api_key = "#{api_key}"
17
- #{filter_parameters}
18
-
19
- # The default is Rails.env.production?
20
- # config.enable_reporting = !Rails.env.development? && !Rails.env.test?
21
- end
22
- EOS
23
- end
24
- end
25
- end
26
- end
1
+ module Raygun
2
+ class InstallGenerator < Rails::Generators::Base
3
+
4
+ argument :api_key
5
+
6
+ desc "This generator creates a configuration file for the Raygun ruby adapter inside config/initializers"
7
+ def create_configuration_file
8
+ filter_parameters = if defined?(Rails)
9
+ "config.filter_parameters = Rails.application.config.filter_parameters"
10
+ else
11
+ "config.filter_parameters = [ :password, :card_number, :cvv ] # don't forget to filter out sensitive parameters"
12
+ end
13
+ initializer "raygun.rb" do
14
+ <<-EOS
15
+ Raygun.setup do |config|
16
+ config.api_key = "#{api_key}"
17
+ #{filter_parameters}
18
+
19
+ # The default is Rails.env.production?
20
+ # config.enable_reporting = !Rails.env.development? && !Rails.env.test?
21
+ end
22
+ EOS
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/raygun.rb CHANGED
@@ -1,182 +1,179 @@
1
- require "concurrent"
2
- require "httparty"
3
- require "logger"
4
- require "json"
5
- require "socket"
6
- require "rack"
7
- require "ostruct"
8
-
9
- begin
10
- require "pry"
11
- rescue LoadError
12
- end
13
-
14
- require "raygun/version"
15
- require "raygun/configuration"
16
- require "raygun/client"
17
- require "raygun/javascript_tracker"
18
- require "raygun/middleware/rack_exception_interceptor"
19
- require "raygun/middleware/breadcrumbs_store_initializer"
20
- require "raygun/middleware/javascript_exception_tracking"
21
- require "raygun/testable"
22
- require "raygun/error"
23
- require "raygun/affected_user"
24
- require "raygun/services/apply_whitelist_filter_to_payload"
25
- require "raygun/breadcrumbs/breadcrumb"
26
- require "raygun/breadcrumbs/store"
27
- require "raygun/breadcrumbs"
28
- require "raygun/railtie" if defined?(Rails)
29
-
30
- module Raygun
31
-
32
- # used to identify ourselves to Raygun
33
- CLIENT_URL = "https://github.com/MindscapeHQ/raygun4ruby"
34
- CLIENT_NAME = "Raygun4Ruby Gem"
35
-
36
- class << self
37
- include Testable
38
-
39
- # Configuration Object (instance of Raygun::Configuration)
40
- attr_writer :configuration
41
-
42
- def setup
43
- yield(configuration)
44
-
45
- log("configuration settings: #{configuration.inspect}")
46
- end
47
-
48
- def configuration
49
- @configuration ||= Configuration.new
50
- end
51
-
52
- def default_configuration
53
- configuration.defaults
54
- end
55
-
56
- def reset_configuration
57
- @configuration = Configuration.new
58
- end
59
-
60
- def configured?
61
- !!configuration.api_key
62
- end
63
-
64
- def track_exception(exception_instance, env = {}, user = nil, retry_count = 1)
65
- log('tracking exception')
66
-
67
- if configuration.send_in_background
68
- track_exception_async(exception_instance, env, user, retry_count)
69
- else
70
- track_exception_sync(exception_instance, env, user, retry_count)
71
- end
72
- end
73
-
74
- def track_exceptions
75
- yield
76
- rescue => e
77
- track_exception(e)
78
- end
79
-
80
- def record_breadcrumb(
81
- message: nil,
82
- category: '',
83
- level: :info,
84
- timestamp: Time.now.utc,
85
- metadata: {},
86
- class_name: nil,
87
- method_name: nil,
88
- line_number: nil
89
- )
90
- log('recording breadcrumb')
91
-
92
- Raygun::Breadcrumbs::Store.record(
93
- message: message,
94
- category: category,
95
- level: level,
96
- timestamp: timestamp,
97
- metadata: metadata,
98
- class_name: class_name,
99
- method_name: method_name,
100
- line_number: line_number,
101
- )
102
- end
103
-
104
- def log(message)
105
- return unless configuration.debug
106
-
107
- configuration.logger.info("[Raygun] #{message}") if configuration.logger
108
- end
109
-
110
- def failsafe_log(message)
111
- configuration.failsafe_logger.info(message)
112
- end
113
-
114
- def deprecation_warning(message)
115
- if defined?(ActiveSupport::Deprecation)
116
- ActiveSupport::Deprecation.warn(message)
117
- else
118
- puts message
119
- end
120
- end
121
-
122
- private
123
-
124
- def track_exception_async(*args)
125
- future = Concurrent::Future.execute { track_exception_sync(*args) }
126
- future.add_observer(lambda do |_, value, reason|
127
- if value == nil || !value.responds_to?(:response) || value.response.code != "202"
128
- log("unexpected response from Raygun, could indicate error: #{value.inspect}")
129
- end
130
- end, :call)
131
- end
132
-
133
- def track_exception_sync(exception_instance, env, user, retry_count)
134
- if should_report?(exception_instance)
135
- log('attempting to send exception')
136
- resp = Client.new.track_exception(exception_instance, env, user)
137
- log('sent payload to api')
138
-
139
- resp
140
- end
141
- rescue Exception => e
142
- log('error sending exception to raygun, see failsafe logger for more information')
143
-
144
- if configuration.failsafe_logger
145
- failsafe_log("Problem reporting exception to Raygun: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}")
146
- end
147
-
148
- if retry_count > 0
149
- new_exception = e.exception("raygun4ruby encountered an exception processing your exception")
150
- new_exception.set_backtrace(e.backtrace)
151
-
152
- env[:custom_data] ||= {}
153
- env[:custom_data].merge!(original_stacktrace: exception_instance.backtrace)
154
-
155
- track_exception(new_exception, env, user, retry_count - 1)
156
- else
157
- raise e
158
- end
159
- end
160
-
161
-
162
- def print_api_key_warning
163
- $stderr.puts(NO_API_KEY_MESSAGE)
164
- end
165
-
166
- def should_report?(exception)
167
- if configuration.silence_reporting
168
- log('skipping reporting because Configuration.silence_reporting is enabled')
169
-
170
- return false
171
- end
172
-
173
- if configuration.ignore.flatten.include?(exception.class.to_s)
174
- log("skipping reporting of exception #{exception.class} because it is in the ignore list")
175
-
176
- return false
177
- end
178
-
179
- true
180
- end
181
- end
182
- end
1
+ require "concurrent"
2
+ require "httparty"
3
+ require "logger"
4
+ require "json"
5
+ require "socket"
6
+ require "rack"
7
+ require "ostruct"
8
+
9
+ require "raygun/version"
10
+ require "raygun/configuration"
11
+ require "raygun/client"
12
+ require "raygun/javascript_tracker"
13
+ require "raygun/middleware/rack_exception_interceptor"
14
+ require "raygun/middleware/breadcrumbs_store_initializer"
15
+ require "raygun/middleware/javascript_exception_tracking"
16
+ require "raygun/testable"
17
+ require "raygun/error"
18
+ require "raygun/affected_user"
19
+ require "raygun/services/apply_whitelist_filter_to_payload"
20
+ require "raygun/breadcrumbs/breadcrumb"
21
+ require "raygun/breadcrumbs/store"
22
+ require "raygun/breadcrumbs"
23
+ require "raygun/railtie" if defined?(Rails)
24
+
25
+ module Raygun
26
+
27
+ # used to identify ourselves to Raygun
28
+ CLIENT_URL = "https://github.com/MindscapeHQ/raygun4ruby"
29
+ CLIENT_NAME = "Raygun4Ruby Gem"
30
+
31
+ class << self
32
+ include Testable
33
+
34
+ # Configuration Object (instance of Raygun::Configuration)
35
+ attr_writer :configuration
36
+
37
+ def setup
38
+ yield(configuration)
39
+
40
+ log("configuration settings: #{configuration.inspect}")
41
+ end
42
+
43
+ def configuration
44
+ @configuration ||= Configuration.new
45
+ end
46
+
47
+ def default_configuration
48
+ configuration.defaults
49
+ end
50
+
51
+ def reset_configuration
52
+ @configuration = Configuration.new
53
+ end
54
+
55
+ def configured?
56
+ !!configuration.api_key
57
+ end
58
+
59
+ def track_exception(exception_instance, env = {}, user = nil, retry_count = 1)
60
+ log('tracking exception')
61
+
62
+ if configuration.send_in_background
63
+ track_exception_async(exception_instance, env, user, retry_count)
64
+ else
65
+ track_exception_sync(exception_instance, env, user, retry_count)
66
+ end
67
+ end
68
+
69
+ def track_exceptions
70
+ yield
71
+ rescue => e
72
+ track_exception(e)
73
+ end
74
+
75
+ def record_breadcrumb(
76
+ message: nil,
77
+ category: '',
78
+ level: :info,
79
+ timestamp: Time.now.utc,
80
+ metadata: {},
81
+ class_name: nil,
82
+ method_name: nil,
83
+ line_number: nil
84
+ )
85
+ log('recording breadcrumb')
86
+
87
+ Raygun::Breadcrumbs::Store.record(
88
+ message: message,
89
+ category: category,
90
+ level: level,
91
+ timestamp: timestamp,
92
+ metadata: metadata,
93
+ class_name: class_name,
94
+ method_name: method_name,
95
+ line_number: line_number,
96
+ )
97
+ end
98
+
99
+ def log(message)
100
+ return unless configuration.debug
101
+
102
+ configuration.logger.info("[Raygun] #{message}") if configuration.logger
103
+ end
104
+
105
+ def failsafe_log(message)
106
+ configuration.failsafe_logger.info(message)
107
+ end
108
+
109
+ def deprecation_warning(message)
110
+ if defined?(ActiveSupport::Deprecation)
111
+ ActiveSupport::Deprecation.warn(message)
112
+ else
113
+ puts message
114
+ end
115
+ end
116
+
117
+ private
118
+
119
+ def track_exception_async(*args)
120
+ future = Concurrent::Future.execute { track_exception_sync(*args) }
121
+ future.add_observer(lambda do |_, value, reason|
122
+ if value == nil || !value.responds_to?(:response) || value.response.code != "202"
123
+ log("unexpected response from Raygun, could indicate error: #{value.inspect}")
124
+ end
125
+ end, :call)
126
+ end
127
+
128
+ def track_exception_sync(exception_instance, env, user, retry_count)
129
+ if should_report?(exception_instance)
130
+ log('attempting to send exception')
131
+ resp = Client.new.track_exception(exception_instance, env, user)
132
+ log('sent payload to api')
133
+
134
+ resp
135
+ end
136
+ rescue Exception => e
137
+ log('error sending exception to raygun, see failsafe logger for more information')
138
+
139
+ if configuration.failsafe_logger
140
+ failsafe_log("Problem reporting exception to Raygun: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}")
141
+ end
142
+
143
+ if retry_count > 0
144
+ new_exception = e.exception("raygun4ruby encountered an exception processing your exception")
145
+ new_exception.set_backtrace(e.backtrace)
146
+
147
+ env[:custom_data] ||= {}
148
+ env[:custom_data].merge!(original_stacktrace: exception_instance.backtrace)
149
+
150
+ ::Raygun::Breadcrumbs::Store.clear
151
+
152
+ track_exception(new_exception, env, user, retry_count - 1)
153
+ else
154
+ raise e
155
+ end
156
+ end
157
+
158
+
159
+ def print_api_key_warning
160
+ $stderr.puts(NO_API_KEY_MESSAGE)
161
+ end
162
+
163
+ def should_report?(exception)
164
+ if configuration.silence_reporting
165
+ log('skipping reporting because Configuration.silence_reporting is enabled')
166
+
167
+ return false
168
+ end
169
+
170
+ if configuration.ignore.flatten.include?(exception.class.to_s)
171
+ log("skipping reporting of exception #{exception.class} because it is in the ignore list")
172
+
173
+ return false
174
+ end
175
+
176
+ true
177
+ end
178
+ end
179
+ end