appsignal 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/lib/appsignal_spec.rb
CHANGED
@@ -44,7 +44,9 @@ describe Appsignal do
|
|
44
44
|
it "should create a config from the env" do
|
45
45
|
ENV['APPSIGNAL_PUSH_API_KEY'] = 'something'
|
46
46
|
Appsignal::Extension.should_receive(:start)
|
47
|
-
Appsignal.
|
47
|
+
expect(Appsignal.logger).not_to receive(:error)
|
48
|
+
silence { Appsignal.start }
|
49
|
+
expect(Appsignal.config[:push_api_key]).to eq('something')
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
@@ -551,7 +553,8 @@ describe Appsignal do
|
|
551
553
|
end
|
552
554
|
|
553
555
|
describe ".start_logger" do
|
554
|
-
let(:out_stream) {
|
556
|
+
let(:out_stream) { std_stream }
|
557
|
+
let(:output) { out_stream.read }
|
555
558
|
let(:log_path) { File.join(tmp_dir, 'log') }
|
556
559
|
let(:log_file) { File.join(log_path, 'appsignal.log') }
|
557
560
|
|
@@ -564,28 +567,28 @@ describe Appsignal do
|
|
564
567
|
:log_path => log_path
|
565
568
|
)
|
566
569
|
end
|
567
|
-
around
|
568
|
-
recognize_as_container(:none) do
|
569
|
-
capture_stdout(out_stream) { example.run }
|
570
|
-
end
|
571
|
-
end
|
570
|
+
around { |example| recognize_as_container(:none) { example.run } }
|
572
571
|
after { FileUtils.rm_rf(log_path) }
|
573
572
|
|
574
573
|
context "when the log path is writable" do
|
575
574
|
context "when the log file is writable" do
|
576
575
|
let(:log_file_contents) { File.open(log_file).read }
|
576
|
+
|
577
577
|
before do
|
578
|
-
|
579
|
-
|
578
|
+
capture_stdout(out_stream) do
|
579
|
+
Appsignal.start_logger
|
580
|
+
Appsignal.logger.error('Log to file')
|
581
|
+
end
|
580
582
|
end
|
581
583
|
|
582
584
|
it "logs to file" do
|
583
585
|
expect(File.exist?(log_file)).to be_true
|
584
|
-
expect(log_file_contents).to include 'Log to file'
|
586
|
+
expect(log_file_contents).to include '[ERROR] Log to file'
|
587
|
+
expect(output).to be_empty
|
585
588
|
end
|
586
589
|
|
587
590
|
it "amends in memory log to log file" do
|
588
|
-
expect(log_file_contents).to include 'Log in memory'
|
591
|
+
expect(log_file_contents).to include '[ERROR] appsignal: Log in memory'
|
589
592
|
end
|
590
593
|
end
|
591
594
|
|
@@ -594,46 +597,54 @@ describe Appsignal do
|
|
594
597
|
FileUtils.touch log_file
|
595
598
|
FileUtils.chmod 0444, log_file
|
596
599
|
|
597
|
-
|
598
|
-
|
600
|
+
capture_stdout(out_stream) do
|
601
|
+
Appsignal.start_logger
|
602
|
+
Appsignal.logger.error('Log to not writable log file')
|
603
|
+
end
|
599
604
|
end
|
600
605
|
|
601
606
|
it "logs to stdout" do
|
602
607
|
expect(File.writable?(log_file)).to be_false
|
603
|
-
expect(
|
608
|
+
expect(output).to include '[ERROR] appsignal: Log to not writable log file'
|
604
609
|
end
|
605
610
|
|
606
611
|
it "amends in memory log to stdout" do
|
607
|
-
expect(
|
612
|
+
expect(output).to include '[ERROR] appsignal: Log in memory'
|
608
613
|
end
|
609
614
|
|
610
615
|
it "outputs a warning" do
|
611
|
-
expect(
|
612
|
-
"appsignal: Unable to start logger with log path '#{log_file}'.",
|
613
|
-
"appsignal: Permission denied"
|
616
|
+
expect(output).to include \
|
617
|
+
"[WARN] appsignal: Unable to start logger with log path '#{log_file}'.",
|
618
|
+
"[WARN] appsignal: Permission denied"
|
614
619
|
end
|
615
620
|
end
|
616
621
|
end
|
617
622
|
|
618
|
-
context "when the log path
|
623
|
+
context "when the log path and fallback path are not writable" do
|
619
624
|
before do
|
620
625
|
FileUtils.chmod 0444, log_path
|
626
|
+
FileUtils.chmod 0444, Appsignal::Config::SYSTEM_TMP_DIR
|
621
627
|
|
622
|
-
|
623
|
-
|
628
|
+
capture_stdout(out_stream) do
|
629
|
+
Appsignal.start_logger
|
630
|
+
Appsignal.logger.error('Log to not writable log path')
|
631
|
+
end
|
632
|
+
end
|
633
|
+
after do
|
634
|
+
FileUtils.chmod 0755, Appsignal::Config::SYSTEM_TMP_DIR
|
624
635
|
end
|
625
636
|
|
626
637
|
it "logs to stdout" do
|
627
638
|
expect(File.writable?(log_path)).to be_false
|
628
|
-
expect(
|
639
|
+
expect(output).to include '[ERROR] appsignal: Log to not writable log path'
|
629
640
|
end
|
630
641
|
|
631
642
|
it "amends in memory log to stdout" do
|
632
|
-
expect(
|
643
|
+
expect(output).to include '[ERROR] appsignal: Log in memory'
|
633
644
|
end
|
634
645
|
|
635
646
|
it "outputs a warning" do
|
636
|
-
expect(
|
647
|
+
expect(output).to include \
|
637
648
|
"appsignal: Unable to log to '#{log_path}' "\
|
638
649
|
"or the '#{Appsignal::Config::SYSTEM_TMP_DIR}' fallback."
|
639
650
|
end
|
@@ -641,17 +652,19 @@ describe Appsignal do
|
|
641
652
|
|
642
653
|
context "when on Heroku" do
|
643
654
|
before do
|
644
|
-
|
645
|
-
|
655
|
+
capture_stdout(out_stream) do
|
656
|
+
Appsignal.start_logger
|
657
|
+
Appsignal.logger.error('Log to stdout')
|
658
|
+
end
|
646
659
|
end
|
647
660
|
around { |example| recognize_as_heroku { example.run } }
|
648
661
|
|
649
662
|
it "logs to stdout" do
|
650
|
-
expect(
|
663
|
+
expect(output).to include '[ERROR] appsignal: Log to stdout'
|
651
664
|
end
|
652
665
|
|
653
666
|
it "amends in memory log to stdout" do
|
654
|
-
expect(
|
667
|
+
expect(output).to include '[ERROR] appsignal: Log in memory'
|
655
668
|
end
|
656
669
|
end
|
657
670
|
|
@@ -661,7 +674,9 @@ describe Appsignal do
|
|
661
674
|
context "when there is no config" do
|
662
675
|
before do
|
663
676
|
Appsignal.config = nil
|
664
|
-
|
677
|
+
capture_stdout(out_stream) do
|
678
|
+
Appsignal.start_logger
|
679
|
+
end
|
665
680
|
end
|
666
681
|
|
667
682
|
it "sets the log level to info" do
|
@@ -673,7 +688,9 @@ describe Appsignal do
|
|
673
688
|
context "when log level is configured to debug" do
|
674
689
|
before do
|
675
690
|
Appsignal.config.config_hash[:debug] = true
|
676
|
-
|
691
|
+
capture_stdout(out_stream) do
|
692
|
+
Appsignal.start_logger
|
693
|
+
end
|
677
694
|
end
|
678
695
|
|
679
696
|
it "sets the log level to debug" do
|
@@ -685,11 +702,21 @@ describe Appsignal do
|
|
685
702
|
end
|
686
703
|
|
687
704
|
describe ".log_formatter" do
|
688
|
-
subject { Appsignal.log_formatter }
|
705
|
+
subject { Appsignal.log_formatter.call('Debug', Time.parse('2015-07-08'), nil, 'log line') }
|
706
|
+
|
707
|
+
it "formats a log" do
|
708
|
+
expect(subject).to eq "[2015-07-08T00:00:00 (process) ##{Process.pid}][Debug] log line\n"
|
709
|
+
end
|
710
|
+
|
711
|
+
context "with prefix" do
|
712
|
+
subject do
|
713
|
+
Appsignal.log_formatter("prefix").call('Debug', Time.parse('2015-07-08'), nil, 'log line')
|
714
|
+
end
|
689
715
|
|
690
|
-
|
691
|
-
|
692
|
-
|
716
|
+
it "adds a prefix" do
|
717
|
+
expect(subject)
|
718
|
+
.to eq "[2015-07-08T00:00:00 (process) ##{Process.pid}][Debug] prefix: log line\n"
|
719
|
+
end
|
693
720
|
end
|
694
721
|
end
|
695
722
|
|
@@ -792,40 +819,36 @@ describe Appsignal do
|
|
792
819
|
end
|
793
820
|
|
794
821
|
describe ".instrument" do
|
795
|
-
|
796
|
-
|
797
|
-
|
822
|
+
before do
|
823
|
+
expect(Appsignal::Transaction).to receive(:current).at_least(:once).and_return(transaction)
|
824
|
+
end
|
798
825
|
|
799
|
-
|
800
|
-
transaction.
|
801
|
-
|
802
|
-
'title',
|
803
|
-
'body',
|
804
|
-
0
|
805
|
-
)
|
826
|
+
it "should instrument through the transaction" do
|
827
|
+
expect(transaction).to receive(:start_event)
|
828
|
+
expect(transaction).to receive(:finish_event)
|
829
|
+
.with('name', 'title', 'body', Appsignal::EventFormatter::DEFAULT)
|
806
830
|
|
807
|
-
Appsignal.instrument 'name', 'title', 'body' do
|
808
|
-
|
809
|
-
end
|
831
|
+
result = Appsignal.instrument 'name', 'title', 'body' do
|
832
|
+
'return value'
|
833
|
+
end
|
834
|
+
expect(result).to eq 'return value'
|
810
835
|
end
|
811
836
|
end
|
812
837
|
|
813
838
|
describe ".instrument_sql" do
|
814
|
-
|
815
|
-
|
816
|
-
|
839
|
+
before do
|
840
|
+
expect(Appsignal::Transaction).to receive(:current).at_least(:once).and_return(transaction)
|
841
|
+
end
|
817
842
|
|
818
|
-
|
819
|
-
transaction.
|
820
|
-
|
821
|
-
'title',
|
822
|
-
'body',
|
823
|
-
1
|
824
|
-
)
|
843
|
+
it "should instrument sql through the transaction" do
|
844
|
+
expect(transaction).to receive(:start_event)
|
845
|
+
expect(transaction).to receive(:finish_event)
|
846
|
+
.with('name', 'title', 'body', Appsignal::EventFormatter::SQL_BODY_FORMAT)
|
825
847
|
|
826
|
-
Appsignal.instrument_sql 'name', 'title', 'body' do
|
827
|
-
|
828
|
-
end
|
848
|
+
result = Appsignal.instrument_sql 'name', 'title', 'body' do
|
849
|
+
'return value'
|
850
|
+
end
|
851
|
+
expect(result).to eq 'return value'
|
829
852
|
end
|
830
853
|
end
|
831
854
|
|
data/spec/spec_helper.rb
CHANGED
@@ -48,22 +48,23 @@ RSpec.configure do |config|
|
|
48
48
|
config.extend DependencyHelper
|
49
49
|
|
50
50
|
config.before :all do
|
51
|
-
|
52
|
-
FileUtils.mkdir_p(tmp_dir)
|
53
|
-
|
54
|
-
# Use modifiable SYSTEM_TMP_DIR
|
51
|
+
# Use modified SYSTEM_TMP_DIR
|
55
52
|
Appsignal::Config.send :remove_const, :SYSTEM_TMP_DIR
|
56
53
|
Appsignal::Config.send :const_set, :SYSTEM_TMP_DIR,
|
57
54
|
File.join(tmp_dir, 'system-tmp')
|
55
|
+
|
56
|
+
FileUtils.rm_rf(tmp_dir)
|
57
|
+
FileUtils.mkdir_p(Appsignal::Config::SYSTEM_TMP_DIR)
|
58
58
|
end
|
59
59
|
|
60
60
|
config.before do
|
61
|
-
ENV['RAILS_ENV']
|
62
|
-
ENV['
|
61
|
+
ENV['RAILS_ENV'] ||= 'test'
|
62
|
+
ENV['RACK_ENV'] ||= 'test'
|
63
|
+
ENV['PADRINO_ENV'] ||= 'test'
|
63
64
|
|
64
65
|
# Clean environment
|
65
66
|
ENV.keys.select { |key| key.start_with?('APPSIGNAL_') }.each do |key|
|
66
|
-
ENV
|
67
|
+
ENV.delete(key)
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
@@ -1,35 +1,66 @@
|
|
1
1
|
module StdStreamsHelper
|
2
|
+
def std_stream
|
3
|
+
Tempfile.new SecureRandom.uuid
|
4
|
+
end
|
5
|
+
|
2
6
|
# Capture STDOUT in a variable
|
3
7
|
#
|
8
|
+
# Given tempfiles are rewinded and unlinked after yield, so no cleanup
|
9
|
+
# required. You can read from the stream using `stdout.read`.
|
10
|
+
#
|
4
11
|
# Usage
|
5
12
|
#
|
6
|
-
# out_stream =
|
13
|
+
# out_stream = Tempfile.new
|
7
14
|
# capture_stdout(out_stream) { do_something }
|
8
15
|
def capture_stdout(stdout)
|
9
|
-
original_stdout = $stdout
|
10
|
-
$stdout
|
16
|
+
original_stdout = $stdout.dup
|
17
|
+
$stdout.reopen stdout
|
11
18
|
|
12
19
|
yield
|
13
|
-
|
14
|
-
$stdout
|
20
|
+
ensure
|
21
|
+
$stdout.reopen original_stdout
|
22
|
+
stdout.rewind
|
23
|
+
stdout.unlink
|
15
24
|
end
|
16
25
|
|
17
26
|
# Capture STDOUT and STDERR in variables
|
18
27
|
#
|
28
|
+
# Given tempfiles are rewinded and unlinked after yield, so no cleanup
|
29
|
+
# required. You can read from the stream using `stdout.read`.
|
30
|
+
#
|
19
31
|
# Usage
|
20
32
|
#
|
21
|
-
# out_stream =
|
22
|
-
# err_stream =
|
33
|
+
# out_stream = Tempfile.new
|
34
|
+
# err_stream = Tempfile.new
|
23
35
|
# capture_std_streams(out_stream, err_stream) { do_something }
|
24
36
|
def capture_std_streams(stdout, stderr)
|
25
|
-
original_stdout = $stdout
|
26
|
-
$stdout
|
27
|
-
original_stderr = $stderr
|
28
|
-
$stderr
|
37
|
+
original_stdout = $stdout.dup
|
38
|
+
$stdout.reopen stdout
|
39
|
+
original_stderr = $stderr.dup
|
40
|
+
$stderr.reopen stderr
|
29
41
|
|
30
42
|
yield
|
43
|
+
ensure
|
44
|
+
$stdout.reopen original_stdout
|
45
|
+
$stderr.reopen original_stderr
|
46
|
+
stdout.rewind
|
47
|
+
stdout.unlink
|
48
|
+
stderr.rewind
|
49
|
+
stderr.unlink
|
50
|
+
end
|
31
51
|
|
32
|
-
|
33
|
-
|
52
|
+
def silence
|
53
|
+
std_stream = Tempfile.new(SecureRandom.uuid)
|
54
|
+
original_stdout = $stdout.dup
|
55
|
+
original_stderr = $stderr.dup
|
56
|
+
$stdout.reopen std_stream
|
57
|
+
$stderr.reopen std_stream
|
58
|
+
|
59
|
+
yield
|
60
|
+
ensure
|
61
|
+
$stdout.reopen original_stdout
|
62
|
+
$stderr.reopen original_stderr
|
63
|
+
std_stream.rewind
|
64
|
+
std_stream.unlink
|
34
65
|
end
|
35
66
|
end
|
@@ -8,7 +8,7 @@ module TransactionHelpers
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def background_job_transaction(args={})
|
11
|
-
Appsignal::Transaction.
|
11
|
+
Appsignal::Transaction.new(
|
12
12
|
'1',
|
13
13
|
Appsignal::Transaction::BACKGROUND_JOB,
|
14
14
|
Appsignal::Transaction::GenericRequest.new({
|
@@ -19,7 +19,7 @@ module TransactionHelpers
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def http_request_transaction(args={})
|
22
|
-
Appsignal::Transaction.
|
22
|
+
Appsignal::Transaction.new(
|
23
23
|
'1',
|
24
24
|
Appsignal::Transaction::HTTP_REQUEST,
|
25
25
|
Appsignal::Transaction::GenericRequest.new({
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appsignal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Beekman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -43,16 +43,16 @@ dependencies:
|
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '11'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '11'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -153,6 +153,7 @@ files:
|
|
153
153
|
- lib/appsignal/cli.rb
|
154
154
|
- lib/appsignal/cli/demo.rb
|
155
155
|
- lib/appsignal/cli/diagnose.rb
|
156
|
+
- lib/appsignal/cli/helpers.rb
|
156
157
|
- lib/appsignal/cli/install.rb
|
157
158
|
- lib/appsignal/cli/notify_of_deploy.rb
|
158
159
|
- lib/appsignal/config.rb
|
@@ -220,6 +221,7 @@ files:
|
|
220
221
|
- spec/lib/appsignal/capistrano3_spec.rb
|
221
222
|
- spec/lib/appsignal/cli/demo_spec.rb
|
222
223
|
- spec/lib/appsignal/cli/diagnose_spec.rb
|
224
|
+
- spec/lib/appsignal/cli/helpers_spec.rb
|
223
225
|
- spec/lib/appsignal/cli/install_spec.rb
|
224
226
|
- spec/lib/appsignal/cli/notify_of_deploy_spec.rb
|
225
227
|
- spec/lib/appsignal/cli_spec.rb
|
@@ -340,6 +342,7 @@ test_files:
|
|
340
342
|
- spec/lib/appsignal/capistrano3_spec.rb
|
341
343
|
- spec/lib/appsignal/cli/demo_spec.rb
|
342
344
|
- spec/lib/appsignal/cli/diagnose_spec.rb
|
345
|
+
- spec/lib/appsignal/cli/helpers_spec.rb
|
343
346
|
- spec/lib/appsignal/cli/install_spec.rb
|
344
347
|
- spec/lib/appsignal/cli/notify_of_deploy_spec.rb
|
345
348
|
- spec/lib/appsignal/cli_spec.rb
|