appsignal 2.1.0.alpha.3 → 2.1.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +43 -0
- data/.rubocop_todo.yml +289 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/appsignal.gemspec +1 -0
- data/bin/appsignal +2 -2
- data/ext/agent.yml +11 -11
- data/ext/extconf.rb +33 -33
- data/gemfiles/rails-4.2.gemfile +4 -0
- data/gemfiles/resque.gemfile +4 -0
- data/lib/appsignal.rb +58 -54
- data/lib/appsignal/auth_check.rb +15 -16
- data/lib/appsignal/capistrano.rb +4 -4
- data/lib/appsignal/cli.rb +28 -28
- data/lib/appsignal/cli/diagnose.rb +11 -11
- data/lib/appsignal/cli/helpers.rb +1 -1
- data/lib/appsignal/cli/install.rb +38 -38
- data/lib/appsignal/cli/notify_of_deploy.rb +1 -1
- data/lib/appsignal/config.rb +73 -71
- data/lib/appsignal/event_formatter.rb +8 -8
- data/lib/appsignal/event_formatter/action_view/render_formatter.rb +4 -4
- data/lib/appsignal/event_formatter/active_record/instantiation_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/elastic_search/search_formatter.rb +9 -7
- data/lib/appsignal/event_formatter/faraday/request_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb +6 -6
- data/lib/appsignal/event_formatter/moped/query_formatter.rb +56 -43
- data/lib/appsignal/extension.rb +5 -5
- data/lib/appsignal/hooks.rb +28 -26
- data/lib/appsignal/hooks/active_support_notifications.rb +2 -2
- data/lib/appsignal/hooks/celluloid.rb +1 -1
- data/lib/appsignal/hooks/data_mapper.rb +2 -2
- data/lib/appsignal/hooks/delayed_job.rb +1 -1
- data/lib/appsignal/hooks/mongo_ruby_driver.rb +1 -1
- data/lib/appsignal/hooks/net_http.rb +4 -4
- data/lib/appsignal/hooks/passenger.rb +2 -2
- data/lib/appsignal/hooks/puma.rb +4 -4
- data/lib/appsignal/hooks/rake.rb +1 -1
- data/lib/appsignal/hooks/redis.rb +1 -1
- data/lib/appsignal/hooks/sequel.rb +2 -2
- data/lib/appsignal/hooks/shoryuken.rb +8 -8
- data/lib/appsignal/hooks/sidekiq.rb +16 -15
- data/lib/appsignal/hooks/unicorn.rb +1 -1
- data/lib/appsignal/hooks/webmachine.rb +1 -1
- data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +6 -6
- data/lib/appsignal/integrations/data_mapper.rb +2 -3
- data/lib/appsignal/integrations/delayed_job_plugin.rb +5 -5
- data/lib/appsignal/integrations/mongo_ruby_driver.rb +6 -6
- data/lib/appsignal/integrations/padrino.rb +8 -8
- data/lib/appsignal/integrations/railtie.rb +5 -5
- data/lib/appsignal/integrations/resque.rb +4 -5
- data/lib/appsignal/integrations/resque_active_job.rb +3 -6
- data/lib/appsignal/integrations/sinatra.rb +2 -2
- data/lib/appsignal/integrations/webmachine.rb +2 -3
- data/lib/appsignal/js_exception_transaction.rb +10 -10
- data/lib/appsignal/marker.rb +3 -3
- data/lib/appsignal/rack/generic_instrumentation.rb +10 -9
- data/lib/appsignal/rack/js_exception_catcher.rb +7 -6
- data/lib/appsignal/rack/rails_instrumentation.rb +9 -8
- data/lib/appsignal/rack/sinatra_instrumentation.rb +19 -17
- data/lib/appsignal/rack/streaming_listener.rb +9 -8
- data/lib/appsignal/system.rb +19 -17
- data/lib/appsignal/transaction.rb +97 -40
- data/lib/appsignal/transmitter.rb +23 -30
- data/lib/appsignal/utils.rb +3 -3
- data/lib/appsignal/utils/params_sanitizer.rb +1 -1
- data/lib/appsignal/utils/query_params_sanitizer.rb +1 -1
- data/lib/appsignal/version.rb +2 -2
- data/spec/.rubocop.yml +4 -0
- data/spec/lib/appsignal/auth_check_spec.rb +7 -7
- data/spec/lib/appsignal/capistrano2_spec.rb +41 -41
- data/spec/lib/appsignal/capistrano3_spec.rb +43 -44
- data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +9 -11
- data/spec/lib/appsignal/cli_spec.rb +9 -9
- data/spec/lib/appsignal/config_spec.rb +88 -86
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +9 -9
- data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +12 -12
- data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +23 -23
- data/spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb +29 -30
- data/spec/lib/appsignal/event_formatter_spec.rb +28 -28
- data/spec/lib/appsignal/extension_spec.rb +15 -15
- data/spec/lib/appsignal/garbage_collection_profiler_spec.rb +6 -5
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +12 -12
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +34 -34
- data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +3 -3
- data/spec/lib/appsignal/hooks/net_http_spec.rb +10 -10
- data/spec/lib/appsignal/hooks/rake_spec.rb +7 -7
- data/spec/lib/appsignal/hooks/redis_spec.rb +6 -6
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +21 -22
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +48 -45
- data/spec/lib/appsignal/hooks/webmachine_spec.rb +2 -2
- data/spec/lib/appsignal/hooks_spec.rb +16 -17
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +7 -8
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +19 -19
- data/spec/lib/appsignal/integrations/object_spec.rb +3 -3
- data/spec/lib/appsignal/integrations/padrino_spec.rb +44 -44
- data/spec/lib/appsignal/integrations/railtie_spec.rb +13 -13
- data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +7 -7
- data/spec/lib/appsignal/integrations/resque_spec.rb +8 -8
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +7 -7
- data/spec/lib/appsignal/integrations/webmachine_spec.rb +15 -15
- data/spec/lib/appsignal/js_exception_transaction_spec.rb +23 -23
- data/spec/lib/appsignal/marker_spec.rb +8 -8
- data/spec/lib/appsignal/minutely_spec.rb +6 -6
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +7 -7
- data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +13 -13
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +11 -11
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +21 -21
- data/spec/lib/appsignal/rack/streaming_listener_spec.rb +36 -36
- data/spec/lib/appsignal/system/container_spec.rb +1 -1
- data/spec/lib/appsignal/transaction_spec.rb +213 -184
- data/spec/lib/appsignal/transmitter_spec.rb +20 -20
- data/spec/lib/appsignal/utils/params_sanitizer_spec.rb +19 -19
- data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +41 -41
- data/spec/lib/appsignal/utils_spec.rb +41 -37
- data/spec/lib/appsignal_spec.rb +150 -142
- data/spec/spec_helper.rb +18 -18
- data/spec/support/delegate_matcher.rb +6 -6
- data/spec/support/helpers/api_request_helper.rb +2 -2
- data/spec/support/helpers/config_helpers.rb +3 -3
- data/spec/support/helpers/dependency_helper.rb +13 -13
- data/spec/support/helpers/directory_helper.rb +5 -5
- data/spec/support/helpers/env_helpers.rb +14 -14
- data/spec/support/helpers/system_helpers.rb +3 -3
- data/spec/support/helpers/transaction_helpers.rb +10 -10
- metadata +20 -2
data/spec/lib/appsignal_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "./spec/support/mocks/mock_extension"
|
2
2
|
|
3
3
|
describe Appsignal do
|
4
4
|
before do
|
@@ -42,11 +42,11 @@ describe Appsignal do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should create a config from the env" do
|
45
|
-
ENV[
|
45
|
+
ENV["APPSIGNAL_PUSH_API_KEY"] = "something"
|
46
46
|
Appsignal::Extension.should_receive(:start)
|
47
47
|
expect(Appsignal.logger).not_to receive(:error)
|
48
48
|
silence { Appsignal.start }
|
49
|
-
expect(Appsignal.config[:push_api_key]).to eq(
|
49
|
+
expect(Appsignal.config[:push_api_key]).to eq("something")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -69,7 +69,7 @@ describe Appsignal do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
context "when not active for this environment" do
|
72
|
-
before { Appsignal.config = project_fixture_config(
|
72
|
+
before { Appsignal.config = project_fixture_config("staging") }
|
73
73
|
|
74
74
|
it "should do nothing" do
|
75
75
|
Appsignal.start
|
@@ -125,10 +125,10 @@ describe Appsignal do
|
|
125
125
|
Appsignal.start
|
126
126
|
end
|
127
127
|
|
128
|
-
|
128
|
+
it "should not add the gc probe to minutely" do
|
129
129
|
expect(Appsignal::Minutely).not_to receive(:add_gc_probe)
|
130
130
|
Appsignal.start
|
131
|
-
|
131
|
+
end
|
132
132
|
end
|
133
133
|
|
134
134
|
context "when minutely metrics has been enabled" do
|
@@ -155,7 +155,7 @@ describe Appsignal do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
context "with debug logging" do
|
158
|
-
before { Appsignal.config = project_fixture_config(
|
158
|
+
before { Appsignal.config = project_fixture_config("test") }
|
159
159
|
|
160
160
|
it "should change the log level" do
|
161
161
|
Appsignal.start
|
@@ -189,7 +189,7 @@ describe Appsignal do
|
|
189
189
|
|
190
190
|
describe ".stop" do
|
191
191
|
it "should call stop on the extension" do
|
192
|
-
Appsignal.logger.should_receive(:debug).with(
|
192
|
+
Appsignal.logger.should_receive(:debug).with("Stopping appsignal")
|
193
193
|
Appsignal::Extension.should_receive(:stop)
|
194
194
|
Appsignal.stop
|
195
195
|
Appsignal.active?.should be_false
|
@@ -197,15 +197,15 @@ describe Appsignal do
|
|
197
197
|
|
198
198
|
context "with context specified" do
|
199
199
|
it "should log the context" do
|
200
|
-
Appsignal.logger.should_receive(:debug).with(
|
200
|
+
Appsignal.logger.should_receive(:debug).with("Stopping appsignal (something)")
|
201
201
|
Appsignal::Extension.should_receive(:stop)
|
202
|
-
Appsignal.stop(
|
202
|
+
Appsignal.stop("something")
|
203
203
|
Appsignal.active?.should be_false
|
204
204
|
end
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
-
describe
|
208
|
+
describe ".active?" do
|
209
209
|
subject { Appsignal.active? }
|
210
210
|
|
211
211
|
context "without config" do
|
@@ -218,7 +218,7 @@ describe Appsignal do
|
|
218
218
|
|
219
219
|
context "with inactive config" do
|
220
220
|
before do
|
221
|
-
Appsignal.config = project_fixture_config(
|
221
|
+
Appsignal.config = project_fixture_config("nonsense")
|
222
222
|
end
|
223
223
|
|
224
224
|
it { should be_false }
|
@@ -241,13 +241,13 @@ describe Appsignal do
|
|
241
241
|
|
242
242
|
describe ".get_server_state" do
|
243
243
|
it "should call server state on the extension" do
|
244
|
-
Appsignal::Extension.should_receive(:get_server_state).with(
|
244
|
+
Appsignal::Extension.should_receive(:get_server_state).with("key")
|
245
245
|
|
246
|
-
Appsignal.get_server_state(
|
246
|
+
Appsignal.get_server_state("key")
|
247
247
|
end
|
248
248
|
|
249
249
|
it "should get nil by default" do
|
250
|
-
Appsignal.get_server_state(
|
250
|
+
Appsignal.get_server_state("key").should be_nil
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
@@ -259,59 +259,59 @@ describe Appsignal do
|
|
259
259
|
object = double
|
260
260
|
object.should_receive(:some_method).and_return(1)
|
261
261
|
|
262
|
-
lambda
|
263
|
-
Appsignal.monitor_transaction(
|
262
|
+
lambda do
|
263
|
+
Appsignal.monitor_transaction("perform_job.nothing") do
|
264
264
|
object.some_method
|
265
265
|
end.should eq 1
|
266
|
-
|
266
|
+
end.should_not raise_error
|
267
267
|
end
|
268
268
|
end
|
269
269
|
|
270
270
|
describe ".listen_for_error" do
|
271
271
|
it "should do nothing" do
|
272
|
-
error = RuntimeError.new(
|
273
|
-
lambda
|
272
|
+
error = RuntimeError.new("specific error")
|
273
|
+
lambda do
|
274
274
|
Appsignal.listen_for_error do
|
275
275
|
raise error
|
276
276
|
end
|
277
|
-
|
277
|
+
end.should raise_error(error)
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
281
|
describe ".send_error" do
|
282
282
|
it "should do nothing" do
|
283
|
-
lambda
|
283
|
+
lambda do
|
284
284
|
Appsignal.send_error(RuntimeError.new)
|
285
|
-
|
285
|
+
end.should_not raise_error
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
289
|
describe ".set_error" do
|
290
290
|
it "should do nothing" do
|
291
|
-
lambda
|
291
|
+
lambda do
|
292
292
|
Appsignal.set_error(RuntimeError.new)
|
293
|
-
|
293
|
+
end.should_not raise_error
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
297
|
describe ".tag_request" do
|
298
298
|
it "should do nothing" do
|
299
|
-
lambda
|
300
|
-
Appsignal.tag_request(:tag =>
|
301
|
-
|
299
|
+
lambda do
|
300
|
+
Appsignal.tag_request(:tag => "tag")
|
301
|
+
end.should_not raise_error
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
305
|
describe ".instrument" do
|
306
306
|
it "should not instrument, but still call the block" do
|
307
307
|
stub = double
|
308
|
-
stub.should_receive(:method_call).and_return(
|
308
|
+
stub.should_receive(:method_call).and_return("return value")
|
309
309
|
|
310
|
-
lambda
|
311
|
-
Appsignal.instrument
|
310
|
+
lambda do
|
311
|
+
Appsignal.instrument "name" do
|
312
312
|
stub.method_call
|
313
|
-
end.should eq
|
314
|
-
|
313
|
+
end.should eq "return value"
|
314
|
+
end.should_not raise_error
|
315
315
|
end
|
316
316
|
end
|
317
317
|
end
|
@@ -326,14 +326,14 @@ describe Appsignal do
|
|
326
326
|
context "with a successful call" do
|
327
327
|
it "should instrument and complete for a background job" do
|
328
328
|
Appsignal.should_receive(:instrument).with(
|
329
|
-
|
329
|
+
"perform_job.something"
|
330
330
|
).and_yield
|
331
331
|
Appsignal::Transaction.should_receive(:complete_current!)
|
332
332
|
object = double
|
333
333
|
object.should_receive(:some_method).and_return(1)
|
334
334
|
|
335
335
|
Appsignal.monitor_transaction(
|
336
|
-
|
336
|
+
"perform_job.something",
|
337
337
|
background_env_with_data
|
338
338
|
) do
|
339
339
|
current = Appsignal::Transaction.current
|
@@ -345,14 +345,14 @@ describe Appsignal do
|
|
345
345
|
|
346
346
|
it "should instrument and complete for a http request" do
|
347
347
|
Appsignal.should_receive(:instrument).with(
|
348
|
-
|
348
|
+
"process_action.something"
|
349
349
|
).and_yield
|
350
350
|
Appsignal::Transaction.should_receive(:complete_current!)
|
351
351
|
object = double
|
352
352
|
object.should_receive(:some_method)
|
353
353
|
|
354
354
|
Appsignal.monitor_transaction(
|
355
|
-
|
355
|
+
"process_action.something",
|
356
356
|
http_request_env_with_data
|
357
357
|
) do
|
358
358
|
current = Appsignal::Transaction.current
|
@@ -370,11 +370,11 @@ describe Appsignal do
|
|
370
370
|
Appsignal::Transaction.any_instance.should_receive(:set_error).with(error)
|
371
371
|
Appsignal::Transaction.should_receive(:complete_current!)
|
372
372
|
|
373
|
-
lambda
|
374
|
-
Appsignal.monitor_transaction(
|
373
|
+
lambda do
|
374
|
+
Appsignal.monitor_transaction("perform_job.something") do
|
375
375
|
raise error
|
376
376
|
end
|
377
|
-
|
377
|
+
end.should raise_error(error)
|
378
378
|
end
|
379
379
|
end
|
380
380
|
end
|
@@ -383,12 +383,12 @@ describe Appsignal do
|
|
383
383
|
context "with a successful call" do
|
384
384
|
it "should call monitor_transaction and stop" do
|
385
385
|
Appsignal.should_receive(:monitor_transaction).with(
|
386
|
-
|
386
|
+
"perform_job.something",
|
387
387
|
:key => :value
|
388
388
|
).and_yield
|
389
389
|
Appsignal.should_receive(:stop)
|
390
390
|
|
391
|
-
Appsignal.monitor_single_transaction(
|
391
|
+
Appsignal.monitor_single_transaction("perform_job.something", :key => :value) do
|
392
392
|
# nothing
|
393
393
|
end
|
394
394
|
end
|
@@ -399,16 +399,16 @@ describe Appsignal do
|
|
399
399
|
|
400
400
|
it "should call monitor_transaction and stop and then raise the error" do
|
401
401
|
Appsignal.should_receive(:monitor_transaction).with(
|
402
|
-
|
402
|
+
"perform_job.something",
|
403
403
|
:key => :value
|
404
404
|
).and_yield
|
405
405
|
Appsignal.should_receive(:stop)
|
406
406
|
|
407
|
-
lambda
|
408
|
-
Appsignal.monitor_single_transaction(
|
407
|
+
lambda do
|
408
|
+
Appsignal.monitor_single_transaction("perform_job.something", :key => :value) do
|
409
409
|
raise error
|
410
410
|
end
|
411
|
-
|
411
|
+
end.should raise_error(error)
|
412
412
|
end
|
413
413
|
end
|
414
414
|
end
|
@@ -419,11 +419,10 @@ describe Appsignal do
|
|
419
419
|
context "with transaction" do
|
420
420
|
let(:transaction) { double }
|
421
421
|
it "should call set_tags on transaction" do
|
422
|
-
|
423
|
-
transaction.should_receive(:set_tags).with({'a' => 'b'})
|
422
|
+
transaction.should_receive(:set_tags).with("a" => "b")
|
424
423
|
end
|
425
424
|
|
426
|
-
after { Appsignal.tag_request(
|
425
|
+
after { Appsignal.tag_request("a" => "b") }
|
427
426
|
end
|
428
427
|
|
429
428
|
context "without transaction" do
|
@@ -442,111 +441,111 @@ describe Appsignal do
|
|
442
441
|
describe "custom stats" do
|
443
442
|
describe ".set_gauge" do
|
444
443
|
it "should call set_gauge on the extension with a string key and float" do
|
445
|
-
Appsignal::Extension.should_receive(:set_gauge).with(
|
446
|
-
Appsignal.set_gauge(
|
444
|
+
Appsignal::Extension.should_receive(:set_gauge).with("key", 0.1)
|
445
|
+
Appsignal.set_gauge("key", 0.1)
|
447
446
|
end
|
448
447
|
|
449
448
|
it "should call set_gauge on the extension with a symbol key and int" do
|
450
|
-
Appsignal::Extension.should_receive(:set_gauge).with(
|
449
|
+
Appsignal::Extension.should_receive(:set_gauge).with("key", 1.0)
|
451
450
|
Appsignal.set_gauge(:key, 1)
|
452
451
|
end
|
453
452
|
|
454
453
|
it "should not raise an exception when out of range" do
|
455
|
-
Appsignal::Extension.should_receive(:set_gauge).with(
|
454
|
+
Appsignal::Extension.should_receive(:set_gauge).with("key", 10).and_raise(RangeError)
|
456
455
|
Appsignal.logger.should_receive(:warn).with("Gauge value 10 for key 'key' is too big")
|
457
|
-
lambda
|
458
|
-
Appsignal.set_gauge(
|
459
|
-
|
456
|
+
lambda do
|
457
|
+
Appsignal.set_gauge("key", 10)
|
458
|
+
end.should_not raise_error
|
460
459
|
end
|
461
460
|
end
|
462
461
|
|
463
462
|
describe ".set_host_gauge" do
|
464
463
|
it "should call set_host_gauge on the extension with a string key and float" do
|
465
|
-
Appsignal::Extension.should_receive(:set_host_gauge).with(
|
466
|
-
Appsignal.set_host_gauge(
|
464
|
+
Appsignal::Extension.should_receive(:set_host_gauge).with("key", 0.1)
|
465
|
+
Appsignal.set_host_gauge("key", 0.1)
|
467
466
|
end
|
468
467
|
|
469
468
|
it "should call set_host_gauge on the extension with a symbol key and int" do
|
470
|
-
Appsignal::Extension.should_receive(:set_host_gauge).with(
|
469
|
+
Appsignal::Extension.should_receive(:set_host_gauge).with("key", 1.0)
|
471
470
|
Appsignal.set_host_gauge(:key, 1)
|
472
471
|
end
|
473
472
|
|
474
473
|
it "should not raise an exception when out of range" do
|
475
|
-
Appsignal::Extension.should_receive(:set_host_gauge).with(
|
474
|
+
Appsignal::Extension.should_receive(:set_host_gauge).with("key", 10).and_raise(RangeError)
|
476
475
|
Appsignal.logger.should_receive(:warn).with("Host gauge value 10 for key 'key' is too big")
|
477
|
-
lambda
|
478
|
-
Appsignal.set_host_gauge(
|
479
|
-
|
476
|
+
lambda do
|
477
|
+
Appsignal.set_host_gauge("key", 10)
|
478
|
+
end.should_not raise_error
|
480
479
|
end
|
481
480
|
end
|
482
481
|
|
483
482
|
describe ".set_process_gauge" do
|
484
483
|
it "should call set_process_gauge on the extension with a string key and float" do
|
485
|
-
Appsignal::Extension.should_receive(:set_process_gauge).with(
|
486
|
-
Appsignal.set_process_gauge(
|
484
|
+
Appsignal::Extension.should_receive(:set_process_gauge).with("key", 0.1)
|
485
|
+
Appsignal.set_process_gauge("key", 0.1)
|
487
486
|
end
|
488
487
|
|
489
488
|
it "should call set_process_gauge on the extension with a symbol key and int" do
|
490
|
-
Appsignal::Extension.should_receive(:set_process_gauge).with(
|
489
|
+
Appsignal::Extension.should_receive(:set_process_gauge).with("key", 1.0)
|
491
490
|
Appsignal.set_process_gauge(:key, 1)
|
492
491
|
end
|
493
492
|
|
494
493
|
it "should not raise an exception when out of range" do
|
495
|
-
Appsignal::Extension.should_receive(:set_process_gauge).with(
|
494
|
+
Appsignal::Extension.should_receive(:set_process_gauge).with("key", 10).and_raise(RangeError)
|
496
495
|
Appsignal.logger.should_receive(:warn).with("Process gauge value 10 for key 'key' is too big")
|
497
|
-
lambda
|
498
|
-
Appsignal.set_process_gauge(
|
499
|
-
|
496
|
+
lambda do
|
497
|
+
Appsignal.set_process_gauge("key", 10)
|
498
|
+
end.should_not raise_error
|
500
499
|
end
|
501
500
|
end
|
502
501
|
|
503
502
|
describe ".increment_counter" do
|
504
503
|
it "should call increment_counter on the extension with a string key" do
|
505
|
-
Appsignal::Extension.should_receive(:increment_counter).with(
|
506
|
-
Appsignal.increment_counter(
|
504
|
+
Appsignal::Extension.should_receive(:increment_counter).with("key", 1)
|
505
|
+
Appsignal.increment_counter("key")
|
507
506
|
end
|
508
507
|
|
509
508
|
it "should call increment_counter on the extension with a symbol key" do
|
510
|
-
Appsignal::Extension.should_receive(:increment_counter).with(
|
509
|
+
Appsignal::Extension.should_receive(:increment_counter).with("key", 1)
|
511
510
|
Appsignal.increment_counter(:key)
|
512
511
|
end
|
513
512
|
|
514
513
|
it "should call increment_counter on the extension with a count" do
|
515
|
-
Appsignal::Extension.should_receive(:increment_counter).with(
|
516
|
-
Appsignal.increment_counter(
|
514
|
+
Appsignal::Extension.should_receive(:increment_counter).with("key", 5)
|
515
|
+
Appsignal.increment_counter("key", 5)
|
517
516
|
end
|
518
517
|
|
519
518
|
it "should not raise an exception when out of range" do
|
520
|
-
Appsignal::Extension.should_receive(:increment_counter).with(
|
519
|
+
Appsignal::Extension.should_receive(:increment_counter).with("key", 10).and_raise(RangeError)
|
521
520
|
Appsignal.logger.should_receive(:warn).with("Counter value 10 for key 'key' is too big")
|
522
|
-
lambda
|
523
|
-
Appsignal.increment_counter(
|
524
|
-
|
521
|
+
lambda do
|
522
|
+
Appsignal.increment_counter("key", 10)
|
523
|
+
end.should_not raise_error
|
525
524
|
end
|
526
525
|
end
|
527
526
|
|
528
527
|
describe ".add_distribution_value" do
|
529
528
|
it "should call add_distribution_value on the extension with a string key and float" do
|
530
|
-
Appsignal::Extension.should_receive(:add_distribution_value).with(
|
531
|
-
Appsignal.add_distribution_value(
|
529
|
+
Appsignal::Extension.should_receive(:add_distribution_value).with("key", 0.1)
|
530
|
+
Appsignal.add_distribution_value("key", 0.1)
|
532
531
|
end
|
533
532
|
|
534
533
|
it "should call add_distribution_value on the extension with a symbol key and int" do
|
535
|
-
Appsignal::Extension.should_receive(:add_distribution_value).with(
|
534
|
+
Appsignal::Extension.should_receive(:add_distribution_value).with("key", 1.0)
|
536
535
|
Appsignal.add_distribution_value(:key, 1)
|
537
536
|
end
|
538
537
|
|
539
538
|
it "should not raise an exception when out of range" do
|
540
|
-
Appsignal::Extension.should_receive(:add_distribution_value).with(
|
539
|
+
Appsignal::Extension.should_receive(:add_distribution_value).with("key", 10).and_raise(RangeError)
|
541
540
|
Appsignal.logger.should_receive(:warn).with("Distribution value 10 for key 'key' is too big")
|
542
|
-
lambda
|
543
|
-
Appsignal.add_distribution_value(
|
544
|
-
|
541
|
+
lambda do
|
542
|
+
Appsignal.add_distribution_value("key", 10)
|
543
|
+
end.should_not raise_error
|
545
544
|
end
|
546
545
|
end
|
547
546
|
end
|
548
547
|
|
549
|
-
describe
|
548
|
+
describe ".logger" do
|
550
549
|
subject { Appsignal.logger }
|
551
550
|
|
552
551
|
it { should be_a Logger }
|
@@ -555,15 +554,15 @@ describe Appsignal do
|
|
555
554
|
describe ".start_logger" do
|
556
555
|
let(:out_stream) { std_stream }
|
557
556
|
let(:output) { out_stream.read }
|
558
|
-
let(:log_path) { File.join(tmp_dir,
|
559
|
-
let(:log_file) { File.join(log_path,
|
557
|
+
let(:log_path) { File.join(tmp_dir, "log") }
|
558
|
+
let(:log_file) { File.join(log_path, "appsignal.log") }
|
560
559
|
|
561
560
|
before do
|
562
561
|
FileUtils.mkdir_p(log_path)
|
563
562
|
|
564
|
-
Appsignal.logger.error(
|
563
|
+
Appsignal.logger.error("Log in memory")
|
565
564
|
Appsignal.config = project_fixture_config(
|
566
|
-
|
565
|
+
"production",
|
567
566
|
:log_path => log_path
|
568
567
|
)
|
569
568
|
end
|
@@ -577,18 +576,18 @@ describe Appsignal do
|
|
577
576
|
before do
|
578
577
|
capture_stdout(out_stream) do
|
579
578
|
Appsignal.start_logger
|
580
|
-
Appsignal.logger.error(
|
579
|
+
Appsignal.logger.error("Log to file")
|
581
580
|
end
|
582
581
|
end
|
583
582
|
|
584
583
|
it "logs to file" do
|
585
584
|
expect(File.exist?(log_file)).to be_true
|
586
|
-
expect(log_file_contents).to include
|
585
|
+
expect(log_file_contents).to include "[ERROR] Log to file"
|
587
586
|
expect(output).to be_empty
|
588
587
|
end
|
589
588
|
|
590
589
|
it "amends in memory log to log file" do
|
591
|
-
expect(log_file_contents).to include
|
590
|
+
expect(log_file_contents).to include "[ERROR] appsignal: Log in memory"
|
592
591
|
end
|
593
592
|
end
|
594
593
|
|
@@ -599,17 +598,17 @@ describe Appsignal do
|
|
599
598
|
|
600
599
|
capture_stdout(out_stream) do
|
601
600
|
Appsignal.start_logger
|
602
|
-
Appsignal.logger.error(
|
601
|
+
Appsignal.logger.error("Log to not writable log file")
|
603
602
|
end
|
604
603
|
end
|
605
604
|
|
606
605
|
it "logs to stdout" do
|
607
606
|
expect(File.writable?(log_file)).to be_false
|
608
|
-
expect(output).to include
|
607
|
+
expect(output).to include "[ERROR] appsignal: Log to not writable log file"
|
609
608
|
end
|
610
609
|
|
611
610
|
it "amends in memory log to stdout" do
|
612
|
-
expect(output).to include
|
611
|
+
expect(output).to include "[ERROR] appsignal: Log in memory"
|
613
612
|
end
|
614
613
|
|
615
614
|
it "outputs a warning" do
|
@@ -627,7 +626,7 @@ describe Appsignal do
|
|
627
626
|
|
628
627
|
capture_stdout(out_stream) do
|
629
628
|
Appsignal.start_logger
|
630
|
-
Appsignal.logger.error(
|
629
|
+
Appsignal.logger.error("Log to not writable log path")
|
631
630
|
end
|
632
631
|
end
|
633
632
|
after do
|
@@ -636,11 +635,11 @@ describe Appsignal do
|
|
636
635
|
|
637
636
|
it "logs to stdout" do
|
638
637
|
expect(File.writable?(log_path)).to be_false
|
639
|
-
expect(output).to include
|
638
|
+
expect(output).to include "[ERROR] appsignal: Log to not writable log path"
|
640
639
|
end
|
641
640
|
|
642
641
|
it "amends in memory log to stdout" do
|
643
|
-
expect(output).to include
|
642
|
+
expect(output).to include "[ERROR] appsignal: Log in memory"
|
644
643
|
end
|
645
644
|
|
646
645
|
it "outputs a warning" do
|
@@ -654,17 +653,17 @@ describe Appsignal do
|
|
654
653
|
before do
|
655
654
|
capture_stdout(out_stream) do
|
656
655
|
Appsignal.start_logger
|
657
|
-
Appsignal.logger.error(
|
656
|
+
Appsignal.logger.error("Log to stdout")
|
658
657
|
end
|
659
658
|
end
|
660
659
|
around { |example| recognize_as_heroku { example.run } }
|
661
660
|
|
662
661
|
it "logs to stdout" do
|
663
|
-
expect(output).to include
|
662
|
+
expect(output).to include "[ERROR] appsignal: Log to stdout"
|
664
663
|
end
|
665
664
|
|
666
665
|
it "amends in memory log to stdout" do
|
667
|
-
expect(output).to include
|
666
|
+
expect(output).to include "[ERROR] appsignal: Log in memory"
|
668
667
|
end
|
669
668
|
end
|
670
669
|
|
@@ -702,7 +701,7 @@ describe Appsignal do
|
|
702
701
|
end
|
703
702
|
|
704
703
|
describe ".log_formatter" do
|
705
|
-
subject { Appsignal.log_formatter.call(
|
704
|
+
subject { Appsignal.log_formatter.call("Debug", Time.parse("2015-07-08"), nil, "log line") }
|
706
705
|
|
707
706
|
it "formats a log" do
|
708
707
|
expect(subject).to eq "[2015-07-08T00:00:00 (process) ##{Process.pid}][Debug] log line\n"
|
@@ -710,7 +709,7 @@ describe Appsignal do
|
|
710
709
|
|
711
710
|
context "with prefix" do
|
712
711
|
subject do
|
713
|
-
Appsignal.log_formatter("prefix").call(
|
712
|
+
Appsignal.log_formatter("prefix").call("Debug", Time.parse("2015-07-08"), nil, "log line")
|
714
713
|
end
|
715
714
|
|
716
715
|
it "adds a prefix" do
|
@@ -720,17 +719,17 @@ describe Appsignal do
|
|
720
719
|
end
|
721
720
|
end
|
722
721
|
|
723
|
-
describe
|
722
|
+
describe ".config" do
|
724
723
|
subject { Appsignal.config }
|
725
724
|
|
726
725
|
it { should be_a Appsignal::Config }
|
727
|
-
it
|
728
|
-
subject[:endpoint].should eq
|
726
|
+
it "should return configuration" do
|
727
|
+
subject[:endpoint].should eq "https://push.appsignal.com"
|
729
728
|
end
|
730
729
|
end
|
731
730
|
|
732
731
|
describe ".send_error" do
|
733
|
-
let(:tags)
|
732
|
+
let(:tags) { nil }
|
734
733
|
let(:error) { VerySpecificError.new }
|
735
734
|
|
736
735
|
it "should send the error to AppSignal" do
|
@@ -738,7 +737,7 @@ describe Appsignal do
|
|
738
737
|
end
|
739
738
|
|
740
739
|
context "with tags" do
|
741
|
-
let(:tags) { {:a =>
|
740
|
+
let(:tags) { { :a => "a", :b => "b" } }
|
742
741
|
|
743
742
|
it "should tag the request before sending" do
|
744
743
|
transaction = Appsignal::Transaction.new(
|
@@ -752,20 +751,15 @@ describe Appsignal do
|
|
752
751
|
end
|
753
752
|
end
|
754
753
|
|
755
|
-
it "should not send the error if it's in the ignored list" do
|
756
|
-
Appsignal.stub(:is_ignored_error? => true)
|
757
|
-
Appsignal::Transaction.should_not_receive(:create)
|
758
|
-
end
|
759
|
-
|
760
754
|
context "when given class is not an error" do
|
761
755
|
let(:error) { double }
|
762
756
|
|
763
757
|
it "should log a message" do
|
764
|
-
expect(
|
758
|
+
expect(Appsignal.logger).to receive(:error).with('Can\'t send error, given value is not an exception')
|
765
759
|
end
|
766
760
|
|
767
761
|
it "should not send the error" do
|
768
|
-
expect(
|
762
|
+
expect(Appsignal::Transaction).to_not receive(:create)
|
769
763
|
end
|
770
764
|
end
|
771
765
|
|
@@ -777,17 +771,17 @@ describe Appsignal do
|
|
777
771
|
describe ".listen_for_error" do
|
778
772
|
it "should call send_error and re-raise" do
|
779
773
|
Appsignal.should_receive(:send_error).with(kind_of(Exception))
|
780
|
-
lambda
|
774
|
+
lambda do
|
781
775
|
Appsignal.listen_for_error do
|
782
776
|
raise "I am an exception"
|
783
777
|
end
|
784
|
-
|
778
|
+
end.should raise_error(RuntimeError, "I am an exception")
|
785
779
|
end
|
786
780
|
end
|
787
781
|
|
788
782
|
describe ".set_error" do
|
789
783
|
before { Appsignal::Transaction.stub(:current => transaction) }
|
790
|
-
let(:error) { RuntimeError.new(
|
784
|
+
let(:error) { RuntimeError.new("I am an exception") }
|
791
785
|
|
792
786
|
it "should add the error to the current transaction" do
|
793
787
|
transaction.should_receive(:set_error).with(error)
|
@@ -803,14 +797,6 @@ describe Appsignal do
|
|
803
797
|
Appsignal.set_error(error)
|
804
798
|
end
|
805
799
|
|
806
|
-
it "should not add the error if it's in the ignored list" do
|
807
|
-
Appsignal.stub(:is_ignored_error? => true)
|
808
|
-
|
809
|
-
transaction.should_not_receive(:set_error)
|
810
|
-
|
811
|
-
Appsignal.set_error(error)
|
812
|
-
end
|
813
|
-
|
814
800
|
it "should do nothing if the error is nil" do
|
815
801
|
transaction.should_not_receive(:set_error)
|
816
802
|
|
@@ -826,12 +812,12 @@ describe Appsignal do
|
|
826
812
|
it "should instrument through the transaction" do
|
827
813
|
expect(transaction).to receive(:start_event)
|
828
814
|
expect(transaction).to receive(:finish_event)
|
829
|
-
.with(
|
815
|
+
.with("name", "title", "body", Appsignal::EventFormatter::DEFAULT)
|
830
816
|
|
831
|
-
result = Appsignal.instrument
|
832
|
-
|
817
|
+
result = Appsignal.instrument "name", "title", "body" do
|
818
|
+
"return value"
|
833
819
|
end
|
834
|
-
expect(result).to eq
|
820
|
+
expect(result).to eq "return value"
|
835
821
|
end
|
836
822
|
end
|
837
823
|
|
@@ -843,12 +829,12 @@ describe Appsignal do
|
|
843
829
|
it "should instrument sql through the transaction" do
|
844
830
|
expect(transaction).to receive(:start_event)
|
845
831
|
expect(transaction).to receive(:finish_event)
|
846
|
-
.with(
|
832
|
+
.with("name", "title", "body", Appsignal::EventFormatter::SQL_BODY_FORMAT)
|
847
833
|
|
848
|
-
result = Appsignal.instrument_sql
|
849
|
-
|
834
|
+
result = Appsignal.instrument_sql "name", "title", "body" do
|
835
|
+
"return value"
|
850
836
|
end
|
851
|
-
expect(result).to eq
|
837
|
+
expect(result).to eq "return value"
|
852
838
|
end
|
853
839
|
end
|
854
840
|
|
@@ -878,18 +864,29 @@ describe Appsignal do
|
|
878
864
|
|
879
865
|
describe ".is_ignored_error?" do
|
880
866
|
let(:error) { StandardError.new }
|
867
|
+
let(:err_stream) { std_stream }
|
868
|
+
let(:stderr) { err_stream.read }
|
881
869
|
before do
|
882
870
|
Appsignal.stub(
|
883
|
-
:config => {:ignore_errors => [
|
871
|
+
:config => { :ignore_errors => ["StandardError"] }
|
884
872
|
)
|
885
873
|
end
|
886
874
|
|
887
|
-
subject
|
875
|
+
subject do
|
876
|
+
capture_std_streams(std_stream, err_stream) do
|
877
|
+
Appsignal.is_ignored_error?(error)
|
878
|
+
end
|
879
|
+
end
|
888
880
|
|
889
881
|
it "should return true if it's in the ignored list" do
|
890
882
|
should be_true
|
891
883
|
end
|
892
884
|
|
885
|
+
it "outputs deprecated warning" do
|
886
|
+
subject
|
887
|
+
expect(stderr).to include("Appsignal.is_ignored_error? is deprecated with no replacement.")
|
888
|
+
end
|
889
|
+
|
893
890
|
context "when error is not in the ignored list" do
|
894
891
|
let(:error) { Object.new }
|
895
892
|
|
@@ -900,21 +897,32 @@ describe Appsignal do
|
|
900
897
|
end
|
901
898
|
|
902
899
|
describe ".is_ignored_action?" do
|
903
|
-
let(:action) {
|
900
|
+
let(:action) { "TestController#isup" }
|
901
|
+
let(:err_stream) { std_stream }
|
902
|
+
let(:stderr) { err_stream.read }
|
904
903
|
before do
|
905
904
|
Appsignal.stub(
|
906
|
-
:config => {:ignore_actions =>
|
905
|
+
:config => { :ignore_actions => "TestController#isup" }
|
907
906
|
)
|
908
907
|
end
|
909
908
|
|
910
|
-
subject
|
909
|
+
subject do
|
910
|
+
capture_std_streams(std_stream, err_stream) do
|
911
|
+
Appsignal.is_ignored_action?(action)
|
912
|
+
end
|
913
|
+
end
|
911
914
|
|
912
915
|
it "should return true if it's in the ignored list" do
|
913
916
|
should be_true
|
914
917
|
end
|
915
918
|
|
919
|
+
it "outputs deprecated warning" do
|
920
|
+
subject
|
921
|
+
expect(stderr).to include("Appsignal.is_ignored_action? is deprecated with no replacement.")
|
922
|
+
end
|
923
|
+
|
916
924
|
context "when action is not in the ingore list" do
|
917
|
-
let(:action) {
|
925
|
+
let(:action) { "TestController#other_action" }
|
918
926
|
|
919
927
|
it "should return false" do
|
920
928
|
should be_false
|