appsignal 0.11.18 → 0.12.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/CHANGELOG.md +4 -38
- data/Rakefile +14 -6
- data/appsignal.gemspec +3 -1
- data/benchmark.rake +12 -16
- data/ext/appsignal_extension.c +183 -0
- data/ext/extconf.rb +39 -0
- data/gemfiles/capistrano2.gemfile +0 -1
- data/gemfiles/capistrano3.gemfile +0 -1
- data/gemfiles/rails-4.2.gemfile +1 -1
- data/lib/appsignal.rb +23 -61
- data/lib/appsignal/capistrano.rb +1 -2
- data/lib/appsignal/config.rb +13 -1
- data/lib/appsignal/event_formatter.rb +67 -0
- data/lib/appsignal/event_formatter/action_view/render_formatter.rb +23 -0
- data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +74 -0
- data/lib/appsignal/event_formatter/moped/query_formatter.rb +80 -0
- data/lib/appsignal/event_formatter/net_http/request_formatter.rb +13 -0
- data/lib/appsignal/instrumentations/net_http.rb +6 -4
- data/lib/appsignal/integrations/resque.rb +2 -10
- data/lib/appsignal/integrations/sidekiq.rb +2 -2
- data/lib/appsignal/integrations/sinatra.rb +1 -0
- data/lib/appsignal/js_exception_transaction.rb +44 -28
- data/lib/appsignal/marker.rb +11 -13
- data/lib/appsignal/params_sanitizer.rb +5 -8
- data/lib/appsignal/rack/instrumentation.rb +2 -0
- data/lib/appsignal/rack/js_exception_catcher.rb +1 -0
- data/lib/appsignal/rack/listener.rb +1 -1
- data/lib/appsignal/rack/sinatra_instrumentation.rb +2 -12
- data/lib/appsignal/subscriber.rb +59 -0
- data/lib/appsignal/transaction.rb +117 -174
- data/lib/appsignal/transmitter.rb +8 -37
- data/lib/appsignal/version.rb +2 -1
- data/spec/lib/appsignal/config_spec.rb +25 -4
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +42 -0
- data/spec/lib/appsignal/{aggregator/middleware/active_record_sanitizer_spec.rb → event_formatter/active_record/sql_formatter_spec.rb} +61 -61
- data/spec/lib/appsignal/{event/moped_event_spec.rb → event_formatter/moped/query_formatter_spec.rb} +32 -78
- data/spec/lib/appsignal/event_formatter/net_http/request_formatter_spec.rb +26 -0
- data/spec/lib/appsignal/event_formatter_spec.rb +102 -0
- data/spec/lib/appsignal/extension_spec.rb +75 -0
- data/spec/lib/appsignal/instrumentations/net_http_spec.rb +20 -4
- data/spec/lib/appsignal/integrations/delayed_job_spec.rb +3 -2
- data/spec/lib/appsignal/integrations/rails_spec.rb +0 -7
- data/spec/lib/appsignal/integrations/resque_spec.rb +51 -55
- data/spec/lib/appsignal/integrations/sequel_spec.rb +8 -3
- data/spec/lib/appsignal/integrations/sidekiq_spec.rb +4 -21
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +0 -6
- data/spec/lib/appsignal/js_exception_transaction_spec.rb +57 -60
- data/spec/lib/appsignal/params_sanitizer_spec.rb +11 -27
- data/spec/lib/appsignal/rack/listener_spec.rb +6 -6
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +2 -43
- data/spec/lib/appsignal/subscriber_spec.rb +162 -0
- data/spec/lib/appsignal/transaction_spec.rb +283 -615
- data/spec/lib/appsignal/transmitter_spec.rb +3 -32
- data/spec/lib/appsignal_spec.rb +41 -90
- data/spec/lib/generators/appsignal/appsignal_generator_spec.rb +0 -17
- data/spec/spec_helper.rb +18 -22
- data/spec/support/helpers/notification_helpers.rb +1 -1
- data/spec/support/helpers/time_helpers.rb +11 -0
- data/spec/support/helpers/transaction_helpers.rb +6 -18
- data/spec/support/project_fixture/config/appsignal.yml +1 -2
- metadata +68 -78
- checksums.yaml +0 -7
- data/gemfiles/padrino-0.13.gemfile +0 -7
- data/gemfiles/resque.gemfile +0 -5
- data/lib/appsignal/agent.rb +0 -217
- data/lib/appsignal/aggregator.rb +0 -67
- data/lib/appsignal/aggregator/middleware.rb +0 -4
- data/lib/appsignal/aggregator/middleware/action_view_sanitizer.rb +0 -23
- data/lib/appsignal/aggregator/middleware/active_record_sanitizer.rb +0 -65
- data/lib/appsignal/aggregator/middleware/chain.rb +0 -101
- data/lib/appsignal/aggregator/middleware/delete_blanks.rb +0 -16
- data/lib/appsignal/aggregator/post_processor.rb +0 -32
- data/lib/appsignal/event.rb +0 -20
- data/lib/appsignal/event/moped_event.rb +0 -90
- data/lib/appsignal/integrations/padrino.rb +0 -64
- data/lib/appsignal/integrations/passenger.rb +0 -13
- data/lib/appsignal/integrations/rake.rb +0 -29
- data/lib/appsignal/integrations/unicorn.rb +0 -25
- data/lib/appsignal/ipc.rb +0 -68
- data/lib/appsignal/transaction/formatter.rb +0 -85
- data/lib/appsignal/transaction/params_sanitizer.rb +0 -4
- data/lib/appsignal/zipped_payload.rb +0 -37
- data/spec/lib/appsignal/agent_spec.rb +0 -592
- data/spec/lib/appsignal/aggregator/middleware/action_view_sanitizer_spec.rb +0 -44
- data/spec/lib/appsignal/aggregator/middleware/chain_spec.rb +0 -168
- data/spec/lib/appsignal/aggregator/middleware/delete_blanks_spec.rb +0 -37
- data/spec/lib/appsignal/aggregator/post_processor_spec.rb +0 -99
- data/spec/lib/appsignal/aggregator_spec.rb +0 -186
- data/spec/lib/appsignal/event_spec.rb +0 -48
- data/spec/lib/appsignal/integrations/padrino_spec.rb +0 -171
- data/spec/lib/appsignal/integrations/passenger_spec.rb +0 -22
- data/spec/lib/appsignal/integrations/rake_spec.rb +0 -92
- data/spec/lib/appsignal/integrations/unicorn_spec.rb +0 -48
- data/spec/lib/appsignal/ipc_spec.rb +0 -128
- data/spec/lib/appsignal/transaction/formatter_spec.rb +0 -247
- data/spec/lib/appsignal/zipped_payload_spec.rb +0 -42
@@ -22,12 +22,6 @@ if defined?(::Sinatra)
|
|
22
22
|
it { should be_a(Appsignal::Config) }
|
23
23
|
end
|
24
24
|
|
25
|
-
context "agent" do
|
26
|
-
subject { Appsignal.agent }
|
27
|
-
|
28
|
-
it { should be_a(Appsignal::Agent) }
|
29
|
-
end
|
30
|
-
|
31
25
|
it "should have added the listener middleware" do
|
32
26
|
Sinatra::Application.middleware.to_a.should include(
|
33
27
|
[Appsignal::Rack::Listener, [], nil]
|
@@ -1,15 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Appsignal::JSExceptionTransaction do
|
4
|
-
|
4
|
+
before { SecureRandom.stub(:uuid => '123abc') }
|
5
|
+
|
6
|
+
let!(:transaction) { Appsignal::JSExceptionTransaction.new(data) }
|
5
7
|
let(:data) do
|
6
8
|
{
|
7
9
|
'name' => 'TypeError',
|
8
10
|
'message' => 'foo is not a valid method',
|
9
11
|
'action' => 'ExceptionIncidentComponent',
|
10
12
|
'path' => 'foo.bar/moo',
|
11
|
-
'environment' =>
|
12
|
-
'tags' => {"intercom_user_id" => "abc123"},
|
13
|
+
'environment' => 'development',
|
13
14
|
'backtrace' => [
|
14
15
|
'foo.bar/js:11:1',
|
15
16
|
'foo.bar/js:22:2',
|
@@ -17,77 +18,73 @@ describe Appsignal::JSExceptionTransaction do
|
|
17
18
|
}
|
18
19
|
end
|
19
20
|
|
20
|
-
describe "#
|
21
|
-
it "should
|
22
|
-
expect(
|
23
|
-
end
|
24
|
-
end
|
21
|
+
describe "#initialize" do
|
22
|
+
it "should call all required methods" do
|
23
|
+
expect( Appsignal::Extension ).to receive(:start_transaction).with('123abc')
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
expect( transaction
|
29
|
-
|
30
|
-
end
|
25
|
+
expect( transaction ).to receive(:set_base_data)
|
26
|
+
expect( transaction ).to receive(:set_metadata)
|
27
|
+
expect( transaction ).to receive(:set_error)
|
28
|
+
expect( transaction ).to receive(:set_error_data)
|
31
29
|
|
32
|
-
|
33
|
-
it "should respond to `clear_events!`" do
|
34
|
-
expect( transaction ).to respond_to :clear_events!
|
30
|
+
transaction.send :initialize, data
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
|
-
describe "#
|
39
|
-
it "should
|
40
|
-
expect(
|
34
|
+
describe "#set_base_data" do
|
35
|
+
it "should call `Appsignal::Extension.set_transaction_basedata`" do
|
36
|
+
expect( Appsignal::Extension ).to receive(:set_transaction_basedata).with(
|
37
|
+
'123abc',
|
38
|
+
'frontend',
|
39
|
+
'ExceptionIncidentComponent',
|
40
|
+
0
|
41
|
+
)
|
42
|
+
|
43
|
+
transaction.set_base_data
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
|
-
describe "#
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
describe "#set_metadata" do
|
48
|
+
it "should call `Appsignal::Extension.set_transaction_metadata`" do
|
49
|
+
expect( Appsignal::Extension ).to receive(:set_transaction_metadata).with(
|
50
|
+
'123abc',
|
51
|
+
'path',
|
52
|
+
'foo.bar/moo'
|
53
|
+
)
|
54
|
+
|
55
|
+
transaction.set_metadata
|
56
|
+
end
|
48
57
|
end
|
49
58
|
|
50
|
-
describe "#
|
51
|
-
|
52
|
-
|
53
|
-
|
59
|
+
describe "#set_error" do
|
60
|
+
it "should call `Appsignal::Extension.set_transaction_error`" do
|
61
|
+
expect( Appsignal::Extension ).to receive(:set_transaction_error).with(
|
62
|
+
'123abc',
|
63
|
+
'TypeError',
|
64
|
+
'foo is not a valid method'
|
65
|
+
)
|
54
66
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
67
|
+
transaction.set_error
|
68
|
+
end
|
69
|
+
end
|
59
70
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
:time => 123,
|
68
|
-
:environment => {"user_agent" => "Mozilla/5.0"},
|
69
|
-
:tags => {"intercom_user_id" => "abc123"},
|
70
|
-
:revision => 'abcdef'
|
71
|
-
},
|
72
|
-
:exception => {
|
73
|
-
:exception => 'TypeError',
|
74
|
-
:message => 'foo is not a valid method',
|
75
|
-
:backtrace => [
|
76
|
-
'foo.bar/js:11:1',
|
77
|
-
'foo.bar/js:22:2',
|
78
|
-
]
|
79
|
-
},
|
80
|
-
:failed => true
|
81
|
-
})
|
82
|
-
end
|
71
|
+
describe "#set_error_data" do
|
72
|
+
it "should call `Appsignal::Extension.set_transaction_error_data`" do
|
73
|
+
expect( Appsignal::Extension ).to receive(:set_transaction_error_data).with(
|
74
|
+
'123abc',
|
75
|
+
'backtrace',
|
76
|
+
'["foo.bar/js:11:1","foo.bar/js:22:2"]'
|
77
|
+
)
|
83
78
|
|
84
|
-
|
85
|
-
|
86
|
-
|
79
|
+
transaction.set_error_data
|
80
|
+
end
|
81
|
+
end
|
87
82
|
|
88
|
-
|
89
|
-
|
83
|
+
describe "#complete!" do
|
84
|
+
it "should call all required methods" do
|
85
|
+
expect( Appsignal::Extension ).to receive(:finish_transaction).with('123abc')
|
86
|
+
transaction.complete!
|
90
87
|
end
|
91
|
-
|
92
88
|
end
|
89
|
+
|
93
90
|
end
|
@@ -6,54 +6,39 @@ class ErrorOnInspect
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
class ClassWithInspect
|
10
|
-
def inspect
|
11
|
-
"#<ClassWithInspect foo=\"bar\"/>"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
9
|
describe Appsignal::ParamsSanitizer do
|
16
10
|
let(:klass) { Appsignal::ParamsSanitizer }
|
17
11
|
let(:file) { uploaded_file }
|
18
12
|
let(:params) do
|
19
13
|
{
|
20
|
-
:text
|
21
|
-
:file
|
22
|
-
:
|
23
|
-
|
24
|
-
:bool_false => false,
|
25
|
-
:int => 1,
|
26
|
-
:hash => {
|
27
|
-
:nested_text => 'string',
|
14
|
+
:text => 'string',
|
15
|
+
:file => file,
|
16
|
+
:hash => {
|
17
|
+
:nested_text => 'string',
|
28
18
|
:nested_array => [
|
29
19
|
'something',
|
30
20
|
'else',
|
31
21
|
file,
|
32
22
|
{
|
33
|
-
:key
|
23
|
+
:key => 'value',
|
34
24
|
:file => file,
|
35
25
|
},
|
36
|
-
ErrorOnInspect.new
|
37
|
-
ClassWithInspect.new
|
26
|
+
ErrorOnInspect.new
|
38
27
|
]
|
39
28
|
}
|
40
29
|
}
|
41
30
|
end
|
42
31
|
let(:sanitized_params) { klass.sanitize(params) }
|
43
|
-
let(:scrubbed_params)
|
32
|
+
let(:scrubbed_params) { klass.scrub(params) }
|
44
33
|
|
45
34
|
describe ".sanitize!" do
|
46
35
|
subject { params }
|
47
36
|
before { klass.sanitize!(subject) }
|
48
37
|
|
49
38
|
it { should be_instance_of Hash }
|
50
|
-
its([:text])
|
51
|
-
its([:file])
|
52
|
-
its([:file])
|
53
|
-
its([:float]) { should == 0.0 }
|
54
|
-
its([:int]) { should == 1 }
|
55
|
-
its([:bool_true]) { should == 'true' }
|
56
|
-
its([:bool_false]) { should == 'false' }
|
39
|
+
its([:text]) { should == 'string' }
|
40
|
+
its([:file]) { should be_instance_of String }
|
41
|
+
its([:file]) { should include '::UploadedFile' }
|
57
42
|
|
58
43
|
context "hash" do
|
59
44
|
subject { params[:hash] }
|
@@ -69,8 +54,7 @@ describe Appsignal::ParamsSanitizer do
|
|
69
54
|
its([1]) { should == 'else' }
|
70
55
|
its([2]) { should be_instance_of String }
|
71
56
|
its([2]) { should include '::UploadedFile' }
|
72
|
-
its([4]) { should == '#<ErrorOnInspect
|
73
|
-
its([5]) { should == '#<ClassWithInspect>' }
|
57
|
+
its([4]) { should == '#<ErrorOnInspect/>' }
|
74
58
|
|
75
59
|
context "nested hash" do
|
76
60
|
subject { params[:hash][:nested_array][3] }
|
@@ -19,7 +19,7 @@ describe Appsignal::Rack::Listener do
|
|
19
19
|
let(:env) { {} }
|
20
20
|
|
21
21
|
describe '#call' do
|
22
|
-
let(:current) { double(:
|
22
|
+
let(:current) { double(:request_id => '1', :set_error => true) }
|
23
23
|
before do
|
24
24
|
middleware.stub(:request_id => '1')
|
25
25
|
Appsignal::Transaction.stub(:current => current)
|
@@ -31,7 +31,7 @@ describe Appsignal::Rack::Listener do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should call complete! after the call' do
|
34
|
-
|
34
|
+
Appsignal::Transaction.should_receive(:complete_current!)
|
35
35
|
end
|
36
36
|
|
37
37
|
context "when not active" do
|
@@ -55,7 +55,7 @@ describe Appsignal::Rack::Listener do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'should catch the exception and notify the transaction of it' do
|
58
|
-
current.should_receive(:
|
58
|
+
current.should_receive(:set_error)
|
59
59
|
middleware.call(env) rescue nil
|
60
60
|
end
|
61
61
|
|
@@ -69,14 +69,14 @@ describe Appsignal::Rack::Listener do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'should ignore the error' do
|
72
|
-
current.should_not_receive(:
|
72
|
+
current.should_not_receive(:set_error)
|
73
73
|
middleware.call(env) rescue nil
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
describe 'after an error' do
|
78
|
-
it 'should call
|
79
|
-
|
78
|
+
it 'should call complete_current! after the call' do
|
79
|
+
Appsignal::Transaction.should_receive(:complete_current!)
|
80
80
|
end
|
81
81
|
|
82
82
|
after { middleware.call(env) rescue nil }
|
@@ -23,34 +23,6 @@ if defined?(::Sinatra)
|
|
23
23
|
let(:middleware) { Appsignal::Rack::SinatraInstrumentation.new(app, {}) }
|
24
24
|
|
25
25
|
describe "#call" do
|
26
|
-
before do
|
27
|
-
middleware.stub(:raw_payload => {})
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when appsignal is active" do
|
31
|
-
before { Appsignal.stub(:active? => true) }
|
32
|
-
|
33
|
-
it "should call with monitoring" do
|
34
|
-
expect( middleware ).to receive(:call_with_appsignal_monitoring).with(env)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "when appsignal is not active" do
|
39
|
-
before { Appsignal.stub(:active? => false) }
|
40
|
-
|
41
|
-
it "should not call with monitoring" do
|
42
|
-
expect( middleware ).to_not receive(:call_with_appsignal_monitoring)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should call the stack" do
|
46
|
-
expect( app ).to receive(:call).with(env)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
after { middleware.call(env) }
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#call_with_appsignal_monitoring" do
|
54
26
|
before do
|
55
27
|
middleware.stub(:raw_payload => {})
|
56
28
|
env['sinatra.route'] = 'GET /'
|
@@ -59,7 +31,7 @@ if defined?(::Sinatra)
|
|
59
31
|
it "should instrument the call" do
|
60
32
|
app.should_receive(:call).with(env)
|
61
33
|
|
62
|
-
middleware.
|
34
|
+
middleware.call(env)
|
63
35
|
|
64
36
|
process_action_event = @events.last
|
65
37
|
process_action_event.name.should == 'process_action.sinatra'
|
@@ -70,26 +42,13 @@ if defined?(::Sinatra)
|
|
70
42
|
app.should_receive(:call).with(env).and_raise('the roof')
|
71
43
|
|
72
44
|
lambda {
|
73
|
-
middleware.
|
45
|
+
middleware.call(env)
|
74
46
|
}.should raise_error
|
75
47
|
|
76
48
|
process_action_event = @events.last
|
77
49
|
process_action_event.name.should == 'process_action.sinatra'
|
78
50
|
process_action_event.payload[:action].should == 'GET /'
|
79
51
|
end
|
80
|
-
|
81
|
-
it "should add exceptions stored in env under sinatra.error" do
|
82
|
-
exception = RuntimeError.new('Raise the roof')
|
83
|
-
env['sinatra.error'] = exception
|
84
|
-
|
85
|
-
transaction = double
|
86
|
-
transaction.stub(:set_process_action_event)
|
87
|
-
transaction.stub(:add_event)
|
88
|
-
Appsignal.should_receive(:add_exception).with(exception)
|
89
|
-
Appsignal::Transaction.stub(:current => transaction)
|
90
|
-
|
91
|
-
middleware.call_with_appsignal_monitoring(env)
|
92
|
-
end
|
93
52
|
end
|
94
53
|
|
95
54
|
describe "raw_payload" do
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Appsignal::Subscriber do
|
4
|
+
before :all do
|
5
|
+
start_agent
|
6
|
+
end
|
7
|
+
|
8
|
+
before do
|
9
|
+
Thread.current[:appsignal_transaction] = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:subscriber) { Appsignal.subscriber }
|
13
|
+
subject { subscriber }
|
14
|
+
|
15
|
+
context "initialization" do
|
16
|
+
it "should be in the subscriber list" do
|
17
|
+
ActiveSupport::Notifications.notifier.instance_variable_get(:@subscribers).select do |s|
|
18
|
+
s.instance_variable_get(:@delegate).is_a?(Appsignal::Subscriber)
|
19
|
+
end.count == 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "subscriptions" do
|
24
|
+
describe "subscribe" do
|
25
|
+
it "should subscribe" do
|
26
|
+
ActiveSupport::Notifications.should_receive(:subscribe).with(/^[^!]/, subject).at_least(:once)
|
27
|
+
|
28
|
+
subject.subscribe
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#unsubscribe" do
|
33
|
+
it "should unsubscribe" do
|
34
|
+
ActiveSupport::Notifications.should_receive(:unsubscribe).with(subject).at_least(:once)
|
35
|
+
|
36
|
+
subject.unsubscribe
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#resubscribe" do
|
41
|
+
it "should unsubscribe and subscribe" do
|
42
|
+
subject.should_receive(:unsubscribe).at_least(:once)
|
43
|
+
subject.should_receive(:subscribe)
|
44
|
+
|
45
|
+
subject.resubscribe
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#publish" do
|
51
|
+
it "should exist" do
|
52
|
+
lambda {
|
53
|
+
subject.publish('name', '')
|
54
|
+
}.should_not raise_error
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "handling events using #start and #finish" do
|
59
|
+
it "should should not listen to events that start with a bang" do
|
60
|
+
subject.should_not_receive(:start)
|
61
|
+
subject.should_not_receive(:finish)
|
62
|
+
|
63
|
+
ActiveSupport::Notifications.instrument '!render_template'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should not record events when there is no current transaction" do
|
67
|
+
Appsignal::Extension.should_not_receive(:start_event)
|
68
|
+
Appsignal::Extension.should_not_receive(:finish_event)
|
69
|
+
|
70
|
+
lambda {
|
71
|
+
ActiveSupport::Notifications.instrument 'something'
|
72
|
+
}.should_not raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with a current transaction" do
|
76
|
+
let(:transaction) { Appsignal::Transaction.current }
|
77
|
+
|
78
|
+
before do
|
79
|
+
Appsignal::Transaction.create('request-id', {})
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should call native start and finish event for every event" do
|
83
|
+
Appsignal::Extension.should_receive(:start_event).exactly(4).times
|
84
|
+
Appsignal::Extension.should_receive(:finish_event).with('request-id', 'one', '', '').once
|
85
|
+
Appsignal::Extension.should_receive(:finish_event).with('request-id', 'two', '', '').once
|
86
|
+
Appsignal::Extension.should_receive(:finish_event).with('request-id', 'two.three', '', '').once
|
87
|
+
Appsignal::Extension.should_receive(:finish_event).with('request-id', 'one.three', '', '').once
|
88
|
+
|
89
|
+
ActiveSupport::Notifications.instrument('one') do
|
90
|
+
ActiveSupport::Notifications.instrument('two') do
|
91
|
+
ActiveSupport::Notifications.instrument('one.three') do
|
92
|
+
end
|
93
|
+
ActiveSupport::Notifications.instrument('two.three') do
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should call finish with title and body if there is a formatter" do
|
100
|
+
Appsignal::Extension.should_receive(:start_event).once
|
101
|
+
Appsignal::Extension.should_receive(:finish_event).with(
|
102
|
+
'request-id',
|
103
|
+
'request.net_http',
|
104
|
+
'GET http://www.google.com',
|
105
|
+
''
|
106
|
+
).once
|
107
|
+
|
108
|
+
ActiveSupport::Notifications.instrument(
|
109
|
+
'request.net_http',
|
110
|
+
:protocol => 'http',
|
111
|
+
:domain => 'www.google.com',
|
112
|
+
:method => 'GET'
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
context "root event" do
|
117
|
+
it "should not set the root event for normal events" do
|
118
|
+
transaction.should_not_receive(:set_root_event)
|
119
|
+
|
120
|
+
ActiveSupport::Notifications.instrument 'something'
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should set the root event when the name starts with process_action" do
|
124
|
+
transaction.respond_to?(:set_root_event).should be_true
|
125
|
+
transaction.should_receive(:set_root_event).with(
|
126
|
+
'process_action.action_controller',
|
127
|
+
:params => {}
|
128
|
+
)
|
129
|
+
|
130
|
+
ActiveSupport::Notifications.instrument 'process_action.action_controller', {:params => {}}
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should set the root event when the name starts with perform_job" do
|
134
|
+
transaction.respond_to?(:set_root_event).should be_true
|
135
|
+
transaction.should_receive(:set_root_event).with(
|
136
|
+
'perform_job.resque',
|
137
|
+
:params => {}
|
138
|
+
)
|
139
|
+
|
140
|
+
ActiveSupport::Notifications.instrument 'perform_job.resque', {:params => {}}
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "when paused" do
|
145
|
+
before { transaction.pause! }
|
146
|
+
|
147
|
+
it "should set a root event, but no other events" do
|
148
|
+
Appsignal::Extension.should_not_receive(:start_event)
|
149
|
+
Appsignal::Extension.should_not_receive(:finish_event)
|
150
|
+
|
151
|
+
transaction.respond_to?(:set_root_event).should be_true
|
152
|
+
transaction.should_receive(:set_root_event).with(
|
153
|
+
'perform_job.resque',
|
154
|
+
:params => {}
|
155
|
+
)
|
156
|
+
|
157
|
+
ActiveSupport::Notifications.instrument 'perform_job.resque', {:params => {}}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|