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
@@ -2,8 +2,8 @@ describe Appsignal::Rack::JSExceptionCatcher do
|
|
2
2
|
let(:app) { double(:call => true) }
|
3
3
|
let(:options) { double }
|
4
4
|
let(:active) { true }
|
5
|
-
let(:config_options) { {:enable_frontend_error_catching => true} }
|
6
|
-
let(:config) { project_fixture_config(
|
5
|
+
let(:config_options) { { :enable_frontend_error_catching => true } }
|
6
|
+
let(:config) { project_fixture_config("production", config_options) }
|
7
7
|
|
8
8
|
before do
|
9
9
|
Appsignal.stub(:config => config)
|
@@ -13,7 +13,7 @@ describe Appsignal::Rack::JSExceptionCatcher do
|
|
13
13
|
describe "#initialize" do
|
14
14
|
it "should log to the logger" do
|
15
15
|
expect(Appsignal.logger).to receive(:debug)
|
16
|
-
.with(
|
16
|
+
.with("Initializing Appsignal::Rack::JSExceptionCatcher")
|
17
17
|
|
18
18
|
Appsignal::Rack::JSExceptionCatcher.new(app, options)
|
19
19
|
end
|
@@ -23,7 +23,7 @@ describe Appsignal::Rack::JSExceptionCatcher do
|
|
23
23
|
let(:catcher) { Appsignal::Rack::JSExceptionCatcher.new(app, options) }
|
24
24
|
|
25
25
|
context "when path is not `/appsignal_error_catcher`" do
|
26
|
-
let(:env) { {
|
26
|
+
let(:env) { { "PATH_INFO" => "/foo" } }
|
27
27
|
|
28
28
|
it "should call the next middleware" do
|
29
29
|
expect(app).to receive(:call).with(env)
|
@@ -34,21 +34,21 @@ describe Appsignal::Rack::JSExceptionCatcher do
|
|
34
34
|
let(:transaction) { double(:complete! => true) }
|
35
35
|
let(:env) do
|
36
36
|
{
|
37
|
-
|
38
|
-
|
37
|
+
"PATH_INFO" => "/appsignal_error_catcher",
|
38
|
+
"rack.input" => double(:read => '{"name": "error"}')
|
39
39
|
}
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should create a JSExceptionTransaction" do
|
43
43
|
expect(Appsignal::JSExceptionTransaction).to receive(:new)
|
44
|
-
.with(
|
44
|
+
.with("name" => "error")
|
45
45
|
.and_return(transaction)
|
46
46
|
|
47
47
|
expect(transaction).to receive(:complete!)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should return 200" do
|
51
|
-
allow(
|
51
|
+
allow(Appsignal::JSExceptionTransaction).to receive(:new)
|
52
52
|
.and_return(transaction)
|
53
53
|
|
54
54
|
expect(catcher.call(env)).to eql([200, {}, []])
|
@@ -57,7 +57,7 @@ describe Appsignal::Rack::JSExceptionCatcher do
|
|
57
57
|
context "when `frontend_error_catching_path` is different" do
|
58
58
|
let(:config_options) do
|
59
59
|
{
|
60
|
-
:frontend_error_catching_path
|
60
|
+
:frontend_error_catching_path => "/foo"
|
61
61
|
}
|
62
62
|
end
|
63
63
|
|
@@ -73,8 +73,8 @@ describe Appsignal::Rack::JSExceptionCatcher do
|
|
73
73
|
context "when `name` is empty" do
|
74
74
|
let(:env) do
|
75
75
|
{
|
76
|
-
|
77
|
-
|
76
|
+
"PATH_INFO" => "/appsignal_error_catcher",
|
77
|
+
"rack.input" => double(:read => '{"name": ""}')
|
78
78
|
}
|
79
79
|
end
|
80
80
|
|
@@ -90,8 +90,8 @@ describe Appsignal::Rack::JSExceptionCatcher do
|
|
90
90
|
context "when `name` doesn't exist" do
|
91
91
|
let(:env) do
|
92
92
|
{
|
93
|
-
|
94
|
-
|
93
|
+
"PATH_INFO" => "/appsignal_error_catcher",
|
94
|
+
"rack.input" => double(:read => '{"foo": ""}')
|
95
95
|
}
|
96
96
|
end
|
97
97
|
|
@@ -9,10 +9,10 @@ if DependencyHelper.rails_present?
|
|
9
9
|
|
10
10
|
let(:app) { double(:call => true) }
|
11
11
|
let(:env) do
|
12
|
-
http_request_env_with_data(
|
13
|
-
request[
|
12
|
+
http_request_env_with_data("action_dispatch.request_id" => "1").tap do |request|
|
13
|
+
request["action_controller.instance"] = double(
|
14
14
|
:class => MockController,
|
15
|
-
:action_name =>
|
15
|
+
:action_name => "index"
|
16
16
|
)
|
17
17
|
end
|
18
18
|
end
|
@@ -27,7 +27,7 @@ if DependencyHelper.rails_present?
|
|
27
27
|
before { Appsignal.stub(:active? => true) }
|
28
28
|
|
29
29
|
it "should call with monitoring" do
|
30
|
-
expect(
|
30
|
+
expect(middleware).to receive(:call_with_appsignal_monitoring).with(env)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,11 +35,11 @@ if DependencyHelper.rails_present?
|
|
35
35
|
before { Appsignal.stub(:active? => false) }
|
36
36
|
|
37
37
|
it "should not call with monitoring" do
|
38
|
-
expect(
|
38
|
+
expect(middleware).to_not receive(:call_with_appsignal_monitoring)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should call the app" do
|
42
|
-
expect(
|
42
|
+
expect(app).to receive(:call).with(env)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -49,10 +49,10 @@ if DependencyHelper.rails_present?
|
|
49
49
|
describe "#call_with_appsignal_monitoring" do
|
50
50
|
it "should create a transaction" do
|
51
51
|
Appsignal::Transaction.should_receive(:create).with(
|
52
|
-
|
52
|
+
"1",
|
53
53
|
Appsignal::Transaction::HTTP_REQUEST,
|
54
54
|
kind_of(ActionDispatch::Request),
|
55
|
-
:params_method
|
55
|
+
:params_method => :filtered_parameters
|
56
56
|
).and_return(
|
57
57
|
double(
|
58
58
|
:set_action => nil,
|
@@ -84,7 +84,7 @@ if DependencyHelper.rails_present?
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should set the action and queue start" do
|
87
|
-
Appsignal::Transaction.any_instance.should_receive(:set_action).with(
|
87
|
+
Appsignal::Transaction.any_instance.should_receive(:set_action).with("MockController#index")
|
88
88
|
Appsignal::Transaction.any_instance.should_receive(:set_http_or_background_queue_start)
|
89
89
|
end
|
90
90
|
|
@@ -95,9 +95,9 @@ if DependencyHelper.rails_present?
|
|
95
95
|
subject { middleware.request_id(env) }
|
96
96
|
|
97
97
|
context "with request id set" do
|
98
|
-
let(:env) { {
|
98
|
+
let(:env) { { "action_dispatch.request_id" => "id" } }
|
99
99
|
|
100
|
-
it { should eq
|
100
|
+
it { should eq "id" }
|
101
101
|
end
|
102
102
|
|
103
103
|
context "with request id not set" do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
if DependencyHelper.sinatra_present?
|
2
|
-
require
|
2
|
+
require "appsignal/integrations/sinatra"
|
3
3
|
|
4
4
|
describe Appsignal::Rack::SinatraInstrumentation do
|
5
5
|
let(:settings) { double(:raise_errors => false) }
|
6
6
|
let(:app) { double(:call => true, :settings => settings) }
|
7
|
-
let(:env) { {
|
7
|
+
let(:env) { { "sinatra.route" => "GET /", :path => "/", :method => "GET" } }
|
8
8
|
let(:middleware) { Appsignal::Rack::SinatraInstrumentation.new(app) }
|
9
9
|
|
10
10
|
describe "#call" do
|
@@ -37,7 +37,7 @@ if DependencyHelper.sinatra_present?
|
|
37
37
|
|
38
38
|
let(:settings) { double(:raise_errors => false) }
|
39
39
|
let(:app) { double(:call => true, :settings => settings) }
|
40
|
-
let(:env) { {
|
40
|
+
let(:env) { { "sinatra.route" => "GET /", :path => "/", :method => "GET" } }
|
41
41
|
let(:options) { {} }
|
42
42
|
let(:middleware) { Appsignal::Rack::SinatraBaseInstrumentation.new(app, options) }
|
43
43
|
|
@@ -46,7 +46,7 @@ if DependencyHelper.sinatra_present?
|
|
46
46
|
let(:app) { double(:call => true) }
|
47
47
|
|
48
48
|
it "should not raise errors" do
|
49
|
-
expect(
|
49
|
+
expect(middleware.raise_errors_on).to be(false)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -54,7 +54,7 @@ if DependencyHelper.sinatra_present?
|
|
54
54
|
let(:app) { double(:call => true, :settings => double) }
|
55
55
|
|
56
56
|
it "should not raise errors" do
|
57
|
-
expect(
|
57
|
+
expect(middleware.raise_errors_on).to be(false)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,7 +62,7 @@ if DependencyHelper.sinatra_present?
|
|
62
62
|
let(:app) { double(:call => true, :settings => double(:raise_errors => false)) }
|
63
63
|
|
64
64
|
it "should raise errors" do
|
65
|
-
expect(
|
65
|
+
expect(middleware.raise_errors_on).to be(false)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -70,7 +70,7 @@ if DependencyHelper.sinatra_present?
|
|
70
70
|
let(:app) { double(:call => true, :settings => double(:raise_errors => true)) }
|
71
71
|
|
72
72
|
it "should raise errors" do
|
73
|
-
expect(
|
73
|
+
expect(middleware.raise_errors_on).to be(true)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -84,7 +84,7 @@ if DependencyHelper.sinatra_present?
|
|
84
84
|
before { Appsignal.stub(:active? => true) }
|
85
85
|
|
86
86
|
it "should call with monitoring" do
|
87
|
-
expect(
|
87
|
+
expect(middleware).to receive(:call_with_appsignal_monitoring).with(env)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -92,11 +92,11 @@ if DependencyHelper.sinatra_present?
|
|
92
92
|
before { Appsignal.stub(:active? => false) }
|
93
93
|
|
94
94
|
it "should not call with monitoring" do
|
95
|
-
expect(
|
95
|
+
expect(middleware).to_not receive(:call_with_appsignal_monitoring)
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should call the stack" do
|
99
|
-
expect(
|
99
|
+
expect(app).to receive(:call).with(env)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -133,7 +133,7 @@ if DependencyHelper.sinatra_present?
|
|
133
133
|
|
134
134
|
context "with an error in sinatra.error" do
|
135
135
|
let(:error) { VerySpecificError.new }
|
136
|
-
let(:env) { {
|
136
|
+
let(:env) { { "sinatra.error" => error } }
|
137
137
|
|
138
138
|
it "should set the error" do
|
139
139
|
Appsignal::Transaction.any_instance.should_receive(:set_error).with(error)
|
@@ -148,7 +148,7 @@ if DependencyHelper.sinatra_present?
|
|
148
148
|
end
|
149
149
|
|
150
150
|
context "if sinatra.skip_appsignal_error is set" do
|
151
|
-
let(:env) { {
|
151
|
+
let(:env) { { "sinatra.error" => error, "sinatra.skip_appsignal_error" => true } }
|
152
152
|
|
153
153
|
it "should not set the error" do
|
154
154
|
Appsignal::Transaction.any_instance.should_not_receive(:set_error)
|
@@ -158,11 +158,11 @@ if DependencyHelper.sinatra_present?
|
|
158
158
|
|
159
159
|
describe "action name" do
|
160
160
|
it "should set the action" do
|
161
|
-
Appsignal::Transaction.any_instance.should_receive(:set_action).with(
|
161
|
+
Appsignal::Transaction.any_instance.should_receive(:set_action).with("GET /")
|
162
162
|
end
|
163
163
|
|
164
164
|
context "without 'sinatra.route' env" do
|
165
|
-
let(:env) { {:path =>
|
165
|
+
let(:env) { { :path => "/", :method => "GET" } }
|
166
166
|
|
167
167
|
it "returns nil" do
|
168
168
|
Appsignal::Transaction.any_instance.should_receive(:set_action).with(nil)
|
@@ -170,14 +170,14 @@ if DependencyHelper.sinatra_present?
|
|
170
170
|
end
|
171
171
|
|
172
172
|
context "with mounted modular application" do
|
173
|
-
before { env[
|
173
|
+
before { env["SCRIPT_NAME"] = "/api" }
|
174
174
|
|
175
175
|
it "should call set_action with an application prefix path" do
|
176
176
|
Appsignal::Transaction.any_instance.should_receive(:set_action).with("GET /api/")
|
177
177
|
end
|
178
178
|
|
179
179
|
context "without 'sinatra.route' env" do
|
180
|
-
let(:env) { {:path =>
|
180
|
+
let(:env) { { :path => "/", :method => "GET" } }
|
181
181
|
|
182
182
|
it "returns nil" do
|
183
183
|
Appsignal::Transaction.any_instance.should_receive(:set_action).with(nil)
|
@@ -195,14 +195,14 @@ if DependencyHelper.sinatra_present?
|
|
195
195
|
end
|
196
196
|
|
197
197
|
context "with overridden request class and params method" do
|
198
|
-
let(:options) { {:request_class => ::Rack::Request, :params_method => :filtered_params} }
|
198
|
+
let(:options) { { :request_class => ::Rack::Request, :params_method => :filtered_params } }
|
199
199
|
|
200
200
|
it "should use the overridden request class and params method" do
|
201
201
|
request = ::Rack::Request.new(env)
|
202
|
-
::Rack::Request.should_receive(:new)
|
203
|
-
|
204
|
-
|
205
|
-
|
202
|
+
::Rack::Request.should_receive(:new)
|
203
|
+
.with(env.merge(:params_method => :filtered_params))
|
204
|
+
.at_least(:once)
|
205
|
+
.and_return(request)
|
206
206
|
end
|
207
207
|
end
|
208
208
|
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require "appsignal/rack/streaming_listener"
|
2
2
|
|
3
3
|
describe Appsignal::Rack::StreamingListener do
|
4
|
-
let(:headers)
|
4
|
+
let(:headers) { {} }
|
5
5
|
let(:env) do
|
6
6
|
{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
"rack.input" => StringIO.new,
|
8
|
+
"REQUEST_METHOD" => "GET",
|
9
|
+
"PATH_INFO" => "/homepage",
|
10
|
+
"QUERY_STRING" => "param=something"
|
11
11
|
}
|
12
12
|
end
|
13
|
-
let(:app) { double(:call => [200, headers,
|
13
|
+
let(:app) { double(:call => [200, headers, "body"]) }
|
14
14
|
let(:listener) { Appsignal::Rack::StreamingListener.new(app, {}) }
|
15
15
|
|
16
16
|
describe "#call" do
|
@@ -18,7 +18,7 @@ describe Appsignal::Rack::StreamingListener do
|
|
18
18
|
before { Appsignal.stub(:active? => true) }
|
19
19
|
|
20
20
|
it "should call `call_with_appsignal_monitoring`" do
|
21
|
-
expect(
|
21
|
+
expect(listener).to receive(:call_with_appsignal_monitoring)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -26,7 +26,7 @@ describe Appsignal::Rack::StreamingListener do
|
|
26
26
|
before { Appsignal.stub(:active? => false) }
|
27
27
|
|
28
28
|
it "should not call `call_with_appsignal_monitoring`" do
|
29
|
-
expect(
|
29
|
+
expect(listener).to_not receive(:call_with_appsignal_monitoring)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -41,69 +41,69 @@ describe Appsignal::Rack::StreamingListener do
|
|
41
41
|
::Rack::Request.new(env)
|
42
42
|
)
|
43
43
|
end
|
44
|
-
let(:wrapper) { Appsignal::StreamWrapper.new(
|
45
|
-
let(:raw_payload) { {:foo => :bar} }
|
44
|
+
let(:wrapper) { Appsignal::StreamWrapper.new("body", transaction) }
|
45
|
+
let(:raw_payload) { { :foo => :bar } }
|
46
46
|
|
47
47
|
before do
|
48
|
-
SecureRandom.stub(:uuid =>
|
48
|
+
SecureRandom.stub(:uuid => "123")
|
49
49
|
listener.stub(:raw_payload => raw_payload)
|
50
50
|
Appsignal::Transaction.stub(:create => transaction)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should create a transaction" do
|
54
|
-
expect(
|
55
|
-
.with(
|
54
|
+
expect(Appsignal::Transaction).to receive(:create)
|
55
|
+
.with("123", Appsignal::Transaction::HTTP_REQUEST, instance_of(Rack::Request))
|
56
56
|
.and_return(transaction)
|
57
57
|
|
58
58
|
listener.call_with_appsignal_monitoring(env)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should instrument the call" do
|
62
|
-
expect(
|
63
|
-
.with(
|
62
|
+
expect(Appsignal).to receive(:instrument)
|
63
|
+
.with("process_action.rack")
|
64
64
|
.and_yield
|
65
65
|
|
66
66
|
listener.call_with_appsignal_monitoring(env)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should add `appsignal.action` to the transaction" do
|
70
|
-
allow(
|
70
|
+
allow(Appsignal).to receive(:instrument).and_yield
|
71
71
|
|
72
|
-
env[
|
72
|
+
env["appsignal.action"] = "Action"
|
73
73
|
|
74
|
-
expect(
|
74
|
+
expect(transaction).to receive(:set_action).with("Action")
|
75
75
|
|
76
76
|
listener.call_with_appsignal_monitoring(env)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should add the path, method and queue start to the transaction" do
|
80
|
-
allow(
|
80
|
+
allow(Appsignal).to receive(:instrument).and_yield
|
81
81
|
|
82
|
-
expect(
|
83
|
-
expect(
|
84
|
-
expect(
|
82
|
+
expect(transaction).to receive(:set_metadata).with("path", "/homepage")
|
83
|
+
expect(transaction).to receive(:set_metadata).with("method", "GET")
|
84
|
+
expect(transaction).to receive(:set_http_or_background_queue_start)
|
85
85
|
|
86
86
|
listener.call_with_appsignal_monitoring(env)
|
87
87
|
end
|
88
88
|
|
89
89
|
context "with an exception in the instrumentation call" do
|
90
90
|
it "should add the exception to the transaction" do
|
91
|
-
allow(
|
91
|
+
allow(app).to receive(:call).and_raise(VerySpecificError.new)
|
92
92
|
|
93
|
-
expect(
|
93
|
+
expect(transaction).to receive(:set_error)
|
94
94
|
|
95
95
|
listener.call_with_appsignal_monitoring(env) rescue VerySpecificError
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should wrap the body in a wrapper" do
|
100
|
-
expect(
|
101
|
-
.with(
|
100
|
+
expect(Appsignal::StreamWrapper).to receive(:new)
|
101
|
+
.with("body", transaction)
|
102
102
|
.and_return(wrapper)
|
103
103
|
|
104
104
|
body = listener.call_with_appsignal_monitoring(env)[2]
|
105
105
|
|
106
|
-
expect(
|
106
|
+
expect(body).to be_a(Appsignal::StreamWrapper)
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -115,17 +115,17 @@ describe Appsignal::StreamWrapper do
|
|
115
115
|
|
116
116
|
describe "#each" do
|
117
117
|
it "should call the original stream" do
|
118
|
-
expect(
|
118
|
+
expect(stream).to receive(:each)
|
119
119
|
|
120
120
|
wrapper.each
|
121
121
|
end
|
122
122
|
|
123
123
|
context "when each raises an error" do
|
124
124
|
it "should add the exception to the transaction" do
|
125
|
-
allow(
|
125
|
+
allow(stream).to receive(:each)
|
126
126
|
.and_raise(VerySpecificError.new)
|
127
127
|
|
128
|
-
expect(
|
128
|
+
expect(transaction).to receive(:set_error)
|
129
129
|
|
130
130
|
wrapper.send(:each) rescue VerySpecificError
|
131
131
|
end
|
@@ -134,19 +134,19 @@ describe Appsignal::StreamWrapper do
|
|
134
134
|
|
135
135
|
describe "#close" do
|
136
136
|
it "should call the original stream and close the transaction" do
|
137
|
-
expect(
|
138
|
-
expect(
|
137
|
+
expect(stream).to receive(:close)
|
138
|
+
expect(Appsignal::Transaction).to receive(:complete_current!)
|
139
139
|
|
140
140
|
wrapper.close
|
141
141
|
end
|
142
142
|
|
143
143
|
context "when each raises an error" do
|
144
144
|
it "should add the exception to the transaction and close it" do
|
145
|
-
allow(
|
145
|
+
allow(stream).to receive(:close)
|
146
146
|
.and_raise(VerySpecificError.new)
|
147
147
|
|
148
|
-
expect(
|
149
|
-
expect(
|
148
|
+
expect(transaction).to receive(:set_error)
|
149
|
+
expect(Appsignal::Transaction).to receive(:complete_current!)
|
150
150
|
|
151
151
|
wrapper.send(:close) rescue VerySpecificError
|
152
152
|
end
|