appsignal 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +22 -0
- data/README.md +9 -5
- data/appsignal.gemspec +1 -1
- data/ext/agent.yml +11 -11
- data/lib/appsignal.rb +8 -9
- data/lib/appsignal/cli.rb +12 -14
- data/lib/appsignal/cli/diagnose.rb +82 -31
- data/lib/appsignal/cli/helpers.rb +67 -0
- data/lib/appsignal/cli/install.rb +22 -69
- data/lib/appsignal/config.rb +3 -3
- data/lib/appsignal/integrations/padrino.rb +1 -1
- data/lib/appsignal/integrations/railtie.rb +1 -1
- data/lib/appsignal/integrations/sinatra.rb +1 -1
- data/lib/appsignal/version.rb +1 -1
- data/spec/lib/appsignal/capistrano2_spec.rb +18 -19
- data/spec/lib/appsignal/capistrano3_spec.rb +16 -17
- data/spec/lib/appsignal/cli/demo_spec.rb +4 -4
- data/spec/lib/appsignal/cli/diagnose_spec.rb +237 -88
- data/spec/lib/appsignal/cli/helpers_spec.rb +99 -0
- data/spec/lib/appsignal/cli/install_spec.rb +486 -352
- data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +5 -6
- data/spec/lib/appsignal/cli_spec.rb +24 -44
- data/spec/lib/appsignal/config_spec.rb +39 -8
- data/spec/lib/appsignal/demo_spec.rb +13 -8
- data/spec/lib/appsignal/hooks_spec.rb +3 -0
- data/spec/lib/appsignal/integrations/object_spec.rb +35 -26
- data/spec/lib/appsignal/marker_spec.rb +10 -14
- data/spec/lib/appsignal_spec.rb +83 -60
- data/spec/spec_helper.rb +8 -7
- data/spec/support/helpers/cli_helpers.rb +9 -0
- data/spec/support/helpers/std_streams_helper.rb +44 -13
- data/spec/support/helpers/transaction_helpers.rb +2 -2
- metadata +9 -6
@@ -3,11 +3,8 @@ require "appsignal/cli"
|
|
3
3
|
describe Appsignal::CLI::NotifyOfDeploy do
|
4
4
|
include CLIHelpers
|
5
5
|
|
6
|
-
let(:out_stream) {
|
7
|
-
let(:output) { out_stream.
|
8
|
-
around do |example|
|
9
|
-
capture_stdout(out_stream) { example.run }
|
10
|
-
end
|
6
|
+
let(:out_stream) { std_stream }
|
7
|
+
let(:output) { out_stream.read }
|
11
8
|
|
12
9
|
define :include_deploy_notification do
|
13
10
|
match do |log|
|
@@ -35,7 +32,9 @@ describe Appsignal::CLI::NotifyOfDeploy do
|
|
35
32
|
end
|
36
33
|
|
37
34
|
def run
|
38
|
-
|
35
|
+
capture_stdout(out_stream) do
|
36
|
+
run_cli("notify_of_deploy", options)
|
37
|
+
end
|
39
38
|
end
|
40
39
|
|
41
40
|
context "without config" do
|
@@ -1,52 +1,46 @@
|
|
1
1
|
require 'appsignal/cli'
|
2
2
|
|
3
3
|
describe Appsignal::CLI do
|
4
|
-
let(:out_stream) {
|
4
|
+
let(:out_stream) { std_stream }
|
5
|
+
let(:output) { out_stream.read }
|
5
6
|
let(:cli) { Appsignal::CLI }
|
6
|
-
before
|
7
|
-
Dir.stub(:pwd => project_fixture_path)
|
8
|
-
cli.options = {:environment => 'production'}
|
9
|
-
end
|
10
|
-
around do |example|
|
11
|
-
capture_stdout(out_stream) { example.run }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#config" do
|
15
|
-
subject { cli.config }
|
16
|
-
|
17
|
-
it { should be_instance_of(Appsignal::Config) }
|
18
|
-
its(:valid?) { should be_true }
|
19
|
-
end
|
7
|
+
before { Dir.stub(:pwd => project_fixture_path) }
|
20
8
|
|
21
9
|
it "should print the help with no arguments, -h and --help" do
|
22
10
|
[nil, '-h', '--help'].each do |arg|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
11
|
+
expect do
|
12
|
+
capture_stdout(out_stream) do
|
13
|
+
cli.run([arg].compact)
|
14
|
+
end
|
15
|
+
end.to raise_error(SystemExit)
|
16
|
+
|
17
|
+
expect(output).to include 'appsignal <command> [options]'
|
18
|
+
expect(output).to include \
|
29
19
|
'Available commands: demo, diagnose, install, notify_of_deploy'
|
30
20
|
end
|
31
21
|
end
|
32
22
|
|
33
23
|
it "should print the version with -v and --version" do
|
34
24
|
['-v', '--version'].each do |arg|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
25
|
+
expect do
|
26
|
+
capture_stdout(out_stream) do
|
27
|
+
cli.run([arg])
|
28
|
+
end
|
29
|
+
end.to raise_error(SystemExit)
|
30
|
+
|
31
|
+
expect(output).to include 'AppSignal'
|
32
|
+
expect(output).to include '.'
|
41
33
|
end
|
42
34
|
end
|
43
35
|
|
44
36
|
it "should print a notice if a command does not exist" do
|
45
|
-
|
37
|
+
expect do
|
38
|
+
capture_stdout(out_stream) do
|
46
39
|
cli.run(['nonsense'])
|
47
|
-
|
40
|
+
end
|
41
|
+
end.to raise_error(SystemExit)
|
48
42
|
|
49
|
-
|
43
|
+
expect(output).to include "Command 'nonsense' does not exist, run "\
|
50
44
|
"appsignal -h to see the help"
|
51
45
|
end
|
52
46
|
|
@@ -59,18 +53,4 @@ describe Appsignal::CLI do
|
|
59
53
|
])
|
60
54
|
end
|
61
55
|
end
|
62
|
-
|
63
|
-
describe "install" do
|
64
|
-
it "should call Appsignal::Install.install" do
|
65
|
-
Appsignal::CLI::Install.should_receive(:run).with(
|
66
|
-
'api-key',
|
67
|
-
instance_of(Appsignal::Config)
|
68
|
-
)
|
69
|
-
|
70
|
-
cli.run([
|
71
|
-
'install',
|
72
|
-
'api-key'
|
73
|
-
])
|
74
|
-
end
|
75
|
-
end
|
76
56
|
end
|
@@ -1,4 +1,34 @@
|
|
1
1
|
describe Appsignal::Config do
|
2
|
+
describe "#initialize" do
|
3
|
+
subject { config.env }
|
4
|
+
|
5
|
+
describe "environment" do
|
6
|
+
context "when environment is nil" do
|
7
|
+
let(:config) { described_class.new("", "") }
|
8
|
+
|
9
|
+
it "sets an empty string" do
|
10
|
+
expect(subject).to eq("")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when environment is given" do
|
15
|
+
let(:config) { described_class.new("", "my_env") }
|
16
|
+
|
17
|
+
it "sets the environment" do
|
18
|
+
expect(subject).to eq("my_env")
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with APPSIGNAL_APP_ENV environment variable" do
|
22
|
+
before { ENV["APPSIGNAL_APP_ENV"] = "my_env_env" }
|
23
|
+
|
24
|
+
it "uses the environment variable" do
|
25
|
+
expect(subject).to eq("my_env_env")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
2
32
|
describe "config based on the system" do
|
3
33
|
let(:config) { project_fixture_config(:none) }
|
4
34
|
|
@@ -407,12 +437,13 @@ describe Appsignal::Config do
|
|
407
437
|
end
|
408
438
|
|
409
439
|
describe "#log_file_path" do
|
410
|
-
let(:
|
440
|
+
let(:out_stream) { std_stream }
|
441
|
+
let(:output) { out_stream.read }
|
411
442
|
let(:config) { project_fixture_config('production', :log_path => log_path) }
|
412
|
-
subject { config.log_file_path }
|
443
|
+
subject { capture_stdout(out_stream) { config.log_file_path } }
|
413
444
|
around do |example|
|
414
445
|
recognize_as_container(:none) do
|
415
|
-
|
446
|
+
example.run
|
416
447
|
end
|
417
448
|
end
|
418
449
|
|
@@ -427,7 +458,7 @@ describe Appsignal::Config do
|
|
427
458
|
|
428
459
|
it "prints no warning" do
|
429
460
|
subject
|
430
|
-
expect(
|
461
|
+
expect(output).to be_empty
|
431
462
|
end
|
432
463
|
end
|
433
464
|
|
@@ -445,7 +476,7 @@ describe Appsignal::Config do
|
|
445
476
|
|
446
477
|
it "prints a warning" do
|
447
478
|
subject
|
448
|
-
expect(
|
479
|
+
expect(output).to include "appsignal: Unable to log to '#{log_path}'. "\
|
449
480
|
"Logging to '#{system_tmp_dir}' instead."
|
450
481
|
end
|
451
482
|
end
|
@@ -459,7 +490,7 @@ describe Appsignal::Config do
|
|
459
490
|
|
460
491
|
it "prints a warning" do
|
461
492
|
subject
|
462
|
-
expect(
|
493
|
+
expect(output).to include "appsignal: Unable to log to '#{log_path}' "\
|
463
494
|
"or the '#{system_tmp_dir}' fallback."
|
464
495
|
end
|
465
496
|
end
|
@@ -476,12 +507,12 @@ describe Appsignal::Config do
|
|
476
507
|
|
477
508
|
context "when root_path is set" do
|
478
509
|
it "returns returns the project log location" do
|
479
|
-
expect(subject).to eq File.join(config.root_path, 'appsignal.log')
|
510
|
+
expect(subject).to eq File.join(config.root_path, 'log/appsignal.log')
|
480
511
|
end
|
481
512
|
|
482
513
|
it "prints no warning" do
|
483
514
|
subject
|
484
|
-
expect(
|
515
|
+
expect(output).to be_empty
|
485
516
|
end
|
486
517
|
end
|
487
518
|
end
|
@@ -11,7 +11,7 @@ describe Appsignal::Demo do
|
|
11
11
|
|
12
12
|
context "without config" do
|
13
13
|
it "returns false" do
|
14
|
-
expect(subject).to be_false
|
14
|
+
expect(silence { subject }).to be_false
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -36,10 +36,12 @@ describe Appsignal::Demo do
|
|
36
36
|
let(:config) { project_fixture_config("production") }
|
37
37
|
before do
|
38
38
|
Appsignal.config = config
|
39
|
-
expect(Appsignal::Transaction).to receive(:
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
expect(Appsignal::Transaction).to receive(:new).with(
|
40
|
+
kind_of(String),
|
41
|
+
Appsignal::Transaction::HTTP_REQUEST,
|
42
|
+
kind_of(::Rack::Request),
|
43
|
+
kind_of(Hash)
|
44
|
+
).and_return(error_transaction)
|
43
45
|
end
|
44
46
|
subject { described_class.send(:create_example_error_request) }
|
45
47
|
|
@@ -57,9 +59,12 @@ describe Appsignal::Demo do
|
|
57
59
|
let(:config) { project_fixture_config("production") }
|
58
60
|
before do
|
59
61
|
Appsignal.config = config
|
60
|
-
expect(Appsignal::Transaction).to receive(:
|
61
|
-
|
62
|
-
|
62
|
+
expect(Appsignal::Transaction).to receive(:new).with(
|
63
|
+
kind_of(String),
|
64
|
+
Appsignal::Transaction::HTTP_REQUEST,
|
65
|
+
kind_of(::Rack::Request),
|
66
|
+
kind_of(Hash)
|
67
|
+
).and_return(performance_transaction)
|
63
68
|
end
|
64
69
|
subject { described_class.send(:create_example_performance_request) }
|
65
70
|
|
@@ -44,6 +44,7 @@ describe Appsignal::Hooks do
|
|
44
44
|
Appsignal::Hooks.load_hooks
|
45
45
|
Appsignal::Hooks.load_hooks
|
46
46
|
Appsignal::Hooks.hooks[:mock_present_hook].installed?.should be_true
|
47
|
+
Appsignal::Hooks.hooks.delete(:mock_present_hook)
|
47
48
|
end
|
48
49
|
|
49
50
|
it "should not install if depencies are not present" do
|
@@ -57,6 +58,7 @@ describe Appsignal::Hooks do
|
|
57
58
|
Appsignal::Hooks.load_hooks
|
58
59
|
|
59
60
|
Appsignal::Hooks.hooks[:mock_not_present_hook].installed?.should be_false
|
61
|
+
Appsignal::Hooks.hooks.delete(:mock_not_present_hook)
|
60
62
|
end
|
61
63
|
|
62
64
|
it "should not install if there is an error while installing" do
|
@@ -70,6 +72,7 @@ describe Appsignal::Hooks do
|
|
70
72
|
Appsignal::Hooks.load_hooks
|
71
73
|
|
72
74
|
Appsignal::Hooks.hooks[:mock_error_hook].installed?.should be_false
|
75
|
+
Appsignal::Hooks.hooks.delete(:mock_error_hook)
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
@@ -15,15 +15,18 @@ describe Object do
|
|
15
15
|
|
16
16
|
context "when active" do
|
17
17
|
let(:transaction) { http_request_transaction }
|
18
|
-
before
|
18
|
+
before do
|
19
|
+
expect(Appsignal::Transaction).to receive(:current).at_least(:once).and_return(transaction)
|
20
|
+
Appsignal.config = project_fixture_config
|
21
|
+
end
|
19
22
|
after { Appsignal.config = nil }
|
20
23
|
|
21
24
|
context "with anonymous class" do
|
22
25
|
it "instruments the method and calls it" do
|
23
26
|
expect(Appsignal.active?).to be_true
|
24
|
-
transaction.
|
25
|
-
transaction.
|
26
|
-
"foo.AnonymousClass.other", nil, nil,
|
27
|
+
expect(transaction).to receive(:start_event)
|
28
|
+
expect(transaction).to receive(:finish_event).with \
|
29
|
+
"foo.AnonymousClass.other", nil, nil, Appsignal::EventFormatter::DEFAULT
|
27
30
|
expect(instance.foo).to eq(1)
|
28
31
|
end
|
29
32
|
end
|
@@ -42,9 +45,9 @@ describe Object do
|
|
42
45
|
|
43
46
|
it "instruments the method and calls it" do
|
44
47
|
expect(Appsignal.active?).to be_true
|
45
|
-
transaction.
|
46
|
-
transaction.
|
47
|
-
"foo.NamedClass.other", nil, nil,
|
48
|
+
expect(transaction).to receive(:start_event)
|
49
|
+
expect(transaction).to receive(:finish_event).with \
|
50
|
+
"foo.NamedClass.other", nil, nil, Appsignal::EventFormatter::DEFAULT
|
48
51
|
expect(instance.foo).to eq(1)
|
49
52
|
end
|
50
53
|
end
|
@@ -67,9 +70,10 @@ describe Object do
|
|
67
70
|
|
68
71
|
it "instruments the method and calls it" do
|
69
72
|
expect(Appsignal.active?).to be_true
|
70
|
-
transaction.
|
71
|
-
transaction.
|
72
|
-
"bar.NamedClass.NestedModule.MyModule.other", nil, nil,
|
73
|
+
expect(transaction).to receive(:start_event)
|
74
|
+
expect(transaction).to receive(:finish_event).with \
|
75
|
+
"bar.NamedClass.NestedModule.MyModule.other", nil, nil,
|
76
|
+
Appsignal::EventFormatter::DEFAULT
|
73
77
|
expect(instance.bar).to eq(2)
|
74
78
|
end
|
75
79
|
end
|
@@ -86,9 +90,9 @@ describe Object do
|
|
86
90
|
|
87
91
|
it "instruments with custom name" do
|
88
92
|
expect(Appsignal.active?).to be_true
|
89
|
-
transaction.
|
90
|
-
transaction.
|
91
|
-
"my_method.group", nil, nil,
|
93
|
+
expect(transaction).to receive(:start_event)
|
94
|
+
expect(transaction).to receive(:finish_event).with \
|
95
|
+
"my_method.group", nil, nil, Appsignal::EventFormatter::DEFAULT
|
92
96
|
expect(instance.foo).to eq(1)
|
93
97
|
end
|
94
98
|
end
|
@@ -132,15 +136,19 @@ describe Object do
|
|
132
136
|
|
133
137
|
context "when active" do
|
134
138
|
let(:transaction) { http_request_transaction }
|
135
|
-
before
|
139
|
+
before do
|
140
|
+
expect(Appsignal::Transaction).to receive(:current).at_least(:once)
|
141
|
+
.and_return(transaction)
|
142
|
+
Appsignal.config = project_fixture_config
|
143
|
+
end
|
136
144
|
after { Appsignal.config = nil }
|
137
145
|
|
138
146
|
context "with anonymous class" do
|
139
147
|
it "instruments the method and calls it" do
|
140
148
|
expect(Appsignal.active?).to be_true
|
141
|
-
transaction.
|
142
|
-
transaction.
|
143
|
-
"bar.class_method.AnonymousClass.other", nil, nil,
|
149
|
+
expect(transaction).to receive(:start_event)
|
150
|
+
expect(transaction).to receive(:finish_event).with \
|
151
|
+
"bar.class_method.AnonymousClass.other", nil, nil, Appsignal::EventFormatter::DEFAULT
|
144
152
|
expect(klass.bar).to eq(2)
|
145
153
|
end
|
146
154
|
end
|
@@ -159,9 +167,9 @@ describe Object do
|
|
159
167
|
|
160
168
|
it "instruments the method and calls it" do
|
161
169
|
expect(Appsignal.active?).to be_true
|
162
|
-
transaction.
|
163
|
-
transaction.
|
164
|
-
"bar.class_method.NamedClass.other", nil, nil,
|
170
|
+
expect(transaction).to receive(:start_event)
|
171
|
+
expect(transaction).to receive(:finish_event).with \
|
172
|
+
"bar.class_method.NamedClass.other", nil, nil, Appsignal::EventFormatter::DEFAULT
|
165
173
|
expect(klass.bar).to eq(2)
|
166
174
|
end
|
167
175
|
|
@@ -183,9 +191,10 @@ describe Object do
|
|
183
191
|
|
184
192
|
it "instruments the method and calls it" do
|
185
193
|
expect(Appsignal.active?).to be_true
|
186
|
-
transaction.
|
187
|
-
transaction.
|
188
|
-
"bar.class_method.NamedClass.NestedModule.MyModule.other", nil, nil,
|
194
|
+
expect(transaction).to receive(:start_event)
|
195
|
+
expect(transaction).to receive(:finish_event).with \
|
196
|
+
"bar.class_method.NamedClass.NestedModule.MyModule.other", nil, nil,
|
197
|
+
Appsignal::EventFormatter::DEFAULT
|
189
198
|
expect(klass.bar).to eq(2)
|
190
199
|
end
|
191
200
|
end
|
@@ -203,9 +212,9 @@ describe Object do
|
|
203
212
|
|
204
213
|
it "instruments with custom name" do
|
205
214
|
expect(Appsignal.active?).to be_true
|
206
|
-
transaction.
|
207
|
-
transaction.
|
208
|
-
"my_method.group", nil, nil,
|
215
|
+
expect(transaction).to receive(:start_event)
|
216
|
+
expect(transaction).to receive(:finish_event).with \
|
217
|
+
"my_method.group", nil, nil, Appsignal::EventFormatter::DEFAULT
|
209
218
|
expect(klass.bar).to eq(2)
|
210
219
|
end
|
211
220
|
end
|
@@ -11,24 +11,23 @@ describe Appsignal::Marker do
|
|
11
11
|
config
|
12
12
|
)
|
13
13
|
end
|
14
|
-
let(:out_stream) {
|
15
|
-
|
16
|
-
capture_stdout(out_stream) { example.run }
|
17
|
-
end
|
14
|
+
let(:out_stream) { std_stream }
|
15
|
+
let(:output) { out_stream.read }
|
18
16
|
|
19
17
|
describe "#transmit" do
|
20
18
|
def stub_marker_request
|
21
19
|
stub_api_request config, "markers", marker.marker_data
|
22
20
|
end
|
23
21
|
|
22
|
+
def run
|
23
|
+
capture_stdout(out_stream) { marker.transmit }
|
24
|
+
end
|
25
|
+
|
24
26
|
context "when request is valid" do
|
25
|
-
before
|
26
|
-
stub_marker_request.to_return(:status => 200)
|
27
|
-
marker.transmit
|
28
|
-
end
|
27
|
+
before { stub_marker_request.to_return(:status => 200) }
|
29
28
|
|
30
29
|
it "outputs success" do
|
31
|
-
|
30
|
+
run
|
32
31
|
expect(output).to include \
|
33
32
|
'Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
34
33
|
'AppSignal has been notified of this deploy!'
|
@@ -36,13 +35,10 @@ describe Appsignal::Marker do
|
|
36
35
|
end
|
37
36
|
|
38
37
|
context "when request is invalid" do
|
39
|
-
before
|
40
|
-
stub_marker_request.to_return(:status => 500)
|
41
|
-
marker.transmit
|
42
|
-
end
|
38
|
+
before { stub_marker_request.to_return(:status => 500) }
|
43
39
|
|
44
40
|
it "outputs failure" do
|
45
|
-
|
41
|
+
run
|
46
42
|
expect(output).to include \
|
47
43
|
'Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
48
44
|
"Something went wrong while trying to notify AppSignal: 500 at "\
|