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
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,179 +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
- 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
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