rollbar 2.16.2 → 2.22.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/.rubocop.yml +47 -0
  3. data/.travis.yml +182 -94
  4. data/Appraisals +10 -10
  5. data/Gemfile +45 -13
  6. data/README.md +20 -3
  7. data/Rakefile +0 -0
  8. data/data/rollbar.snippet.js +1 -1
  9. data/docs/configuration.md +15 -0
  10. data/gemfiles/rails30.gemfile +21 -14
  11. data/gemfiles/rails31.gemfile +21 -12
  12. data/gemfiles/rails32.gemfile +18 -8
  13. data/gemfiles/rails40.gemfile +18 -6
  14. data/gemfiles/rails41.gemfile +17 -6
  15. data/gemfiles/rails42.gemfile +24 -14
  16. data/gemfiles/rails50.gemfile +20 -11
  17. data/gemfiles/rails51.gemfile +20 -10
  18. data/gemfiles/rails52.gemfile +65 -0
  19. data/gemfiles/rails60.gemfile +67 -0
  20. data/lib/generators/rollbar/rollbar_generator.rb +1 -1
  21. data/lib/rails/rollbar_runner.rb +17 -2
  22. data/lib/rollbar.rb +2 -3
  23. data/lib/rollbar/capistrano.rb +71 -39
  24. data/lib/rollbar/capistrano3.rb +56 -1
  25. data/lib/rollbar/capistrano_tasks.rb +130 -0
  26. data/lib/rollbar/configuration.rb +95 -7
  27. data/lib/rollbar/delay/active_job.rb +17 -0
  28. data/lib/rollbar/delay/girl_friday.rb +2 -2
  29. data/lib/rollbar/delay/resque.rb +4 -6
  30. data/lib/rollbar/delay/shoryuken.rb +15 -9
  31. data/lib/rollbar/delay/sidekiq.rb +6 -8
  32. data/lib/rollbar/delay/sucker_punch.rb +17 -19
  33. data/lib/rollbar/delay/thread.rb +3 -3
  34. data/lib/rollbar/deploy.rb +90 -0
  35. data/lib/rollbar/encoding/encoder.rb +9 -9
  36. data/lib/rollbar/exception_reporter.rb +19 -5
  37. data/lib/rollbar/item.rb +62 -20
  38. data/lib/rollbar/item/backtrace.rb +4 -4
  39. data/lib/rollbar/item/frame.rb +7 -1
  40. data/lib/rollbar/item/locals.rb +56 -0
  41. data/lib/rollbar/json.rb +5 -51
  42. data/lib/rollbar/language_support.rb +4 -20
  43. data/lib/rollbar/lazy_store.rb +5 -5
  44. data/lib/rollbar/logger.rb +1 -0
  45. data/lib/rollbar/logger_proxy.rb +15 -2
  46. data/lib/rollbar/middleware/js.rb +110 -10
  47. data/lib/rollbar/middleware/js/json_value.rb +26 -0
  48. data/lib/rollbar/middleware/rack.rb +4 -1
  49. data/lib/rollbar/middleware/rails/rollbar.rb +10 -1
  50. data/lib/rollbar/notifier.rb +118 -49
  51. data/lib/rollbar/notifier/trace_with_bindings.rb +65 -0
  52. data/lib/rollbar/plugin.rb +54 -6
  53. data/lib/rollbar/plugins.rb +7 -1
  54. data/lib/rollbar/plugins/active_job.rb +5 -1
  55. data/lib/rollbar/plugins/basic_socket.rb +21 -6
  56. data/lib/rollbar/plugins/delayed_job/job_data.rb +3 -3
  57. data/lib/rollbar/plugins/delayed_job/plugin.rb +3 -3
  58. data/lib/rollbar/plugins/goalie.rb +11 -3
  59. data/lib/rollbar/plugins/rails/controller_methods.rb +17 -4
  60. data/lib/rollbar/plugins/rails/railtie_mixin.rb +7 -3
  61. data/lib/rollbar/plugins/rake.rb +2 -2
  62. data/lib/rollbar/plugins/sidekiq/plugin.rb +10 -6
  63. data/lib/rollbar/rake_tasks.rb +3 -86
  64. data/lib/rollbar/request_data_extractor.rb +35 -21
  65. data/lib/rollbar/rollbar_test.rb +147 -0
  66. data/lib/rollbar/scrubbers.rb +7 -3
  67. data/lib/rollbar/scrubbers/params.rb +38 -20
  68. data/lib/rollbar/scrubbers/url.rb +27 -13
  69. data/lib/rollbar/truncation.rb +9 -2
  70. data/lib/rollbar/truncation/min_body_strategy.rb +2 -3
  71. data/lib/rollbar/truncation/remove_any_key_strategy.rb +123 -0
  72. data/lib/rollbar/truncation/remove_extra_strategy.rb +35 -0
  73. data/lib/rollbar/truncation/remove_request_strategy.rb +21 -0
  74. data/lib/rollbar/truncation/strings_strategy.rb +3 -4
  75. data/lib/rollbar/util.rb +75 -45
  76. data/lib/rollbar/util/hash.rb +30 -6
  77. data/lib/rollbar/util/ip_anonymizer.rb +8 -7
  78. data/lib/rollbar/util/ip_obfuscator.rb +1 -1
  79. data/lib/rollbar/version.rb +1 -1
  80. data/lib/tasks/benchmark.rake +103 -0
  81. data/rollbar.gemspec +14 -8
  82. metadata +25 -277
  83. data/gemfiles/ruby_1_8_and_1_9_2.gemfile +0 -49
  84. data/lib/rollbar/json/default.rb +0 -11
  85. data/lib/rollbar/json/oj.rb +0 -16
  86. data/lib/rollbar/tasks/rollbar.cap +0 -47
  87. data/spec/cacert.pem +0 -3988
  88. data/spec/controllers/home_controller_spec.rb +0 -480
  89. data/spec/delay/sidekiq_spec.rb +0 -61
  90. data/spec/delay/sucker_punch_spec.rb +0 -25
  91. data/spec/delayed/backend/test.rb +0 -140
  92. data/spec/delayed/serialization/test.rb +0 -0
  93. data/spec/dummyapp/.gitignore +0 -73
  94. data/spec/dummyapp/Rakefile +0 -7
  95. data/spec/dummyapp/app/assets/javascripts/application.js +0 -3
  96. data/spec/dummyapp/app/assets/stylesheets/application.css.scss +0 -37
  97. data/spec/dummyapp/app/controllers/application_controller.rb +0 -3
  98. data/spec/dummyapp/app/controllers/home_controller.rb +0 -60
  99. data/spec/dummyapp/app/controllers/users_controller.rb +0 -17
  100. data/spec/dummyapp/app/helpers/.gitkeep +0 -0
  101. data/spec/dummyapp/app/mailers/.gitkeep +0 -0
  102. data/spec/dummyapp/app/models/.gitkeep +0 -0
  103. data/spec/dummyapp/app/models/book.rb +0 -5
  104. data/spec/dummyapp/app/models/post.rb +0 -9
  105. data/spec/dummyapp/app/models/user.rb +0 -9
  106. data/spec/dummyapp/app/views/devise/registrations/edit.html.erb +0 -27
  107. data/spec/dummyapp/app/views/devise/registrations/new.html.erb +0 -20
  108. data/spec/dummyapp/app/views/devise/shared/_links.html.erb +0 -25
  109. data/spec/dummyapp/app/views/home/cause_exception.html.erb +0 -1
  110. data/spec/dummyapp/app/views/home/index.html.erb +0 -4
  111. data/spec/dummyapp/app/views/home/report_exception.html.erb +0 -1
  112. data/spec/dummyapp/app/views/js/test.html.erb +0 -1
  113. data/spec/dummyapp/app/views/layouts/_messages.html.erb +0 -5
  114. data/spec/dummyapp/app/views/layouts/_navigation.html.erb +0 -21
  115. data/spec/dummyapp/app/views/layouts/application.html.erb +0 -25
  116. data/spec/dummyapp/app/views/layouts/simple.html.erb +0 -18
  117. data/spec/dummyapp/app/views/users/index.html.erb +0 -8
  118. data/spec/dummyapp/app/views/users/show.html.erb +0 -3
  119. data/spec/dummyapp/config.ru +0 -4
  120. data/spec/dummyapp/config/application.rb +0 -59
  121. data/spec/dummyapp/config/boot.rb +0 -10
  122. data/spec/dummyapp/config/database.yml +0 -25
  123. data/spec/dummyapp/config/environment.rb +0 -5
  124. data/spec/dummyapp/config/environments/development.rb +0 -37
  125. data/spec/dummyapp/config/environments/production.rb +0 -67
  126. data/spec/dummyapp/config/environments/test.rb +0 -37
  127. data/spec/dummyapp/config/initializers/backtrace_silencers.rb +0 -7
  128. data/spec/dummyapp/config/initializers/inflections.rb +0 -15
  129. data/spec/dummyapp/config/initializers/mime_types.rb +0 -5
  130. data/spec/dummyapp/config/initializers/rollbar.rb +0 -26
  131. data/spec/dummyapp/config/initializers/secret_token.rb +0 -7
  132. data/spec/dummyapp/config/initializers/session_store.rb +0 -8
  133. data/spec/dummyapp/config/initializers/wrap_parameters.rb +0 -16
  134. data/spec/dummyapp/config/locales/devise.en.yml +0 -58
  135. data/spec/dummyapp/config/locales/en.yml +0 -5
  136. data/spec/dummyapp/config/routes.rb +0 -17
  137. data/spec/dummyapp/config/secrets.yml +0 -2
  138. data/spec/dummyapp/db/migrate/20121121184652_devise_create_users.rb +0 -46
  139. data/spec/dummyapp/db/migrate/20121121184654_add_name_to_users.rb +0 -5
  140. data/spec/dummyapp/db/migrate/20161219184410_create_books.rb +0 -10
  141. data/spec/dummyapp/db/migrate/20161219185529_add_username_to_users.rb +0 -5
  142. data/spec/dummyapp/db/schema.rb +0 -41
  143. data/spec/dummyapp/db/seeds.rb +0 -12
  144. data/spec/dummyapp/lib/assets/.gitkeep +0 -0
  145. data/spec/dummyapp/public/404.html +0 -26
  146. data/spec/dummyapp/public/422.html +0 -26
  147. data/spec/dummyapp/public/500.html +0 -25
  148. data/spec/dummyapp/public/favicon.ico +0 -0
  149. data/spec/dummyapp/script/rails +0 -6
  150. data/spec/fixtures/file1 +0 -1
  151. data/spec/fixtures/file2 +0 -1
  152. data/spec/fixtures/payloads/message.json +0 -25
  153. data/spec/fixtures/payloads/sample.trace.json +0 -275
  154. data/spec/fixtures/payloads/sample.trace_chain.json +0 -530
  155. data/spec/fixtures/plugins/dummy1.rb +0 -5
  156. data/spec/fixtures/plugins/dummy2.rb +0 -5
  157. data/spec/generators/rollbar/rollbar_generator_rails30_spec.rb +0 -31
  158. data/spec/generators/rollbar/rollbar_generator_spec.rb +0 -51
  159. data/spec/requests/home_spec.rb +0 -49
  160. data/spec/rollbar/configuration_spec.rb +0 -46
  161. data/spec/rollbar/delay/delayed_job_spec.rb +0 -22
  162. data/spec/rollbar/delay/girl_friday_spec.rb +0 -41
  163. data/spec/rollbar/delay/resque_spec.rb +0 -37
  164. data/spec/rollbar/delay/thread_spec.rb +0 -27
  165. data/spec/rollbar/encoding/encoder_spec.rb +0 -63
  166. data/spec/rollbar/item/backtrace_spec.rb +0 -26
  167. data/spec/rollbar/item/frame_spec.rb +0 -267
  168. data/spec/rollbar/item_spec.rb +0 -736
  169. data/spec/rollbar/json/oj_spec.rb +0 -18
  170. data/spec/rollbar/json_spec.rb +0 -110
  171. data/spec/rollbar/lazy_store_spec.rb +0 -99
  172. data/spec/rollbar/logger_proxy_spec.rb +0 -50
  173. data/spec/rollbar/logger_spec.rb +0 -124
  174. data/spec/rollbar/middleware/js_spec.rb +0 -421
  175. data/spec/rollbar/middleware/sinatra_spec.rb +0 -197
  176. data/spec/rollbar/notifier_spec.rb +0 -56
  177. data/spec/rollbar/plugin_spec.rb +0 -209
  178. data/spec/rollbar/plugins/active_job_spec.rb +0 -38
  179. data/spec/rollbar/plugins/delayed_job/job_data_spec.rb +0 -48
  180. data/spec/rollbar/plugins/delayed_job_spec.rb +0 -129
  181. data/spec/rollbar/plugins/rack_spec.rb +0 -152
  182. data/spec/rollbar/plugins/rails_js_spec.rb +0 -19
  183. data/spec/rollbar/plugins/rake_spec.rb +0 -34
  184. data/spec/rollbar/plugins/resque/failure_spec.rb +0 -36
  185. data/spec/rollbar/plugins/sidekiq_spec.rb +0 -171
  186. data/spec/rollbar/plugins/validations_spec.rb +0 -56
  187. data/spec/rollbar/plugins_spec.rb +0 -68
  188. data/spec/rollbar/request_data_extractor_spec.rb +0 -270
  189. data/spec/rollbar/scrubbers/params_spec.rb +0 -314
  190. data/spec/rollbar/scrubbers/url_spec.rb +0 -136
  191. data/spec/rollbar/scrubbers_spec.rb +0 -31
  192. data/spec/rollbar/sidekig/clear_scope_spec.rb +0 -19
  193. data/spec/rollbar/truncation/frames_strategy_spec.rb +0 -70
  194. data/spec/rollbar/truncation/min_body_strategy_spec.rb +0 -57
  195. data/spec/rollbar/truncation/strings_strategy_spec.rb +0 -89
  196. data/spec/rollbar/truncation_spec.rb +0 -27
  197. data/spec/rollbar/util/hash_spec.rb +0 -22
  198. data/spec/rollbar/util/ip_anonymizer_spec.rb +0 -30
  199. data/spec/rollbar/util_spec.rb +0 -80
  200. data/spec/rollbar_bc_spec.rb +0 -380
  201. data/spec/rollbar_spec.rb +0 -1667
  202. data/spec/spec_helper.rb +0 -84
  203. data/spec/support/cause_exception.rb +0 -1
  204. data/spec/support/encoding_helpers.rb +0 -8
  205. data/spec/support/encodings/iso_8859_9 +0 -1
  206. data/spec/support/fixture_helpers.rb +0 -10
  207. data/spec/support/get_ip_raising.rb +0 -7
  208. data/spec/support/helpers.rb +0 -5
  209. data/spec/support/matchers.rb +0 -23
  210. data/spec/support/notifier_helpers.rb +0 -57
  211. data/spec/support/rollbar_api.rb +0 -57
  212. data/spec/support/shared_contexts.rb +0 -12
data/spec/rollbar_spec.rb DELETED
@@ -1,1667 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'logger'
4
- require 'socket'
5
- require 'girl_friday'
6
- require 'redis'
7
- require 'active_support/core_ext/object'
8
- require 'active_support/json/encoding'
9
-
10
- require 'rollbar/item'
11
- require 'ostruct'
12
-
13
- begin
14
- require 'rollbar/delay/sidekiq'
15
- require 'rollbar/delay/sucker_punch'
16
- rescue LoadError
17
- end
18
-
19
- begin
20
- require 'sucker_punch'
21
- require 'sucker_punch/testing/inline'
22
- rescue LoadError
23
- end
24
-
25
- begin
26
- require 'rollbar/delay/shoryuken'
27
- rescue LoadError
28
- end
29
-
30
- require 'spec_helper'
31
-
32
- describe Rollbar do
33
- let(:notifier) { Rollbar.notifier }
34
-
35
- before do
36
- Rollbar.clear_notifier!
37
- configure
38
- end
39
-
40
- context 'when notifier has been used before configure it' do
41
- before do
42
- Rollbar.clear_notifier!
43
- end
44
-
45
- it 'is finally reset' do
46
- Rollbar.log_debug('Testing notifier')
47
- expect(Rollbar.error('error message')).to be_eql('disabled')
48
-
49
- reconfigure_notifier
50
-
51
- expect(Rollbar.error('error message')).not_to be_eql('disabled')
52
- end
53
- end
54
-
55
- shared_examples 'stores the root notifier' do
56
-
57
- end
58
-
59
- describe '.configure' do
60
- before { Rollbar.clear_notifier! }
61
-
62
- it 'stores the root notifier' do
63
- Rollbar.configure { |c| }
64
- expect(Rollbar.root_notifier).to be(Rollbar.notifier)
65
- end
66
- end
67
-
68
- describe '.preconfigure' do
69
- before { Rollbar.clear_notifier! }
70
-
71
- it 'stores the root notifier' do
72
- Rollbar.preconfigure { |c| }
73
- expect(Rollbar.root_notifier).to be(Rollbar.notifier)
74
- end
75
- end
76
-
77
- describe '.reconfigure' do
78
- before { Rollbar.clear_notifier! }
79
-
80
- it 'stores the root notifier' do
81
- Rollbar.reconfigure { |c| }
82
- expect(Rollbar.root_notifier).to be(Rollbar.notifier)
83
- end
84
- end
85
-
86
- describe '.unconfigure' do
87
- before { Rollbar.clear_notifier! }
88
-
89
- it 'stores the root notifier' do
90
- expect(Rollbar.root_notifier).to receive(:unconfigure)
91
-
92
- Rollbar.unconfigure
93
-
94
- expect(Rollbar.root_notifier).to be(Rollbar.notifier)
95
- end
96
- end
97
-
98
- context 'Notifier' do
99
- describe '#log' do
100
- let(:exception) do
101
- begin
102
- foo = bar
103
- rescue => e
104
- e
105
- end
106
- end
107
-
108
- let(:configuration) { Rollbar.configuration }
109
-
110
- context 'executing a Thread before Rollbar is configured' do
111
- before do
112
- Rollbar.clear_notifier!
113
-
114
- Thread.new {}
115
-
116
- Rollbar.configure do |config|
117
- config.access_token = 'my-access-token'
118
- end
119
- end
120
-
121
- it 'sets correct configuration for Rollbar.notifier' do
122
- expect(Rollbar.notifier.configuration.enabled).to be_truthy
123
- end
124
- end
125
-
126
- it 'should report a simple message' do
127
- expect(notifier).to receive(:report).with('error', 'test message', nil, nil, nil)
128
- notifier.log('error', 'test message')
129
- end
130
-
131
- it 'should report a simple message with extra data' do
132
- extra_data = {:key => 'value', :hash => {:inner_key => 'inner_value'}}
133
-
134
- expect(notifier).to receive(:report).with('error', 'test message', nil, extra_data, nil)
135
- notifier.log('error', 'test message', extra_data)
136
- end
137
-
138
- it 'should report an exception' do
139
- expect(notifier).to receive(:report).with('error', nil, exception, nil, nil)
140
- notifier.log('error', exception)
141
- end
142
-
143
- it 'should report an exception with extra data' do
144
- extra_data = {:key => 'value', :hash => {:inner_key => 'inner_value'}}
145
-
146
- expect(notifier).to receive(:report).with('error', nil, exception, extra_data, nil)
147
- notifier.log('error', exception, extra_data)
148
- end
149
-
150
- it 'should report an exception with a description' do
151
- expect(notifier).to receive(:report).with('error', 'exception description', exception, nil, nil)
152
- notifier.log('error', exception, 'exception description')
153
- end
154
-
155
- it 'should report an exception with a description and extra data' do
156
- extra_data = {:key => 'value', :hash => {:inner_key => 'inner_value'}}
157
-
158
- expect(notifier).to receive(:report).with('error', 'exception description', exception, extra_data, nil)
159
- notifier.log('error', exception, extra_data, 'exception description')
160
- end
161
-
162
- context 'an item with a context' do
163
- let(:context) { { :controller => 'ExampleController' } }
164
-
165
- context 'with a custom_data_method configured' do
166
- before do
167
- Rollbar.configure do |config|
168
- config.custom_data_method = lambda do |message, exception, context|
169
- { :result => "MyApp#" + context[:controller] }
170
- end
171
- end
172
- end
173
-
174
- it 'should have access to the context data through configuration.custom_data_method' do
175
- result = notifier.log('error', "Custom message", { :custom_data_method_context => context})
176
-
177
- result[:body][:message][:extra].should_not be_nil
178
- result[:body][:message][:extra][:result].should == "MyApp#"+context[:controller]
179
- result[:body][:message][:extra][:custom_data_method_context].should be_nil
180
- end
181
- end
182
- end
183
- end
184
-
185
- context 'with before_process handlers in configuration' do
186
- let!(:notifier) { Rollbar::Notifier.new }
187
- let(:scope) { { :bar => :foo } }
188
- let(:configuration) do
189
- config = Rollbar::Configuration.new
190
- config.access_token = test_access_token
191
- config.enabled = true
192
- config
193
- end
194
- let(:message) { 'message' }
195
- let(:exception) { Exception.new }
196
- let(:extra) { {:foo => :bar } }
197
- let(:level) { 'error' }
198
-
199
- before do
200
- notifier.configuration = configuration
201
- notifier.scope!(scope)
202
- end
203
-
204
- context 'without raise Rollbar::Ignore' do
205
- let(:handler) do
206
- proc do |options|
207
-
208
- end
209
- end
210
-
211
- before do
212
- configuration.before_process = handler
213
- end
214
-
215
- it 'calls the handler with the correct options' do
216
- options = {
217
- :level => level,
218
- :scope => Rollbar::LazyStore.new(scope),
219
- :exception => exception,
220
- :message => message,
221
- :extra => extra
222
- }
223
-
224
- expect(handler).to receive(:call).with(options)
225
- expect(notifier).to receive(:report).with(level, message, exception, extra, nil)
226
-
227
- notifier.log(level, message, exception, extra)
228
- end
229
- end
230
-
231
- context 'raising Rollbar::Ignore in the handler' do
232
- let(:handler) do
233
- proc do |options|
234
- raise Rollbar::Ignore
235
- end
236
- end
237
-
238
- before do
239
- configuration.before_process = handler
240
- end
241
-
242
- it "calls the handler with correct options and doesn't call #report" do
243
- options = {
244
- :level => level,
245
- :scope => Rollbar::LazyStore.new(scope),
246
- :exception => exception,
247
- :message => message,
248
- :extra => extra
249
- }
250
- expect(handler).to receive(:call).with(options).and_call_original
251
- expect(notifier).not_to receive(:report)
252
-
253
- result = notifier.log(level, message, exception, extra)
254
-
255
- expect(result).to be_eql('ignored')
256
- end
257
- end
258
-
259
- context 'with 2 handlers, raising Rollbar::Ignore in the first one' do
260
- let(:handler1) do
261
- proc do |options|
262
- raise Rollbar::Ignore
263
- end
264
- end
265
-
266
- let(:handler2) do
267
- proc do |options|
268
-
269
- end
270
- end
271
-
272
- before do
273
- configuration.before_process << handler1
274
- configuration.before_process << handler2
275
- end
276
-
277
- it "calls only the first handler and doesn't calls #report" do
278
- options = {
279
- :level => level,
280
- :scope => Rollbar::LazyStore.new(scope),
281
- :exception => exception,
282
- :message => message,
283
- :extra => extra
284
- }
285
-
286
- expect(handler1).to receive(:call).with(options).and_call_original
287
- expect(handler2).not_to receive(:call)
288
- expect(notifier).not_to receive(:report)
289
-
290
- result = notifier.log(level, message, exception, extra)
291
-
292
- expect(result).to be_eql('ignored')
293
- end
294
-
295
- context 'if the first handler fails' do
296
- let(:exception) { StandardError.new('foo') }
297
- let(:handler1) do
298
- proc { |options| raise exception }
299
- end
300
-
301
- it 'doesnt call the second handler and logs the error' do
302
- expect(handler2).not_to receive(:call)
303
- expect(notifier).to receive(:log_error).with("[Rollbar] Error calling the `before_process` hook: #{exception}")
304
-
305
- notifier.log(level, message, exception, extra)
306
- end
307
- end
308
- end
309
- end
310
-
311
- context 'debug/info/warning/error/critical' do
312
- let(:exception) do
313
- begin
314
- foo = bar
315
- rescue => e
316
- e
317
- end
318
- end
319
-
320
- let(:extra_data) { {:key => 'value', :hash => {:inner_key => 'inner_value'}} }
321
-
322
- it 'should report with a debug level' do
323
- expect(notifier).to receive(:report).with('debug', nil, exception, nil, nil)
324
- notifier.debug(exception)
325
-
326
- expect(notifier).to receive(:report).with('debug', 'description', exception, nil, nil)
327
- notifier.debug(exception, 'description')
328
-
329
- expect(notifier).to receive(:report).with('debug', 'description', exception, extra_data, nil)
330
- notifier.debug(exception, 'description', extra_data)
331
- end
332
-
333
- it 'should report with an info level' do
334
- expect(notifier).to receive(:report).with('info', nil, exception, nil, nil)
335
- notifier.info(exception)
336
-
337
- expect(notifier).to receive(:report).with('info', 'description', exception, nil, nil)
338
- notifier.info(exception, 'description')
339
-
340
- expect(notifier).to receive(:report).with('info', 'description', exception, extra_data, nil)
341
- notifier.info(exception, 'description', extra_data)
342
- end
343
-
344
- it 'should report with a warning level' do
345
- expect(notifier).to receive(:report).with('warning', nil, exception, nil, nil)
346
- notifier.warning(exception)
347
-
348
- expect(notifier).to receive(:report).with('warning', 'description', exception, nil, nil)
349
- notifier.warning(exception, 'description')
350
-
351
- expect(notifier).to receive(:report).with('warning', 'description', exception, extra_data, nil)
352
- notifier.warning(exception, 'description', extra_data)
353
- end
354
-
355
- it 'should report with an error level' do
356
- expect(notifier).to receive(:report).with('error', nil, exception, nil, nil)
357
- notifier.error(exception)
358
-
359
- expect(notifier).to receive(:report).with('error', 'description', exception, nil, nil)
360
- notifier.error(exception, 'description')
361
-
362
- expect(notifier).to receive(:report).with('error', 'description', exception, extra_data, nil)
363
- notifier.error(exception, 'description', extra_data)
364
- end
365
-
366
- it 'should report with a critical level' do
367
- expect(notifier).to receive(:report).with('critical', nil, exception, nil, nil)
368
- notifier.critical(exception)
369
-
370
- expect(notifier).to receive(:report).with('critical', 'description', exception, nil, nil)
371
- notifier.critical(exception, 'description')
372
-
373
- expect(notifier).to receive(:report).with('critical', 'description', exception, extra_data, nil)
374
- notifier.critical(exception, 'description', extra_data)
375
- end
376
- end
377
-
378
- context 'scope' do
379
- it 'should create a new notifier object' do
380
- notifier2 = notifier.scope
381
-
382
- notifier2.should_not eq(notifier)
383
- notifier2.should be_instance_of(Rollbar::Notifier)
384
- end
385
-
386
- it 'should create a copy of the parent notifier\'s configuration' do
387
- notifier.configure do |config|
388
- config.code_version = '123'
389
- config.payload_options = {
390
- :a => 'a',
391
- :b => {:c => 'c'}
392
- }
393
- end
394
-
395
- notifier2 = notifier.scope
396
-
397
- notifier2.configuration.code_version.should == '123'
398
- notifier2.configuration.should_not equal(notifier.configuration)
399
- notifier2.configuration.payload_options.should_not equal(notifier.configuration.payload_options)
400
- notifier2.configuration.payload_options.should == notifier.configuration.payload_options
401
- notifier2.configuration.payload_options.should == {
402
- :a => 'a',
403
- :b => {:c => 'c'}
404
- }
405
- end
406
-
407
- it 'should not modify any parent notifier configuration' do
408
- Rollbar.clear_notifier!
409
- configure
410
- Rollbar.configuration.code_version.should be_nil
411
- Rollbar.configuration.payload_options.should be_empty
412
-
413
- notifier = Rollbar.notifier.scope
414
- notifier.configure do |config|
415
- config.code_version = '123'
416
- config.payload_options = {
417
- :a => 'a',
418
- :b => {:c => 'c'}
419
- }
420
- end
421
-
422
- notifier2 = notifier.scope
423
-
424
- notifier2.configure do |config|
425
- config.payload_options[:c] = 'c'
426
- end
427
-
428
- notifier.configuration.payload_options[:c].should be_nil
429
-
430
- notifier3 = notifier2.scope({
431
- :b => {:c => 3, :d => 'd'}
432
- })
433
-
434
- notifier3.configure do |config|
435
- config.code_version = '456'
436
- end
437
-
438
- notifier.configuration.code_version.should == '123'
439
- notifier.configuration.payload_options.should == {
440
- :a => 'a',
441
- :b => {:c => 'c'}
442
- }
443
- notifier2.configuration.code_version.should == '123'
444
- notifier2.configuration.payload_options.should == {
445
- :a => 'a',
446
- :b => {:c => 'c'},
447
- :c => 'c'
448
- }
449
- notifier3.configuration.code_version.should == '456'
450
- notifier3.configuration.payload_options.should == {
451
- :a => 'a',
452
- :b => {:c => 'c'},
453
- :c => 'c'
454
- }
455
-
456
- Rollbar.configuration.code_version.should be_nil
457
- Rollbar.configuration.payload_options.should be_empty
458
- end
459
- end
460
-
461
- context 'report' do
462
- let(:logger_mock) { double("Rails.logger").as_null_object }
463
-
464
- before(:each) do
465
- configure
466
- Rollbar.configure do |config|
467
- config.logger = logger_mock
468
- end
469
- end
470
-
471
- after do
472
- configure
473
- end
474
-
475
- it 'should reject input that doesn\'t contain an exception, message or extra data' do
476
- expect(logger_mock).to receive(:error).with('[Rollbar] Tried to send a report with no message, exception or extra data.')
477
- expect(notifier).not_to receive(:schedule_payload)
478
-
479
- result = notifier.send(:report, 'info', nil, nil, nil, nil)
480
- result.should == 'error'
481
- end
482
-
483
- it 'should be ignored if the person is ignored' do
484
- person_data = {
485
- :id => 1,
486
- :username => "test",
487
- :email => "test@example.com"
488
- }
489
-
490
- notifier.configure do |config|
491
- config.ignored_person_ids += [1]
492
- config.payload_options = { :person => person_data }
493
- end
494
-
495
- expect(notifier).not_to receive(:schedule_payload)
496
-
497
- result = notifier.send(:report, 'info', 'message', nil, nil, nil)
498
- result.should == 'ignored'
499
- end
500
- end
501
- end
502
-
503
- context 'reporting' do
504
- let(:exception) do
505
- begin
506
- foo = bar
507
- rescue => e
508
- e
509
- end
510
- end
511
-
512
- let(:logger_mock) { double("Rails.logger").as_null_object }
513
- let(:user) { User.create(:email => 'email@example.com', :encrypted_password => '', :created_at => Time.now, :updated_at => Time.now) }
514
-
515
- before do
516
- Rollbar.unconfigure
517
- configure
518
-
519
- Rollbar.configure do |config|
520
- config.logger = logger_mock
521
- end
522
- end
523
-
524
- it 'should report exceptions without person or request data' do
525
- logger_mock.should_receive(:info).with('[Rollbar] Success')
526
- Rollbar.error(exception)
527
- end
528
-
529
- it 'should not report anything when disabled' do
530
- logger_mock.should_not_receive(:info).with('[Rollbar] Success')
531
-
532
- Rollbar.configure do |config|
533
- config.enabled = false
534
- end
535
-
536
- Rollbar.error(exception).should == 'disabled'
537
- end
538
-
539
- it 'should report exceptions without person or request data' do
540
- logger_mock.should_receive(:info).with('[Rollbar] Success')
541
- Rollbar.error(exception)
542
- end
543
-
544
- it 'should be enabled when freshly configured' do
545
- Rollbar.configuration.enabled.should == true
546
- end
547
-
548
- it 'should not be enabled when not configured' do
549
- Rollbar.clear_notifier!
550
-
551
- Rollbar.configuration.enabled.should be_nil
552
- Rollbar.error(exception).should == 'disabled'
553
- end
554
-
555
- it 'should stay disabled if configure is called again' do
556
- # configure once, setting enabled to false.
557
- Rollbar.configure do |config|
558
- config.enabled = false
559
- end
560
-
561
- # now configure again (perhaps to change some other values)
562
- Rollbar.configure { |_| }
563
-
564
- Rollbar.configuration.enabled.should == false
565
- Rollbar.error(exception).should == 'disabled'
566
- end
567
-
568
- context 'using configuration.use_exception_level_filters_default' do
569
- before do
570
- Rollbar.configure do |config|
571
- config.use_exception_level_filters_default = true
572
- end
573
- end
574
-
575
- context 'without use_exception_level_filters argument' do
576
- it 'sends the correct filtered level' do
577
- Rollbar.configure do |config|
578
- config.exception_level_filters = { 'NameError' => 'warning' }
579
- end
580
-
581
- Rollbar.error(exception)
582
-
583
- expect(Rollbar.last_report[:level]).to be_eql('warning')
584
- end
585
-
586
- it 'ignore ignored exception classes' do
587
- Rollbar.configure do |config|
588
- config.exception_level_filters = { 'NameError' => 'ignore' }
589
- end
590
-
591
- logger_mock.should_not_receive(:info)
592
- logger_mock.should_not_receive(:warn)
593
- logger_mock.should_not_receive(:error)
594
-
595
- Rollbar.error(exception)
596
- end
597
-
598
- it 'should not use the filters if overriden at log site' do
599
- Rollbar.configure do |config|
600
- config.exception_level_filters = { 'NameError' => 'ignore' }
601
- end
602
-
603
- Rollbar.error(exception, :use_exception_level_filters => false)
604
-
605
- expect(Rollbar.last_report[:level]).to be_eql('error')
606
- end
607
- end
608
- end
609
-
610
- context 'using :use_exception_level_filters option as true' do
611
- it 'sends the correct filtered level' do
612
- Rollbar.configure do |config|
613
- config.exception_level_filters = { 'NameError' => 'warning' }
614
- end
615
-
616
- Rollbar.error(exception, :use_exception_level_filters => true)
617
- expect(Rollbar.last_report[:level]).to be_eql('warning')
618
- end
619
-
620
- it 'ignore ignored exception classes' do
621
- Rollbar.configure do |config|
622
- config.exception_level_filters = { 'NameError' => 'ignore' }
623
- end
624
-
625
- logger_mock.should_not_receive(:info)
626
- logger_mock.should_not_receive(:warn)
627
- logger_mock.should_not_receive(:error)
628
-
629
- Rollbar.error(exception, :use_exception_level_filters => true)
630
- end
631
-
632
- context 'using :use_exception_level_filters option as false' do
633
- it 'sends the correct filtered level' do
634
- Rollbar.configure do |config|
635
- config.exception_level_filters = { 'NameError' => 'warning' }
636
- end
637
-
638
- Rollbar.error(exception, :use_exception_level_filters => false)
639
- expect(Rollbar.last_report[:level]).to be_eql('error')
640
- end
641
-
642
- it 'ignore ignored exception classes' do
643
- Rollbar.configure do |config|
644
- config.exception_level_filters = { 'NameError' => 'ignore' }
645
- end
646
-
647
- Rollbar.error(exception, :use_exception_level_filters => false)
648
-
649
- expect(Rollbar.last_report[:level]).to be_eql('error')
650
- end
651
- end
652
- end
653
-
654
- context 'using :use_exception_level_filters option as true' do
655
- it 'sends the correct filtered level' do
656
- Rollbar.configure do |config|
657
- config.exception_level_filters = { 'NameError' => 'warning' }
658
- end
659
-
660
- Rollbar.error(exception, :use_exception_level_filters => true)
661
- expect(Rollbar.last_report[:level]).to be_eql('warning')
662
- end
663
-
664
- it 'ignore ignored exception classes' do
665
- Rollbar.configure do |config|
666
- config.exception_level_filters = { 'NameError' => 'ignore' }
667
- end
668
-
669
- logger_mock.should_not_receive(:info)
670
- logger_mock.should_not_receive(:warn)
671
- logger_mock.should_not_receive(:error)
672
-
673
- Rollbar.error(exception, :use_exception_level_filters => true)
674
- end
675
- end
676
-
677
- context 'if not using :use_exception_level_filters option' do
678
- it 'sends the level defined by the used method' do
679
- Rollbar.configure do |config|
680
- config.exception_level_filters = { 'NameError' => 'warning' }
681
- end
682
-
683
- Rollbar.error(exception)
684
- expect(Rollbar.last_report[:level]).to be_eql('error')
685
- end
686
-
687
- it 'ignore ignored exception classes' do
688
- Rollbar.configure do |config|
689
- config.exception_level_filters = { 'NameError' => 'ignore' }
690
- end
691
-
692
- Rollbar.error(exception)
693
-
694
- expect(Rollbar.last_report[:level]).to be_eql('error')
695
- end
696
- end
697
-
698
- # Skip jruby 1.9+ (https://github.com/jruby/jruby/issues/2373)
699
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' && (not RUBY_VERSION =~ /^1\.9/)
700
- it "should work with an IO object as rack.errors" do
701
- logger_mock.should_receive(:info).with('[Rollbar] Success')
702
-
703
- Rollbar.error(exception, :env => { :"rack.errors" => IO.new(2, File::WRONLY) })
704
- end
705
- end
706
-
707
- it 'should ignore ignored persons' do
708
- person_data = {
709
- :id => 1,
710
- :username => "test",
711
- :email => "test@example.com"
712
- }
713
-
714
- Rollbar.configure do |config|
715
- config.payload_options = { :person => person_data }
716
- config.ignored_person_ids += [1]
717
- end
718
-
719
- logger_mock.should_not_receive(:info)
720
- logger_mock.should_not_receive(:warn)
721
- logger_mock.should_not_receive(:error)
722
-
723
- Rollbar.error(exception)
724
- end
725
-
726
- it 'should not ignore non-ignored persons' do
727
- person_data = {
728
- :id => 1,
729
- :username => "test",
730
- :email => "test@example.com"
731
- }
732
- Rollbar.configure do |config|
733
- config.payload_options = { :person => person_data }
734
- config.ignored_person_ids += [1]
735
- end
736
-
737
- Rollbar.last_report = nil
738
-
739
- Rollbar.error(exception)
740
- Rollbar.last_report.should be_nil
741
-
742
- person_data = {
743
- :id => 2,
744
- :username => "test2",
745
- :email => "test2@example.com"
746
- }
747
-
748
- new_options = {
749
- :person => person_data
750
- }
751
-
752
- Rollbar.scoped(new_options) do
753
- Rollbar.error(exception)
754
- end
755
-
756
- Rollbar.last_report.should_not be_nil
757
- end
758
-
759
- it 'should allow callables to set exception filtered level' do
760
- callable_mock = double
761
- saved_filters = Rollbar.configuration.exception_level_filters
762
-
763
- Rollbar.configure do |config|
764
- config.exception_level_filters = { 'NameError' => callable_mock }
765
- end
766
-
767
- callable_mock.should_receive(:call).with(exception).at_least(:once).and_return("info")
768
- logger_mock.should_receive(:info)
769
- logger_mock.should_not_receive(:warn)
770
- logger_mock.should_not_receive(:error)
771
-
772
- Rollbar.error(exception, :use_exception_level_filters => true)
773
- end
774
-
775
- it 'should not report exceptions when silenced' do
776
- expect_any_instance_of(Rollbar::Notifier).to_not receive(:schedule_payload)
777
-
778
- begin
779
- test_var = 1
780
- Rollbar.silenced do
781
- test_var = 2
782
- raise
783
- end
784
- rescue => e
785
- Rollbar.error(e)
786
- end
787
-
788
- test_var.should == 2
789
- end
790
-
791
- it 'should report exception objects with no backtrace' do
792
- payload = nil
793
-
794
- notifier.stub(:schedule_item) do |*args|
795
- payload = args[0]
796
- end
797
-
798
- Rollbar.error(StandardError.new("oops"))
799
-
800
- payload["data"][:body][:trace][:frames].should == []
801
- payload["data"][:body][:trace][:exception][:class].should == "StandardError"
802
- payload["data"][:body][:trace][:exception][:message].should == "oops"
803
- end
804
-
805
- it 'gets the backtrace from the caller' do
806
- Rollbar.configure do |config|
807
- config.populate_empty_backtraces = true
808
- end
809
-
810
- exception = Exception.new
811
-
812
- Rollbar.error(exception)
813
-
814
- gem_dir = Gem::Specification.find_by_name('rollbar').gem_dir
815
- gem_lib_dir = gem_dir + '/lib'
816
- last_report = Rollbar.last_report
817
-
818
- filepaths = last_report[:body][:trace][:frames].map {|frame| frame[:filename] }.reverse
819
-
820
- expect(filepaths[0]).not_to include(gem_lib_dir)
821
- expect(filepaths.any? {|filepath| filepath.include?(gem_dir) }).to eq true
822
- end
823
-
824
- it 'should return the exception data with a uuid, on platforms with SecureRandom' do
825
- if defined?(SecureRandom) and SecureRandom.respond_to?(:uuid)
826
- exception_data = Rollbar.error(StandardError.new("oops"))
827
- exception_data[:uuid].should_not be_nil
828
- end
829
- end
830
-
831
- it 'should report exception objects with nonstandard backtraces' do
832
- payload = nil
833
-
834
- notifier.stub(:schedule_item) do |*args|
835
- payload = args[0]
836
- end
837
-
838
- class CustomException < StandardError
839
- def backtrace
840
- ["custom backtrace line"]
841
- end
842
- end
843
-
844
- exception = CustomException.new("oops")
845
-
846
- notifier.error(exception)
847
-
848
- payload["data"][:body][:trace][:frames][0][:method].should == "custom backtrace line"
849
- end
850
-
851
- it 'should report exceptions with a custom level' do
852
- payload = nil
853
-
854
- notifier.stub(:schedule_item) do |*args|
855
- payload = args[0]
856
- end
857
-
858
- Rollbar.error(exception)
859
-
860
- payload['data'][:level].should == 'error'
861
-
862
- Rollbar.log('debug', exception)
863
-
864
- payload['data'][:level].should == 'debug'
865
- end
866
-
867
- context 'with invalid utf8 encoding' do
868
- let(:extra) do
869
- { :extra => force_to_ascii("bad value 1\255") }
870
- end
871
-
872
- it 'removes te invalid characteres' do
873
- Rollbar.info('removing invalid chars', extra)
874
-
875
- extra_value = Rollbar.last_report[:body][:message][:extra][:extra]
876
- expect(extra_value).to be_eql('bad value 1')
877
- end
878
- end
879
- end
880
-
881
- # Backwards
882
- context 'report_message' do
883
- before(:each) do
884
- configure
885
- Rollbar.configure do |config|
886
- config.logger = logger_mock
887
- end
888
- end
889
-
890
- let(:logger_mock) { double("Rails.logger").as_null_object }
891
- let(:user) { User.create(:email => 'email@example.com', :encrypted_password => '', :created_at => Time.now, :updated_at => Time.now) }
892
-
893
- it 'should report simple messages' do
894
- logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
895
- logger_mock.should_receive(:info).with('[Rollbar] Success')
896
- Rollbar.error('Test message')
897
- end
898
-
899
- it 'should not report anything when disabled' do
900
- logger_mock.should_not_receive(:info).with('[Rollbar] Success')
901
- Rollbar.configure do |config|
902
- config.enabled = false
903
- end
904
-
905
- Rollbar.error('Test message that should be ignored')
906
-
907
- Rollbar.configure do |config|
908
- config.enabled = true
909
- end
910
- end
911
-
912
- it 'should report messages with extra data' do
913
- logger_mock.should_receive(:info).with('[Rollbar] Success')
914
- Rollbar.debug('Test message with extra data', 'debug', :foo => "bar",
915
- :hash => { :a => 123, :b => "xyz" })
916
- end
917
-
918
- # END Backwards
919
-
920
- it 'should not crash with circular extra_data' do
921
- a = { :foo => "bar" }
922
- b = { :a => a }
923
- c = { :b => b }
924
- a[:c] = c
925
-
926
- logger_mock.should_receive(:error).with(/\[Rollbar\] Reporting internal error encountered while sending data to Rollbar./)
927
-
928
- Rollbar.error("Test message with circular extra data", a)
929
- end
930
-
931
- it 'should be able to report form validation errors when they are present' do
932
- logger_mock.should_receive(:info).with('[Rollbar] Success')
933
- user.errors.add(:example, "error")
934
- user.report_validation_errors_to_rollbar
935
- end
936
-
937
- it 'should not report form validation errors when they are not present' do
938
- logger_mock.should_not_receive(:info).with('[Rollbar] Success')
939
- user.errors.clear
940
- user.report_validation_errors_to_rollbar
941
- end
942
-
943
- it 'should report messages with extra data' do
944
- logger_mock.should_receive(:info).with('[Rollbar] Success')
945
- Rollbar.info("Test message with extra data", :foo => "bar",
946
- :hash => { :a => 123, :b => "xyz" })
947
- end
948
-
949
- it 'should report messages with request, person data and extra data' do
950
- logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
951
- logger_mock.should_receive(:info).with('[Rollbar] Success')
952
-
953
- request_data = {
954
- :params => {:foo => 'bar'}
955
- }
956
-
957
- person_data = {
958
- :id => 123,
959
- :username => 'username'
960
- }
961
-
962
- extra_data = {
963
- :extra_foo => 'extra_bar'
964
- }
965
-
966
- Rollbar.configure do |config|
967
- config.payload_options = {
968
- :request => request_data,
969
- :person => person_data
970
- }
971
- end
972
-
973
- Rollbar.info("Test message", extra_data)
974
-
975
- Rollbar.last_report[:request].should == request_data
976
- Rollbar.last_report[:person].should == person_data
977
- Rollbar.last_report[:body][:message][:extra][:extra_foo].should == 'extra_bar'
978
- end
979
- end
980
-
981
- context 'payload_destination' do
982
- before(:each) do
983
- configure
984
- Rollbar.configure do |config|
985
- config.logger = logger_mock
986
- config.filepath = 'test.rollbar'
987
- end
988
- end
989
-
990
- after do
991
- configure
992
- end
993
-
994
- let(:exception) do
995
- begin
996
- foo = bar
997
- rescue => e
998
- e
999
- end
1000
- end
1001
-
1002
- let(:logger_mock) { double("Rails.logger").as_null_object }
1003
-
1004
- it 'should send the payload over the network by default' do
1005
- logger_mock.should_not_receive(:info).with('[Rollbar] Writing payload to file')
1006
- logger_mock.should_receive(:info).with('[Rollbar] Sending item').once
1007
- logger_mock.should_receive(:info).with('[Rollbar] Success').once
1008
- Rollbar.error(exception)
1009
- end
1010
-
1011
- it 'should save the payload to a file if set' do
1012
- logger_mock.should_not_receive(:info).with('[Rollbar] Sending item')
1013
- logger_mock.should_receive(:info).with('[Rollbar] Writing item to file').once
1014
- logger_mock.should_receive(:info).with('[Rollbar] Success').once
1015
-
1016
- filepath = ''
1017
-
1018
- Rollbar.configure do |config|
1019
- config.write_to_file = true
1020
- filepath = config.filepath
1021
- end
1022
-
1023
- Rollbar.error(exception)
1024
-
1025
- File.exist?(filepath).should == true
1026
- File.read(filepath).should include test_access_token
1027
- File.delete(filepath)
1028
-
1029
- Rollbar.configure do |config|
1030
- config.write_to_file = false
1031
- end
1032
- end
1033
- end
1034
-
1035
- context 'using a proxy server' do
1036
- before do
1037
- allow_any_instance_of(Net::HTTP).to receive(:request).and_return(OpenStruct.new(:code => 200, :body => "Success"))
1038
- @env_vars = clear_proxy_env_vars
1039
- end
1040
-
1041
- after do
1042
- restore_proxy_env_vars(@env_vars)
1043
- end
1044
-
1045
- context 'via environment variables' do
1046
- it 'honors proxy settings in the environment' do
1047
- ENV['http_proxy'] = 'http://user:pass@example.com:80'
1048
- ENV['https_proxy'] = 'http://user:pass@example.com:80'
1049
-
1050
- uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
1051
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, 'example.com', 80, 'user', 'pass').and_call_original
1052
- Rollbar.info("proxy this")
1053
- end
1054
-
1055
- it 'does not use a proxy if no proxy settings in environemnt' do
1056
- uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
1057
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, nil, nil, nil, nil).and_call_original
1058
- Rollbar.info("proxy this")
1059
- end
1060
- end
1061
-
1062
- context 'set in configuration file' do
1063
- before do
1064
- Rollbar.configure do |config|
1065
- config.proxy = {
1066
- :host => 'http://config.com',
1067
- :port => 8080,
1068
- :user => 'foo',
1069
- :password => 'bar'
1070
- }
1071
- end
1072
- end
1073
-
1074
- it 'honors proxy settings in the config file' do
1075
- uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
1076
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, 'config.com', 8080, 'foo', 'bar').and_call_original
1077
- Rollbar.info("proxy this")
1078
- end
1079
-
1080
- it 'gives the configuration settings precedence over environment' do
1081
- ENV['http_proxy'] = 'http://user:pass@example.com:80'
1082
- ENV['https_proxy'] = 'http://user:pass@example.com:80'
1083
-
1084
- uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
1085
- expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, 'config.com', 8080, 'foo', 'bar').and_call_original
1086
- Rollbar.info("proxy this")
1087
- end
1088
- end
1089
- end
1090
-
1091
- context 'asynchronous_handling' do
1092
- before do
1093
- Rollbar.clear_notifier!
1094
- configure
1095
- Rollbar.configure do |config|
1096
- config.logger = logger_mock
1097
- end
1098
- end
1099
-
1100
- after do
1101
- configure
1102
- end
1103
-
1104
- let(:exception) do
1105
- begin
1106
- foo = bar
1107
- rescue => e
1108
- e
1109
- end
1110
- end
1111
-
1112
- let(:logger_mock) { double("Rails.logger").as_null_object }
1113
-
1114
- it 'should send the payload using the default asynchronous handler girl_friday' do
1115
- logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
1116
- logger_mock.should_receive(:info).with('[Rollbar] Sending item')
1117
- logger_mock.should_receive(:info).with('[Rollbar] Success')
1118
-
1119
- Rollbar.configure do |config|
1120
- config.use_async = true
1121
- GirlFriday::WorkQueue.immediate!
1122
- end
1123
-
1124
- Rollbar.error(exception)
1125
-
1126
- Rollbar.configure do |config|
1127
- config.use_async = false
1128
- GirlFriday::WorkQueue.queue!
1129
- end
1130
- end
1131
-
1132
- it 'should send the payload using a user-supplied asynchronous handler' do
1133
- logger_mock.should_receive(:info).with('Custom async handler called')
1134
- logger_mock.should_receive(:info).with('[Rollbar] Sending item')
1135
- logger_mock.should_receive(:info).with('[Rollbar] Success')
1136
-
1137
- Rollbar.configure do |config|
1138
- config.use_async = true
1139
- config.async_handler = Proc.new { |payload|
1140
- logger_mock.info 'Custom async handler called'
1141
- Rollbar.process_from_async_handler(payload)
1142
- }
1143
- end
1144
-
1145
- Rollbar.error(exception)
1146
- end
1147
-
1148
- # We should be able to send String payloads, generated
1149
- # by a previous version of the gem. This can happend just
1150
- # after a deploy with an gem upgrade.
1151
- context 'with a payload generated as String' do
1152
- let(:async_handler) do
1153
- proc do |payload|
1154
- # simulate previous gem version
1155
- string_payload = Rollbar::JSON.dump(payload)
1156
-
1157
- Rollbar.process_from_async_handler(string_payload)
1158
- end
1159
- end
1160
-
1161
- before do
1162
- Rollbar.configuration.stub(:use_async).and_return(true)
1163
- Rollbar.configuration.stub(:async_handler).and_return(async_handler)
1164
- end
1165
-
1166
- it 'sends a payload generated as String, not as a Hash' do
1167
- logger_mock.should_receive(:info).with('[Rollbar] Success')
1168
-
1169
- Rollbar.error(exception)
1170
- end
1171
-
1172
- context 'with async failover handlers' do
1173
- before do
1174
- Rollbar.reconfigure do |config|
1175
- config.use_async = true
1176
- config.async_handler = async_handler
1177
- config.failover_handlers = handlers
1178
- config.logger = logger_mock
1179
- end
1180
- end
1181
-
1182
- let(:exception) { StandardError.new('the error') }
1183
-
1184
- context 'if the async handler doesnt fail' do
1185
- let(:async_handler) { proc { |_| 'success' } }
1186
- let(:handler) { proc { |_| 'success' } }
1187
- let(:handlers) { [handler] }
1188
-
1189
- it 'doesnt call any failover handler' do
1190
- expect(handler).not_to receive(:call)
1191
-
1192
- Rollbar.error(exception)
1193
- end
1194
- end
1195
-
1196
- context 'if the async handler fails' do
1197
- let(:async_handler) { proc { |_| fail 'this handler will crash' } }
1198
-
1199
- context 'if any failover handlers is configured' do
1200
- let(:handlers) { [] }
1201
- let(:log_message) do
1202
- '[Rollbar] Async handler failed, and there are no failover handlers configured. See the docs for "failover_handlers"'
1203
- end
1204
-
1205
- it 'logs the error but doesnt try to report an internal error' do
1206
- expect(logger_mock).to receive(:error).with(log_message)
1207
-
1208
- Rollbar.error(exception)
1209
- end
1210
- end
1211
-
1212
- context 'if the first failover handler success' do
1213
- let(:handler) { proc { |_| 'success' } }
1214
- let(:handlers) { [handler] }
1215
-
1216
- it 'calls the failover handler and doesnt report internal error' do
1217
- expect(Rollbar).not_to receive(:report_internal_error)
1218
- expect(handler).to receive(:call)
1219
-
1220
- Rollbar.error(exception)
1221
- end
1222
- end
1223
-
1224
- context 'with two handlers, the first failing' do
1225
- let(:handler1) { proc { |_| fail 'this handler fails' } }
1226
- let(:handler2) { proc { |_| 'success' } }
1227
- let(:handlers) { [handler1, handler2] }
1228
-
1229
- it 'calls the second handler and doesnt report internal error' do
1230
- expect(handler2).to receive(:call)
1231
-
1232
- Rollbar.error(exception)
1233
- end
1234
- end
1235
-
1236
- context 'with two handlers, both failing' do
1237
- let(:handler1) { proc { |_| fail 'this handler fails' } }
1238
- let(:handler2) { proc { |_| fail 'this will also fail' } }
1239
- let(:handlers) { [handler1, handler2] }
1240
-
1241
- it 'reports internal error' do
1242
- expect(logger_mock).to receive(:error)
1243
-
1244
- Rollbar.error(exception)
1245
- end
1246
- end
1247
- end
1248
- end
1249
- end
1250
-
1251
- describe "#use_sucker_punch", :if => defined?(SuckerPunch) do
1252
- it "should send the payload to sucker_punch delayer" do
1253
- logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
1254
- expect(Rollbar::Delay::SuckerPunch).to receive(:call)
1255
-
1256
- Rollbar.configure(&:use_sucker_punch)
1257
- Rollbar.error(exception)
1258
- end
1259
- end
1260
-
1261
- describe "#use_shoryuken", :if => defined?(Shoryuken) do
1262
- it "should send the payload to shoryuken delayer" do
1263
- logger_mock.should_receive(:info).with('[Rollbar] Scheduling item')
1264
- expect(Rollbar::Delay::Shoryuken).to receive(:call)
1265
-
1266
- Rollbar.configure(&:use_shoryuken)
1267
- Rollbar.error(exception)
1268
- end
1269
- end
1270
-
1271
- describe "#use_sidekiq", :if => defined?(Sidekiq) do
1272
- it "should instanciate sidekiq delayer with custom values" do
1273
- Rollbar::Delay::Sidekiq.should_receive(:new).with('queue' => 'test_queue')
1274
- config = Rollbar::Configuration.new
1275
- config.use_sidekiq 'queue' => 'test_queue'
1276
- end
1277
-
1278
- it "should send the payload to sidekiq delayer" do
1279
- handler = double('sidekiq_handler_mock')
1280
- handler.should_receive(:call)
1281
-
1282
- Rollbar.configure do |config|
1283
- config.use_sidekiq
1284
- config.async_handler = handler
1285
- end
1286
-
1287
- Rollbar.error(exception)
1288
- end
1289
- end
1290
- end
1291
-
1292
- context 'logger' do
1293
- before(:each) do
1294
- reset_configuration
1295
- end
1296
-
1297
- it 'should have use the Rails logger when configured to do so' do
1298
- configure
1299
- expect(Rollbar.send(:logger)).to be_kind_of(Rollbar::LoggerProxy)
1300
- expect(Rollbar.send(:logger).object).to eq ::Rails.logger
1301
- end
1302
-
1303
- it 'should use the default_logger when no logger is set' do
1304
- logger = Logger.new(STDERR)
1305
-
1306
- Rollbar.configure do |config|
1307
- config.default_logger = lambda { logger }
1308
- end
1309
-
1310
- Rollbar.send(:logger).object.should == logger
1311
- end
1312
-
1313
- it 'should have a default default_logger' do
1314
- Rollbar.send(:logger).should_not be_nil
1315
- end
1316
-
1317
- after do
1318
- reset_configuration
1319
- end
1320
- end
1321
-
1322
- context "project_gems" do
1323
- it "should include gem paths for specified project gems in the payload" do
1324
- gems = ['rack', 'rspec-rails']
1325
- gem_paths = []
1326
-
1327
- Rollbar.configure do |config|
1328
- config.project_gems = gems
1329
- end
1330
-
1331
- gem_paths = gems.map do |gem|
1332
- gem_spec = Gem::Specification.find_all_by_name(gem)[0]
1333
- gem_spec.gem_dir if gem_spec
1334
- end.compact
1335
-
1336
- data = notifier.send(:build_item, 'info', 'test', nil, {}, nil)['data']
1337
- data[:project_package_paths].kind_of?(Array).should == true
1338
- data[:project_package_paths].length.should == gem_paths.length
1339
-
1340
- data[:project_package_paths].each_with_index{|path, index|
1341
- path.should == gem_paths[index]
1342
- }
1343
- end
1344
-
1345
- it "should handle regex gem patterns" do
1346
- gems = ["rack", /rspec/, /roll/]
1347
- gem_paths = []
1348
-
1349
- Rollbar.configure do |config|
1350
- config.project_gems = gems
1351
- end
1352
-
1353
- gem_paths = gems.map{|gem| Gem::Specification.find_all_by_name(gem).map(&:gem_dir) }.flatten.compact.uniq
1354
- gem_paths.length.should > 1
1355
-
1356
- gem_paths.any?{|path| path.include? 'rollbar-gem'}.should == true
1357
- gem_paths.any?{|path| path.include? 'rspec-rails'}.should == true
1358
-
1359
- data = notifier.send(:build_item, 'info', 'test', nil, {}, nil)['data']
1360
- data[:project_package_paths].kind_of?(Array).should == true
1361
- data[:project_package_paths].length.should == gem_paths.length
1362
- (data[:project_package_paths] - gem_paths).length.should == 0
1363
- end
1364
-
1365
- it "should not break on non-existent gems" do
1366
- gems = ["this_gem_does_not_exist", "rack"]
1367
-
1368
- Rollbar.configure do |config|
1369
- config.project_gems = gems
1370
- end
1371
-
1372
- data = notifier.send(:build_item, 'info', 'test', nil, {}, nil)['data']
1373
- data[:project_package_paths].kind_of?(Array).should == true
1374
- data[:project_package_paths].length.should == 1
1375
- end
1376
- end
1377
-
1378
- context 'report_internal_error', :reconfigure_notifier => true do
1379
- it "should not crash when given an exception object" do
1380
- begin
1381
- 1 / 0
1382
- rescue => e
1383
- notifier.send(:report_internal_error, e)
1384
- end
1385
- end
1386
- end
1387
-
1388
- context "send_failsafe" do
1389
- let(:exception) { StandardError.new }
1390
-
1391
- it "doesn't crash when given a message and exception" do
1392
- sent_payload = notifier.send(:send_failsafe, "test failsafe", exception)
1393
-
1394
- expected_message = 'Failsafe from rollbar-gem. StandardError: test failsafe'
1395
- expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_message)
1396
- end
1397
-
1398
- it "doesn't crash when given all nils" do
1399
- notifier.send(:send_failsafe, nil, nil)
1400
- end
1401
-
1402
- context 'with a non default exception message' do
1403
- let(:exception) { StandardError.new 'Something is wrong' }
1404
-
1405
- it 'adds it to exception info' do
1406
- sent_payload = notifier.send(:send_failsafe, "test failsafe", exception)
1407
-
1408
- expected_message = 'Failsafe from rollbar-gem. StandardError: "Something is wrong": test failsafe'
1409
- expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_message)
1410
- end
1411
- end
1412
-
1413
- context 'without exception object' do
1414
- it 'just sends the given message' do
1415
- sent_payload = notifier.send(:send_failsafe, "test failsafe", nil)
1416
-
1417
- expected_message = 'Failsafe from rollbar-gem. test failsafe'
1418
- expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_message)
1419
- end
1420
- end
1421
-
1422
- context 'if the exception has a backtrace' do
1423
- let(:backtrace) { ['func3', 'func2', 'func1'] }
1424
- let(:failsafe_reason) { 'StandardError in func3: test failsafe' }
1425
- let(:expected_body) { "Failsafe from rollbar-gem. #{failsafe_reason}" }
1426
- let(:expected_log_message) do
1427
- "[Rollbar] Sending failsafe response due to #{failsafe_reason}"
1428
- end
1429
-
1430
- before { exception.set_backtrace(backtrace) }
1431
-
1432
- it 'adds the nearest frame to the message' do
1433
- expect(notifier).to receive(:log_error).with(expected_log_message)
1434
-
1435
- sent_payload = notifier.send(:send_failsafe, "test failsafe", exception)
1436
-
1437
- expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_body)
1438
- end
1439
- end
1440
-
1441
- context 'with uuid and host' do
1442
- let(:host) { 'the-host' }
1443
- let(:uuid) { 'the-uuid' }
1444
- it 'sets the uuid and host in correct keys' do
1445
- sent_payload = notifier.send(:send_failsafe, 'testing uuid and host',
1446
- exception, uuid, host)
1447
-
1448
- expect(sent_payload['data'][:custom][:orig_uuid]).to be_eql('the-uuid')
1449
- expect(sent_payload['data'][:custom][:orig_host]).to be_eql('the-host')
1450
- end
1451
- end
1452
- end
1453
-
1454
- context 'when reporting internal error with nil context' do
1455
- let(:context_proc) { proc {} }
1456
- let(:scoped_notifier) { notifier.scope(:context => context_proc) }
1457
- let(:exception) { Exception.new }
1458
- let(:logger_mock) { double("Rails.logger").as_null_object }
1459
-
1460
- it 'reports successfully' do
1461
- configure
1462
-
1463
- Rollbar.configure do |config|
1464
- config.logger = logger_mock
1465
- end
1466
-
1467
- logger_mock.should_receive(:info).with('[Rollbar] Sending item').once
1468
- logger_mock.should_receive(:info).with('[Rollbar] Success').once
1469
- scoped_notifier.send(:report_internal_error, exception)
1470
- end
1471
- end
1472
-
1473
- context "request_data_extractor" do
1474
- before(:each) do
1475
- class DummyClass
1476
- end
1477
- @dummy_class = DummyClass.new
1478
- @dummy_class.extend(Rollbar::RequestDataExtractor)
1479
- end
1480
-
1481
- context "rollbar_headers" do
1482
- it "should not include cookies" do
1483
- env = {"HTTP_USER_AGENT" => "test", "HTTP_COOKIE" => "cookie"}
1484
- headers = @dummy_class.send(:rollbar_headers, env)
1485
- headers.should have_key "User-Agent"
1486
- headers.should_not have_key "Cookie"
1487
- end
1488
- end
1489
- end
1490
-
1491
- describe '.scoped' do
1492
- let(:scope_options) do
1493
- { :foo => 'bar' }
1494
- end
1495
-
1496
- it 'changes data in scope_object inside the block' do
1497
- Rollbar.clear_notifier!
1498
- configure
1499
-
1500
- current_notifier_id = Rollbar.notifier.object_id
1501
-
1502
- Rollbar.scoped(scope_options) do
1503
- scope_object = Rollbar.notifier.scope_object
1504
-
1505
- expect(Rollbar.notifier.object_id).not_to be_eql(current_notifier_id)
1506
- expect(scope_object).to be_eql(scope_options)
1507
- end
1508
-
1509
- expect(Rollbar.notifier.object_id).to be_eql(current_notifier_id)
1510
- end
1511
-
1512
- context 'if the block fails' do
1513
- let(:crashing_block) { proc { fail } }
1514
-
1515
- it 'restores the old notifier' do
1516
- notifier = Rollbar.notifier
1517
-
1518
- expect { Rollbar.scoped(&crashing_block) }.to raise_error
1519
- expect(notifier).to be_eql(Rollbar.notifier)
1520
- end
1521
- end
1522
-
1523
- context 'if the block creates a new thread' do
1524
- let(:block) do
1525
- proc do
1526
- Thread.new do
1527
- scope = Rollbar.notifier.scope_object
1528
- Thread.main[:inner_scope] = scope
1529
- end.join
1530
- end
1531
- end
1532
-
1533
- let(:scope) do
1534
- { :foo => 'bar' }
1535
- end
1536
-
1537
- it 'maintains the parent thread notifier scope' do
1538
- Rollbar.scoped(scope, &block)
1539
-
1540
- expect(Thread.main[:inner_scope]).to be_eql(scope)
1541
- end
1542
- end
1543
- end
1544
-
1545
- describe '.scope!' do
1546
- let(:new_scope) do
1547
- { :person => { :id => 1 } }
1548
- end
1549
-
1550
- before { reconfigure_notifier }
1551
-
1552
- it 'adds the new scope to the payload options' do
1553
- scope_object = Rollbar.notifier.scope_object
1554
- Rollbar.scope!(new_scope)
1555
-
1556
- expect(scope_object).to be_eql(new_scope)
1557
- end
1558
- end
1559
-
1560
- describe '.clear_notifier' do
1561
- before { Rollbar.notifier }
1562
-
1563
- it 'resets the notifier' do
1564
- Rollbar.clear_notifier!
1565
- expect(Rollbar.instance_variable_get('@notifier')).to be_nil
1566
- expect(Rollbar.instance_variable_get('@root_notifier')).to be_nil
1567
- end
1568
- end
1569
-
1570
- describe '.process_item' do
1571
- context 'if there is an exception sending the payload' do
1572
- let(:exception) { StandardError.new('error message') }
1573
- let(:payload) { Rollbar::Item.build_with({ :foo => :bar }) }
1574
-
1575
- it 'logs the error and the payload' do
1576
- allow(Rollbar.notifier).to receive(:send_item).and_raise(exception)
1577
- expect(Rollbar.notifier).to receive(:log_error)
1578
-
1579
- expect { Rollbar.notifier.process_item(payload) }.to raise_error(exception)
1580
- end
1581
- end
1582
- end
1583
-
1584
- describe '.process_from_async_handler' do
1585
- context 'with errors' do
1586
- let(:exception) { StandardError.new('the error') }
1587
-
1588
- it 'raises anything and sends internal error' do
1589
- allow(Rollbar.notifier).to receive(:process_item).and_raise(exception)
1590
- expect(Rollbar.notifier).to receive(:report_internal_error).with(exception)
1591
-
1592
- expect do
1593
- Rollbar.notifier.process_from_async_handler({})
1594
- end.to raise_error(exception)
1595
-
1596
- rollbar_do_not_report = exception.instance_variable_get(:@_rollbar_do_not_report)
1597
- expect(rollbar_do_not_report).to be_eql(true)
1598
- end
1599
- end
1600
- end
1601
-
1602
- describe '.preconfigure'do
1603
- before do
1604
- Rollbar.clear_notifier!
1605
- end
1606
-
1607
- it 'resets the notifier' do
1608
- Rollbar.configure do |config|
1609
- config.access_token = 'foo'
1610
- end
1611
-
1612
- Thread.new {}
1613
-
1614
- Rollbar.preconfigure do |config|
1615
- config.root = 'bar'
1616
- end
1617
-
1618
- notifier_config = Rollbar.notifier.configuration
1619
- expect(notifier_config.root).to be_eql('bar')
1620
- end
1621
- end
1622
-
1623
- context 'having timeout issues (for ruby > 1.9.3)' do
1624
- before do
1625
- skip if Rollbar::LanguageSupport.ruby_18? || Rollbar::LanguageSupport.ruby_19?
1626
- end
1627
-
1628
- let(:exception_class) do
1629
- Rollbar::LanguageSupport.timeout_exceptions.first
1630
- end
1631
- let(:net_exception) do
1632
- exception_class.new
1633
- end
1634
-
1635
- before do
1636
- allow_any_instance_of(Net::HTTP).to receive(:request).and_raise(net_exception)
1637
- end
1638
-
1639
- it 'retries the request' do
1640
- expect_any_instance_of(Net::HTTP).to receive(:request).exactly(3)
1641
- expect(Rollbar.notifier).to receive(:report_internal_error).with(net_exception)
1642
-
1643
- Rollbar.info('foo')
1644
- end
1645
- end
1646
-
1647
- describe '.with_config' do
1648
- let(:new_config) do
1649
- { 'environment' => 'foo' }
1650
- end
1651
-
1652
- it 'uses the new config and restores the old one' do
1653
- config1 = described_class.configuration
1654
-
1655
- subject.with_config(:environment => 'bar') do
1656
- expect(described_class.configuration).not_to be(config1)
1657
- end
1658
-
1659
- expect(described_class.configuration).to be(config1)
1660
- end
1661
- end
1662
-
1663
- # configure with some basic params
1664
- def configure
1665
- reconfigure_notifier
1666
- end
1667
- end