appsignal 2.1.0.beta.1 → 2.1.0
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/.rspec +2 -1
- data/CHANGELOG.md +5 -0
- data/README.md +14 -15
- data/appsignal.gemspec +1 -1
- data/lib/appsignal.rb +1 -1
- data/lib/appsignal/auth_check.rb +5 -2
- data/lib/appsignal/cli/demo.rb +1 -1
- data/lib/appsignal/cli/diagnose.rb +1 -1
- data/lib/appsignal/cli/install.rb +1 -1
- data/lib/appsignal/transaction.rb +2 -1
- data/lib/appsignal/version.rb +1 -1
- data/spec/lib/appsignal/auth_check_spec.rb +9 -10
- data/spec/lib/appsignal/capistrano2_spec.rb +6 -6
- data/spec/lib/appsignal/capistrano3_spec.rb +6 -6
- data/spec/lib/appsignal/cli/demo_spec.rb +1 -1
- data/spec/lib/appsignal/cli/diagnose_spec.rb +1 -1
- data/spec/lib/appsignal/cli/helpers_spec.rb +2 -2
- data/spec/lib/appsignal/cli/install_spec.rb +2 -2
- data/spec/lib/appsignal/cli_spec.rb +2 -2
- data/spec/lib/appsignal/config_spec.rb +24 -24
- data/spec/lib/appsignal/demo_spec.rb +4 -2
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +11 -7
- data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +2 -2
- data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +2 -2
- data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +1 -1
- data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +2 -2
- data/spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb +9 -9
- data/spec/lib/appsignal/event_formatter_spec.rb +17 -17
- data/spec/lib/appsignal/extension_spec.rb +7 -7
- data/spec/lib/appsignal/garbage_collection_profiler_spec.rb +0 -3
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +11 -3
- data/spec/lib/appsignal/hooks/celluloid_spec.rb +12 -4
- data/spec/lib/appsignal/hooks/data_mapper_spec.rb +12 -4
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +21 -13
- data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +14 -6
- data/spec/lib/appsignal/hooks/net_http_spec.rb +11 -3
- data/spec/lib/appsignal/hooks/passenger_spec.rb +14 -6
- data/spec/lib/appsignal/hooks/puma_spec.rb +18 -10
- data/spec/lib/appsignal/hooks/rake_spec.rb +2 -2
- data/spec/lib/appsignal/hooks/redis_spec.rb +40 -30
- data/spec/lib/appsignal/hooks/sequel_spec.rb +11 -3
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +15 -7
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +17 -9
- data/spec/lib/appsignal/hooks/unicorn_spec.rb +16 -8
- data/spec/lib/appsignal/hooks/webmachine_spec.rb +14 -4
- data/spec/lib/appsignal/hooks_spec.rb +28 -28
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +1 -1
- data/spec/lib/appsignal/integrations/grape_spec.rb +3 -3
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +14 -16
- data/spec/lib/appsignal/integrations/object_spec.rb +10 -10
- data/spec/lib/appsignal/integrations/padrino_spec.rb +14 -18
- data/spec/lib/appsignal/integrations/railtie_spec.rb +35 -19
- data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +2 -2
- data/spec/lib/appsignal/integrations/resque_spec.rb +8 -8
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +2 -2
- data/spec/lib/appsignal/integrations/webmachine_spec.rb +1 -1
- data/spec/lib/appsignal/js_exception_transaction_spec.rb +1 -1
- data/spec/lib/appsignal/minutely_spec.rb +3 -3
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +12 -12
- data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +2 -2
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +19 -15
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +21 -21
- data/spec/lib/appsignal/rack/streaming_listener_spec.rb +5 -5
- data/spec/lib/appsignal/system_spec.rb +5 -5
- data/spec/lib/appsignal/transaction_spec.rb +176 -155
- data/spec/lib/appsignal/transmitter_spec.rb +29 -23
- data/spec/lib/appsignal/utils/params_sanitizer_spec.rb +49 -35
- data/spec/lib/appsignal/utils_spec.rb +15 -8
- data/spec/lib/appsignal_spec.rb +134 -150
- data/spec/spec_helper.rb +5 -2
- metadata +6 -10
- data/spec/lib/tmp/config/appsignal.yml +0 -2
- data/spec/support/delegate_matcher.rb +0 -38
@@ -6,8 +6,8 @@ describe Appsignal::Rack::JSExceptionCatcher do
|
|
6
6
|
let(:config) { project_fixture_config("production", config_options) }
|
7
7
|
|
8
8
|
before do
|
9
|
-
Appsignal.
|
10
|
-
config.
|
9
|
+
allow(Appsignal).to receive(:config).and_return(config)
|
10
|
+
allow(config).to receive(:active?).and_return(active)
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#initialize" do
|
@@ -3,7 +3,7 @@ if DependencyHelper.rails_present?
|
|
3
3
|
end
|
4
4
|
|
5
5
|
describe Appsignal::Rack::RailsInstrumentation do
|
6
|
-
before :
|
6
|
+
before :context do
|
7
7
|
start_agent
|
8
8
|
end
|
9
9
|
|
@@ -20,11 +20,11 @@ if DependencyHelper.rails_present?
|
|
20
20
|
|
21
21
|
describe "#call" do
|
22
22
|
before do
|
23
|
-
middleware.
|
23
|
+
allow(middleware).to receive(:raw_payload).and_return({})
|
24
24
|
end
|
25
25
|
|
26
26
|
context "when appsignal is active" do
|
27
|
-
before { Appsignal.
|
27
|
+
before { allow(Appsignal).to receive(:active?).and_return(true) }
|
28
28
|
|
29
29
|
it "should call with monitoring" do
|
30
30
|
expect(middleware).to receive(:call_with_appsignal_monitoring).with(env)
|
@@ -32,7 +32,7 @@ if DependencyHelper.rails_present?
|
|
32
32
|
end
|
33
33
|
|
34
34
|
context "when appsignal is not active" do
|
35
|
-
before { Appsignal.
|
35
|
+
before { allow(Appsignal).to receive(:active?).and_return(false) }
|
36
36
|
|
37
37
|
it "should not call with monitoring" do
|
38
38
|
expect(middleware).to_not receive(:call_with_appsignal_monitoring)
|
@@ -48,7 +48,7 @@ if DependencyHelper.rails_present?
|
|
48
48
|
|
49
49
|
describe "#call_with_appsignal_monitoring" do
|
50
50
|
it "should create a transaction" do
|
51
|
-
Appsignal::Transaction.
|
51
|
+
expect(Appsignal::Transaction).to receive(:create).with(
|
52
52
|
"1",
|
53
53
|
Appsignal::Transaction::HTTP_REQUEST,
|
54
54
|
kind_of(ActionDispatch::Request),
|
@@ -63,29 +63,29 @@ if DependencyHelper.rails_present?
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should call the app" do
|
66
|
-
app.
|
66
|
+
expect(app).to receive(:call).with(env)
|
67
67
|
end
|
68
68
|
|
69
69
|
context "with an error" do
|
70
70
|
let(:error) { VerySpecificError.new }
|
71
71
|
let(:app) do
|
72
72
|
double.tap do |d|
|
73
|
-
d.
|
73
|
+
allow(d).to receive(:call).and_raise(error)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should set the error" do
|
78
|
-
Appsignal::Transaction.
|
78
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_error).with(error)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should set metadata" do
|
83
|
-
Appsignal::Transaction.
|
83
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_metadata).twice
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should set the action and queue start" do
|
87
|
-
Appsignal::Transaction.
|
88
|
-
Appsignal::Transaction.
|
87
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_action).with("MockController#index")
|
88
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_http_or_background_queue_start)
|
89
89
|
end
|
90
90
|
|
91
91
|
after { middleware.call(env) rescue VerySpecificError }
|
@@ -94,16 +94,20 @@ if DependencyHelper.rails_present?
|
|
94
94
|
describe "#request_id" do
|
95
95
|
subject { middleware.request_id(env) }
|
96
96
|
|
97
|
-
context "with request id
|
97
|
+
context "with request id present" do
|
98
98
|
let(:env) { { "action_dispatch.request_id" => "id" } }
|
99
99
|
|
100
|
-
it
|
100
|
+
it "returns the present id" do
|
101
|
+
is_expected.to eq "id"
|
102
|
+
end
|
101
103
|
end
|
102
104
|
|
103
|
-
context "with request id not
|
105
|
+
context "with request id not present" do
|
104
106
|
let(:env) { {} }
|
105
107
|
|
106
|
-
|
108
|
+
it "sets a new id" do
|
109
|
+
expect(subject.length).to eq 36
|
110
|
+
end
|
107
111
|
end
|
108
112
|
end
|
109
113
|
end
|
@@ -10,8 +10,8 @@ if DependencyHelper.sinatra_present?
|
|
10
10
|
describe "#call" do
|
11
11
|
before do
|
12
12
|
start_agent
|
13
|
-
middleware.
|
14
|
-
Appsignal.
|
13
|
+
allow(middleware).to receive(:raw_payload).and_return({})
|
14
|
+
allow(Appsignal).to receive(:active?).and_return(true)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should call without monitoring" do
|
@@ -31,7 +31,7 @@ if DependencyHelper.sinatra_present?
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe Appsignal::Rack::SinatraBaseInstrumentation do
|
34
|
-
before :
|
34
|
+
before :context do
|
35
35
|
start_agent
|
36
36
|
end
|
37
37
|
|
@@ -77,11 +77,11 @@ if DependencyHelper.sinatra_present?
|
|
77
77
|
|
78
78
|
describe "#call" do
|
79
79
|
before do
|
80
|
-
middleware.
|
80
|
+
allow(middleware).to receive(:raw_payload).and_return({})
|
81
81
|
end
|
82
82
|
|
83
83
|
context "when appsignal is active" do
|
84
|
-
before { Appsignal.
|
84
|
+
before { allow(Appsignal).to receive(:active?).and_return(true) }
|
85
85
|
|
86
86
|
it "should call with monitoring" do
|
87
87
|
expect(middleware).to receive(:call_with_appsignal_monitoring).with(env)
|
@@ -89,7 +89,7 @@ if DependencyHelper.sinatra_present?
|
|
89
89
|
end
|
90
90
|
|
91
91
|
context "when appsignal is not active" do
|
92
|
-
before { Appsignal.
|
92
|
+
before { allow(Appsignal).to receive(:active?).and_return(false) }
|
93
93
|
|
94
94
|
it "should not call with monitoring" do
|
95
95
|
expect(middleware).to_not receive(:call_with_appsignal_monitoring)
|
@@ -105,7 +105,7 @@ if DependencyHelper.sinatra_present?
|
|
105
105
|
|
106
106
|
describe "#call_with_appsignal_monitoring" do
|
107
107
|
it "should create a transaction" do
|
108
|
-
Appsignal::Transaction.
|
108
|
+
expect(Appsignal::Transaction).to receive(:create).with(
|
109
109
|
kind_of(String),
|
110
110
|
Appsignal::Transaction::HTTP_REQUEST,
|
111
111
|
kind_of(Sinatra::Request),
|
@@ -114,20 +114,20 @@ if DependencyHelper.sinatra_present?
|
|
114
114
|
end
|
115
115
|
|
116
116
|
it "should call the app" do
|
117
|
-
app.
|
117
|
+
expect(app).to receive(:call).with(env)
|
118
118
|
end
|
119
119
|
|
120
120
|
context "with an error" do
|
121
121
|
let(:error) { VerySpecificError.new }
|
122
122
|
let(:app) do
|
123
123
|
double.tap do |d|
|
124
|
-
d.
|
125
|
-
d.
|
124
|
+
allow(d).to receive(:call).and_raise(error)
|
125
|
+
allow(d).to receive(:settings).and_return(settings)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should set the error" do
|
130
|
-
Appsignal::Transaction.
|
130
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_error).with(error)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -136,14 +136,14 @@ if DependencyHelper.sinatra_present?
|
|
136
136
|
let(:env) { { "sinatra.error" => error } }
|
137
137
|
|
138
138
|
it "should set the error" do
|
139
|
-
Appsignal::Transaction.
|
139
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_error).with(error)
|
140
140
|
end
|
141
141
|
|
142
142
|
context "if raise_errors is on" do
|
143
143
|
let(:settings) { double(:raise_errors => true) }
|
144
144
|
|
145
145
|
it "should not set the error" do
|
146
|
-
Appsignal::Transaction.
|
146
|
+
expect_any_instance_of(Appsignal::Transaction).to_not receive(:set_error)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -151,21 +151,21 @@ if DependencyHelper.sinatra_present?
|
|
151
151
|
let(:env) { { "sinatra.error" => error, "sinatra.skip_appsignal_error" => true } }
|
152
152
|
|
153
153
|
it "should not set the error" do
|
154
|
-
Appsignal::Transaction.
|
154
|
+
expect_any_instance_of(Appsignal::Transaction).to_not receive(:set_error)
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
159
|
describe "action name" do
|
160
160
|
it "should set the action" do
|
161
|
-
Appsignal::Transaction.
|
161
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_action).with("GET /")
|
162
162
|
end
|
163
163
|
|
164
164
|
context "without 'sinatra.route' env" do
|
165
165
|
let(:env) { { :path => "/", :method => "GET" } }
|
166
166
|
|
167
167
|
it "returns nil" do
|
168
|
-
Appsignal::Transaction.
|
168
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_action).with(nil)
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
@@ -173,25 +173,25 @@ if DependencyHelper.sinatra_present?
|
|
173
173
|
before { env["SCRIPT_NAME"] = "/api" }
|
174
174
|
|
175
175
|
it "should call set_action with an application prefix path" do
|
176
|
-
Appsignal::Transaction.
|
176
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_action).with("GET /api/")
|
177
177
|
end
|
178
178
|
|
179
179
|
context "without 'sinatra.route' env" do
|
180
180
|
let(:env) { { :path => "/", :method => "GET" } }
|
181
181
|
|
182
182
|
it "returns nil" do
|
183
|
-
Appsignal::Transaction.
|
183
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_action).with(nil)
|
184
184
|
end
|
185
185
|
end
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
189
|
it "should set metadata" do
|
190
|
-
Appsignal::Transaction.
|
190
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_metadata).twice
|
191
191
|
end
|
192
192
|
|
193
193
|
it "should set the queue start" do
|
194
|
-
Appsignal::Transaction.
|
194
|
+
expect_any_instance_of(Appsignal::Transaction).to receive(:set_http_or_background_queue_start)
|
195
195
|
end
|
196
196
|
|
197
197
|
context "with overridden request class and params method" do
|
@@ -199,7 +199,7 @@ if DependencyHelper.sinatra_present?
|
|
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.
|
202
|
+
expect(::Rack::Request).to receive(:new)
|
203
203
|
.with(env.merge(:params_method => :filtered_params))
|
204
204
|
.at_least(:once)
|
205
205
|
.and_return(request)
|
@@ -15,7 +15,7 @@ describe Appsignal::Rack::StreamingListener do
|
|
15
15
|
|
16
16
|
describe "#call" do
|
17
17
|
context "when Appsignal is active" do
|
18
|
-
before { Appsignal.
|
18
|
+
before { allow(Appsignal).to receive(:active?).and_return(true) }
|
19
19
|
|
20
20
|
it "should call `call_with_appsignal_monitoring`" do
|
21
21
|
expect(listener).to receive(:call_with_appsignal_monitoring)
|
@@ -23,7 +23,7 @@ describe Appsignal::Rack::StreamingListener do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when Appsignal is not active" do
|
26
|
-
before { Appsignal.
|
26
|
+
before { allow(Appsignal).to receive(:active?).and_return(false) }
|
27
27
|
|
28
28
|
it "should not call `call_with_appsignal_monitoring`" do
|
29
29
|
expect(listener).to_not receive(:call_with_appsignal_monitoring)
|
@@ -45,9 +45,9 @@ describe Appsignal::Rack::StreamingListener do
|
|
45
45
|
let(:raw_payload) { { :foo => :bar } }
|
46
46
|
|
47
47
|
before do
|
48
|
-
SecureRandom.
|
49
|
-
listener.
|
50
|
-
Appsignal::Transaction.
|
48
|
+
allow(SecureRandom).to receive(:uuid).and_return("123")
|
49
|
+
allow(listener).to receive(:raw_payload).and_return(raw_payload)
|
50
|
+
allow(Appsignal::Transaction).to receive(:create).and_return(transaction)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should create a transaction" do
|
@@ -6,7 +6,7 @@ describe Appsignal::System do
|
|
6
6
|
around { |example| recognize_as_heroku { example.run } }
|
7
7
|
|
8
8
|
it "returns true" do
|
9
|
-
expect(subject).to
|
9
|
+
expect(subject).to be_truthy
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -14,7 +14,7 @@ describe Appsignal::System do
|
|
14
14
|
around { |example| recognize_as_container(:docker) { example.run } }
|
15
15
|
|
16
16
|
it "returns true" do
|
17
|
-
expect(subject).to
|
17
|
+
expect(subject).to be_truthy
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,7 +22,7 @@ describe Appsignal::System do
|
|
22
22
|
around { |example| recognize_as_container(:none) { example.run } }
|
23
23
|
|
24
24
|
it "returns false" do
|
25
|
-
expect(subject).to
|
25
|
+
expect(subject).to be_falsy
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -34,7 +34,7 @@ describe Appsignal::System do
|
|
34
34
|
around { |example| recognize_as_heroku { example.run } }
|
35
35
|
|
36
36
|
it "returns true" do
|
37
|
-
expect(subject).to
|
37
|
+
expect(subject).to be_truthy
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,7 +42,7 @@ describe Appsignal::System do
|
|
42
42
|
around { |example| recognize_as_container(:none) { example.run } }
|
43
43
|
|
44
44
|
it "returns false" do
|
45
|
-
expect(subject).to
|
45
|
+
expect(subject).to be_falsy
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,13 +1,5 @@
|
|
1
|
-
require_relative "../../support/mocks/fake_gc_profiler"
|
2
|
-
|
3
|
-
class Smash < Hash
|
4
|
-
def []=(_key, _val)
|
5
|
-
raise "the roof"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
1
|
describe Appsignal::Transaction do
|
10
|
-
before :
|
2
|
+
before :context do
|
11
3
|
start_agent
|
12
4
|
end
|
13
5
|
|
@@ -25,19 +17,19 @@ describe Appsignal::Transaction do
|
|
25
17
|
describe "class methods" do
|
26
18
|
describe ".create" do
|
27
19
|
it "should add the transaction to thread local" do
|
28
|
-
Appsignal::Extension.
|
20
|
+
expect(Appsignal::Extension).to receive(:start_transaction).with("1", "http_request", 0)
|
29
21
|
|
30
22
|
created_transaction = Appsignal::Transaction.create("1", namespace, request, options)
|
31
23
|
|
32
|
-
Thread.current[:appsignal_transaction].
|
24
|
+
expect(Thread.current[:appsignal_transaction]).to eq created_transaction
|
33
25
|
end
|
34
26
|
|
35
27
|
it "should create a transaction" do
|
36
28
|
created_transaction = Appsignal::Transaction.create("1", namespace, request, options)
|
37
29
|
|
38
|
-
created_transaction.
|
39
|
-
created_transaction.transaction_id.
|
40
|
-
created_transaction.namespace.
|
30
|
+
expect(created_transaction).to be_a Appsignal::Transaction
|
31
|
+
expect(created_transaction.transaction_id).to eq "1"
|
32
|
+
expect(created_transaction.namespace).to eq "http_request"
|
41
33
|
end
|
42
34
|
|
43
35
|
context "when a transaction is already running" do
|
@@ -77,11 +69,11 @@ describe Appsignal::Transaction do
|
|
77
69
|
before { Appsignal::Transaction.create("1", namespace, request, options) }
|
78
70
|
|
79
71
|
it "should return the correct transaction" do
|
80
|
-
|
72
|
+
is_expected.to eq transaction
|
81
73
|
end
|
82
74
|
|
83
75
|
it "should indicate it's not a nil transaction" do
|
84
|
-
subject.nil_transaction
|
76
|
+
expect(subject.nil_transaction?).to be_falsy
|
85
77
|
end
|
86
78
|
end
|
87
79
|
|
@@ -91,11 +83,11 @@ describe Appsignal::Transaction do
|
|
91
83
|
end
|
92
84
|
|
93
85
|
it "should return a nil transaction stub" do
|
94
|
-
|
86
|
+
is_expected.to be_a Appsignal::Transaction::NilTransaction
|
95
87
|
end
|
96
88
|
|
97
89
|
it "should indicate it's a nil transaction" do
|
98
|
-
subject.nil_transaction
|
90
|
+
expect(subject.nil_transaction?).to be_truthy
|
99
91
|
end
|
100
92
|
end
|
101
93
|
end
|
@@ -104,19 +96,19 @@ describe Appsignal::Transaction do
|
|
104
96
|
before { Appsignal::Transaction.create("2", Appsignal::Transaction::HTTP_REQUEST, {}) }
|
105
97
|
|
106
98
|
it "should complete the current transaction and set the thread appsignal_transaction to nil" do
|
107
|
-
Appsignal::Transaction.current.
|
99
|
+
expect(Appsignal::Transaction.current).to receive(:complete)
|
108
100
|
|
109
101
|
Appsignal::Transaction.complete_current!
|
110
102
|
|
111
|
-
Thread.current[:appsignal_transaction].
|
103
|
+
expect(Thread.current[:appsignal_transaction]).to be_nil
|
112
104
|
end
|
113
105
|
|
114
106
|
it "should still clear the transaction if there is an error" do
|
115
|
-
Appsignal::Transaction.current.
|
107
|
+
expect(Appsignal::Transaction.current).to receive(:complete).and_raise "Error"
|
116
108
|
|
117
109
|
Appsignal::Transaction.complete_current!
|
118
110
|
|
119
|
-
Thread.current[:appsignal_transaction].
|
111
|
+
expect(Thread.current[:appsignal_transaction]).to be_nil
|
120
112
|
end
|
121
113
|
|
122
114
|
context "if a transaction is discarded" do
|
@@ -124,18 +116,18 @@ describe Appsignal::Transaction do
|
|
124
116
|
expect(Appsignal::Transaction.current.ext).to_not receive(:complete)
|
125
117
|
|
126
118
|
Appsignal::Transaction.current.discard!
|
127
|
-
expect(Appsignal::Transaction.current.discarded?).to
|
119
|
+
expect(Appsignal::Transaction.current.discarded?).to be_truthy
|
128
120
|
|
129
121
|
Appsignal::Transaction.complete_current!
|
130
122
|
|
131
|
-
Thread.current[:appsignal_transaction].
|
123
|
+
expect(Thread.current[:appsignal_transaction]).to be_nil
|
132
124
|
end
|
133
125
|
|
134
126
|
it "should not be discarded when restore! is called" do
|
135
127
|
Appsignal::Transaction.current.discard!
|
136
|
-
expect(Appsignal::Transaction.current.discarded?).to
|
128
|
+
expect(Appsignal::Transaction.current.discarded?).to be_truthy
|
137
129
|
Appsignal::Transaction.current.restore!
|
138
|
-
expect(Appsignal::Transaction.current.discarded?).to
|
130
|
+
expect(Appsignal::Transaction.current.discarded?).to be_falsy
|
139
131
|
end
|
140
132
|
end
|
141
133
|
end
|
@@ -143,17 +135,17 @@ describe Appsignal::Transaction do
|
|
143
135
|
|
144
136
|
describe "#complete" do
|
145
137
|
it "should sample data if it needs to be sampled" do
|
146
|
-
transaction.ext.
|
147
|
-
transaction.
|
148
|
-
transaction.ext.
|
138
|
+
expect(transaction.ext).to receive(:finish).and_return(true)
|
139
|
+
expect(transaction).to receive(:sample_data)
|
140
|
+
expect(transaction.ext).to receive(:complete)
|
149
141
|
|
150
142
|
transaction.complete
|
151
143
|
end
|
152
144
|
|
153
145
|
it "should not sample data if it does not need to be sampled" do
|
154
|
-
transaction.ext.
|
155
|
-
transaction.
|
156
|
-
transaction.ext.
|
146
|
+
expect(transaction.ext).to receive(:finish).and_return(false)
|
147
|
+
expect(transaction).to_not receive(:sample_data)
|
148
|
+
expect(transaction.ext).to receive(:complete)
|
157
149
|
|
158
150
|
transaction.complete
|
159
151
|
end
|
@@ -180,14 +172,14 @@ describe Appsignal::Transaction do
|
|
180
172
|
|
181
173
|
describe "#paused?" do
|
182
174
|
it "should return the pause state" do
|
183
|
-
expect(transaction.paused?).to
|
175
|
+
expect(transaction.paused?).to be_falsy
|
184
176
|
end
|
185
177
|
|
186
178
|
context "when paused" do
|
187
179
|
before { transaction.pause! }
|
188
180
|
|
189
181
|
it "should return the pause state" do
|
190
|
-
expect(transaction.paused?).to
|
182
|
+
expect(transaction.paused?).to be_truthy
|
191
183
|
end
|
192
184
|
end
|
193
185
|
end
|
@@ -195,24 +187,43 @@ describe Appsignal::Transaction do
|
|
195
187
|
|
196
188
|
context "with transaction instance" do
|
197
189
|
context "initialization" do
|
198
|
-
|
190
|
+
it "loads the AppSignal extension" do
|
191
|
+
expect(transaction.ext).to_not be_nil
|
192
|
+
end
|
193
|
+
|
194
|
+
it "sets the transaction id" do
|
195
|
+
expect(transaction.transaction_id).to eq "1"
|
196
|
+
end
|
197
|
+
|
198
|
+
it "sets the namespace to http_request" do
|
199
|
+
expect(transaction.namespace).to eq "http_request"
|
200
|
+
end
|
201
|
+
|
202
|
+
it "sets the request" do
|
203
|
+
expect(transaction.request).to_not be_nil
|
204
|
+
end
|
199
205
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
+
it "sets the request not to paused" do
|
207
|
+
expect(transaction.paused).to be_falsy
|
208
|
+
end
|
209
|
+
|
210
|
+
it "sets no tags by default" do
|
211
|
+
expect(transaction.tags).to eq({})
|
212
|
+
end
|
206
213
|
|
207
|
-
|
214
|
+
describe "#options" do
|
208
215
|
subject { transaction.options }
|
209
216
|
|
210
|
-
|
217
|
+
it "sets the default :params_method" do
|
218
|
+
expect(subject[:params_method]).to eq :params
|
219
|
+
end
|
211
220
|
|
212
221
|
context "with overridden options" do
|
213
222
|
let(:options) { { :params_method => :filtered_params } }
|
214
223
|
|
215
|
-
|
224
|
+
it "sets the overriden :params_method" do
|
225
|
+
expect(subject[:params_method]).to eq :filtered_params
|
226
|
+
end
|
216
227
|
end
|
217
228
|
end
|
218
229
|
end
|
@@ -240,7 +251,7 @@ describe Appsignal::Transaction do
|
|
240
251
|
|
241
252
|
describe "set_action" do
|
242
253
|
it "should set the action in extension" do
|
243
|
-
transaction.ext.
|
254
|
+
expect(transaction.ext).to receive(:set_action).with(
|
244
255
|
"PagesController#show"
|
245
256
|
).once
|
246
257
|
|
@@ -248,7 +259,7 @@ describe Appsignal::Transaction do
|
|
248
259
|
end
|
249
260
|
|
250
261
|
it "should not set the action in extension when value is nil" do
|
251
|
-
Appsignal::Extension.
|
262
|
+
expect(Appsignal::Extension).to_not receive(:set_transaction_action)
|
252
263
|
|
253
264
|
transaction.set_action(nil)
|
254
265
|
end
|
@@ -259,7 +270,7 @@ describe Appsignal::Transaction do
|
|
259
270
|
let(:from) { { :controller => "HomeController", :action => "show" } }
|
260
271
|
|
261
272
|
it "should set the action" do
|
262
|
-
transaction.
|
273
|
+
expect(transaction).to receive(:set_action).with("HomeController#show")
|
263
274
|
end
|
264
275
|
end
|
265
276
|
|
@@ -267,7 +278,7 @@ describe Appsignal::Transaction do
|
|
267
278
|
let(:from) { { :action => "show" } }
|
268
279
|
|
269
280
|
it "should set the action" do
|
270
|
-
transaction.
|
281
|
+
expect(transaction).to receive(:set_action).with("show")
|
271
282
|
end
|
272
283
|
end
|
273
284
|
|
@@ -275,7 +286,7 @@ describe Appsignal::Transaction do
|
|
275
286
|
let(:from) { { :class => "Worker", :method => "perform" } }
|
276
287
|
|
277
288
|
it "should set the action" do
|
278
|
-
transaction.
|
289
|
+
expect(transaction).to receive(:set_action).with("Worker#perform")
|
279
290
|
end
|
280
291
|
end
|
281
292
|
|
@@ -284,7 +295,7 @@ describe Appsignal::Transaction do
|
|
284
295
|
|
285
296
|
describe "set_queue_start" do
|
286
297
|
it "should set the queue start in extension" do
|
287
|
-
transaction.ext.
|
298
|
+
expect(transaction.ext).to receive(:set_queue_start).with(
|
288
299
|
10.0
|
289
300
|
).once
|
290
301
|
|
@@ -292,19 +303,19 @@ describe Appsignal::Transaction do
|
|
292
303
|
end
|
293
304
|
|
294
305
|
it "should not set the queue start in extension when value is nil" do
|
295
|
-
transaction.ext.
|
306
|
+
expect(transaction.ext).to_not receive(:set_queue_start)
|
296
307
|
|
297
308
|
transaction.set_queue_start(nil)
|
298
309
|
end
|
299
310
|
|
300
311
|
it "should not raise an error when the queue start is too big" do
|
301
|
-
transaction.ext.
|
312
|
+
expect(transaction.ext).to receive(:set_queue_start).and_raise(RangeError)
|
302
313
|
|
303
|
-
Appsignal.logger.
|
314
|
+
expect(Appsignal.logger).to receive(:warn).with("Queue start value 10 is too big")
|
304
315
|
|
305
|
-
|
316
|
+
expect do
|
306
317
|
transaction.set_queue_start(10)
|
307
|
-
end.
|
318
|
+
end.to_not raise_error
|
308
319
|
end
|
309
320
|
end
|
310
321
|
|
@@ -314,7 +325,7 @@ describe Appsignal::Transaction do
|
|
314
325
|
let(:env) { { "HTTP_X_REQUEST_START" => (fixed_time * 1000).to_s } }
|
315
326
|
|
316
327
|
it "should set the queue start on the transaction" do
|
317
|
-
transaction.
|
328
|
+
expect(transaction).to receive(:set_queue_start).with(13_897_836_000)
|
318
329
|
|
319
330
|
transaction.set_http_or_background_queue_start
|
320
331
|
end
|
@@ -325,7 +336,7 @@ describe Appsignal::Transaction do
|
|
325
336
|
let(:env) { { :queue_start => fixed_time } }
|
326
337
|
|
327
338
|
it "should set the queue start on the transaction" do
|
328
|
-
transaction.
|
339
|
+
expect(transaction).to receive(:set_queue_start).with(1_389_783_600_000)
|
329
340
|
|
330
341
|
transaction.set_http_or_background_queue_start
|
331
342
|
end
|
@@ -334,7 +345,7 @@ describe Appsignal::Transaction do
|
|
334
345
|
|
335
346
|
describe "#set_metadata" do
|
336
347
|
it "should set the metdata in extension" do
|
337
|
-
transaction.ext.
|
348
|
+
expect(transaction.ext).to receive(:set_metadata).with(
|
338
349
|
"request_method",
|
339
350
|
"GET"
|
340
351
|
).once
|
@@ -343,7 +354,7 @@ describe Appsignal::Transaction do
|
|
343
354
|
end
|
344
355
|
|
345
356
|
it "should not set the metdata in extension when value is nil" do
|
346
|
-
transaction.ext.
|
357
|
+
expect(transaction.ext).to_not receive(:set_metadata)
|
347
358
|
|
348
359
|
transaction.set_metadata("request_method", nil)
|
349
360
|
end
|
@@ -351,7 +362,7 @@ describe Appsignal::Transaction do
|
|
351
362
|
|
352
363
|
describe "set_sample_data" do
|
353
364
|
it "should set the data" do
|
354
|
-
transaction.ext.
|
365
|
+
expect(transaction.ext).to receive(:set_sample_data).with(
|
355
366
|
"params",
|
356
367
|
Appsignal::Utils.data_generate("controller" => "blog_posts", "action" => "show", "id" => "1")
|
357
368
|
).once
|
@@ -365,7 +376,7 @@ describe Appsignal::Transaction do
|
|
365
376
|
end
|
366
377
|
|
367
378
|
it "should do nothing if the data cannot be converted to json" do
|
368
|
-
transaction.ext.
|
379
|
+
expect(transaction.ext).to_not receive(:set_sample_data).with(
|
369
380
|
"params",
|
370
381
|
kind_of(String)
|
371
382
|
)
|
@@ -376,7 +387,7 @@ describe Appsignal::Transaction do
|
|
376
387
|
|
377
388
|
describe "#sample_data" do
|
378
389
|
it "should sample data" do
|
379
|
-
transaction.ext.
|
390
|
+
expect(transaction.ext).to receive(:set_sample_data).with(
|
380
391
|
"environment",
|
381
392
|
Appsignal::Utils.data_generate(
|
382
393
|
"CONTENT_LENGTH" => "0",
|
@@ -386,19 +397,19 @@ describe Appsignal::Transaction do
|
|
386
397
|
"PATH_INFO" => "/blog"
|
387
398
|
)
|
388
399
|
).once
|
389
|
-
transaction.ext.
|
400
|
+
expect(transaction.ext).to receive(:set_sample_data).with(
|
390
401
|
"session_data",
|
391
402
|
Appsignal::Utils.data_generate({})
|
392
403
|
).once
|
393
|
-
transaction.ext.
|
404
|
+
expect(transaction.ext).to receive(:set_sample_data).with(
|
394
405
|
"params",
|
395
406
|
Appsignal::Utils.data_generate("controller" => "blog_posts", "action" => "show", "id" => "1")
|
396
407
|
).once
|
397
|
-
transaction.ext.
|
408
|
+
expect(transaction.ext).to receive(:set_sample_data).with(
|
398
409
|
"metadata",
|
399
410
|
Appsignal::Utils.data_generate("key" => "value")
|
400
411
|
).once
|
401
|
-
transaction.ext.
|
412
|
+
expect(transaction.ext).to receive(:set_sample_data).with(
|
402
413
|
"tags",
|
403
414
|
Appsignal::Utils.data_generate({})
|
404
415
|
).once
|
@@ -412,20 +423,20 @@ describe Appsignal::Transaction do
|
|
412
423
|
let(:error) { double(:error, :message => "test message", :backtrace => ["line 1"]) }
|
413
424
|
|
414
425
|
it "should also respond to add_exception for backwords compatibility" do
|
415
|
-
transaction.
|
426
|
+
expect(transaction).to respond_to(:add_exception)
|
416
427
|
end
|
417
428
|
|
418
429
|
it "should not add the error if appsignal is not active" do
|
419
|
-
Appsignal.
|
420
|
-
transaction.ext.
|
430
|
+
allow(Appsignal).to receive(:active?).and_return(false)
|
431
|
+
expect(transaction.ext).to_not receive(:set_error)
|
421
432
|
|
422
433
|
transaction.set_error(error)
|
423
434
|
end
|
424
435
|
|
425
436
|
context "for a http request" do
|
426
437
|
it "should set an error in the extension" do
|
427
|
-
transaction.ext.
|
428
|
-
"RSpec::Mocks::
|
438
|
+
expect(transaction.ext).to receive(:set_error).with(
|
439
|
+
"RSpec::Mocks::Double",
|
429
440
|
"test message",
|
430
441
|
Appsignal::Utils.data_generate(["line 1"])
|
431
442
|
)
|
@@ -442,8 +453,8 @@ describe Appsignal::Transaction do
|
|
442
453
|
end
|
443
454
|
|
444
455
|
it "should set an error in the extension" do
|
445
|
-
transaction.ext.
|
446
|
-
"RSpec::Mocks::
|
456
|
+
expect(transaction.ext).to receive(:set_error).with(
|
457
|
+
"RSpec::Mocks::Double",
|
447
458
|
"",
|
448
459
|
Appsignal::Utils.data_generate(["line 1"])
|
449
460
|
)
|
@@ -455,21 +466,27 @@ describe Appsignal::Transaction do
|
|
455
466
|
|
456
467
|
describe "#start_event" do
|
457
468
|
it "should start the event in the extension" do
|
458
|
-
transaction.ext.
|
469
|
+
expect(transaction.ext).to receive(:start_event).with(0).and_call_original
|
459
470
|
|
460
471
|
transaction.start_event
|
461
472
|
end
|
462
473
|
end
|
463
474
|
|
464
475
|
describe "#finish_event" do
|
476
|
+
let(:fake_gc_time) { 123 }
|
477
|
+
before do
|
478
|
+
expect(described_class.garbage_collection_profiler)
|
479
|
+
.to receive(:total_time).at_least(:once).and_return(fake_gc_time)
|
480
|
+
end
|
481
|
+
|
465
482
|
it "should finish the event in the extension" do
|
466
|
-
transaction.ext.
|
483
|
+
expect(transaction.ext).to receive(:finish_event).with(
|
467
484
|
"name",
|
468
485
|
"title",
|
469
486
|
"body",
|
470
487
|
1,
|
471
|
-
|
472
|
-
)
|
488
|
+
fake_gc_time
|
489
|
+
).and_call_original
|
473
490
|
|
474
491
|
transaction.finish_event(
|
475
492
|
"name",
|
@@ -480,13 +497,13 @@ describe Appsignal::Transaction do
|
|
480
497
|
end
|
481
498
|
|
482
499
|
it "should finish the event in the extension with nil arguments" do
|
483
|
-
transaction.ext.
|
500
|
+
expect(transaction.ext).to receive(:finish_event).with(
|
484
501
|
"name",
|
485
502
|
"",
|
486
503
|
"",
|
487
504
|
0,
|
488
|
-
|
489
|
-
)
|
505
|
+
fake_gc_time
|
506
|
+
).and_call_original
|
490
507
|
|
491
508
|
transaction.finish_event(
|
492
509
|
"name",
|
@@ -495,25 +512,24 @@ describe Appsignal::Transaction do
|
|
495
512
|
nil
|
496
513
|
)
|
497
514
|
end
|
498
|
-
|
499
|
-
it "should add garbage collection time" do
|
500
|
-
allow_any_instance_of(Appsignal::GarbageCollectionProfiler)
|
501
|
-
.to receive(:internal_profiler)
|
502
|
-
.and_return(FakeGCProfiler.new(0.12345))
|
503
|
-
|
504
|
-
transaction.finish_event("name", nil, nil, nil)
|
505
|
-
end
|
506
515
|
end
|
507
516
|
|
508
517
|
describe "#record_event" do
|
518
|
+
let(:fake_gc_time) { 123 }
|
519
|
+
before do
|
520
|
+
expect(described_class.garbage_collection_profiler)
|
521
|
+
.to receive(:total_time).at_least(:once).and_return(fake_gc_time)
|
522
|
+
end
|
523
|
+
|
509
524
|
it "should record the event in the extension" do
|
510
|
-
transaction.ext.
|
525
|
+
expect(transaction.ext).to receive(:record_event).with(
|
511
526
|
"name",
|
512
527
|
"title",
|
513
528
|
"body",
|
514
529
|
1000,
|
515
|
-
1
|
516
|
-
|
530
|
+
1,
|
531
|
+
fake_gc_time
|
532
|
+
).and_call_original
|
517
533
|
|
518
534
|
transaction.record_event(
|
519
535
|
"name",
|
@@ -525,13 +541,14 @@ describe Appsignal::Transaction do
|
|
525
541
|
end
|
526
542
|
|
527
543
|
it "should finish the event in the extension with nil arguments" do
|
528
|
-
transaction.ext.
|
544
|
+
expect(transaction.ext).to receive(:record_event).with(
|
529
545
|
"name",
|
530
546
|
"",
|
531
547
|
"",
|
532
548
|
1000,
|
533
|
-
0
|
534
|
-
|
549
|
+
0,
|
550
|
+
fake_gc_time
|
551
|
+
).and_call_original
|
535
552
|
|
536
553
|
transaction.record_event(
|
537
554
|
"name",
|
@@ -546,19 +563,20 @@ describe Appsignal::Transaction do
|
|
546
563
|
describe "#instrument" do
|
547
564
|
it "should start and finish an event around the given block" do
|
548
565
|
stub = double
|
549
|
-
stub.
|
566
|
+
expect(stub).to receive(:method_call).and_return("return value")
|
550
567
|
|
551
|
-
transaction.
|
552
|
-
transaction.
|
568
|
+
expect(transaction).to receive(:start_event)
|
569
|
+
expect(transaction).to receive(:finish_event).with(
|
553
570
|
"name",
|
554
571
|
"title",
|
555
572
|
"body",
|
556
573
|
0
|
557
574
|
)
|
558
575
|
|
559
|
-
transaction.instrument "name", "title", "body" do
|
576
|
+
return_value = transaction.instrument "name", "title", "body" do
|
560
577
|
stub.method_call
|
561
|
-
end
|
578
|
+
end
|
579
|
+
expect(return_value).to eq "return value"
|
562
580
|
end
|
563
581
|
end
|
564
582
|
|
@@ -566,11 +584,11 @@ describe Appsignal::Transaction do
|
|
566
584
|
let(:env) { {} }
|
567
585
|
subject { Appsignal::Transaction::GenericRequest.new(env) }
|
568
586
|
|
569
|
-
it "
|
570
|
-
subject.env.
|
587
|
+
it "initializes with an empty env" do
|
588
|
+
expect(subject.env).to be_empty
|
571
589
|
end
|
572
590
|
|
573
|
-
context "
|
591
|
+
context "when given an env" do
|
574
592
|
let(:env) do
|
575
593
|
{
|
576
594
|
:params => { :id => 1 },
|
@@ -578,8 +596,13 @@ describe Appsignal::Transaction do
|
|
578
596
|
}
|
579
597
|
end
|
580
598
|
|
581
|
-
|
582
|
-
|
599
|
+
it "sets the given env" do
|
600
|
+
expect(subject.env).to eq env
|
601
|
+
end
|
602
|
+
|
603
|
+
it "sets the params present in the env" do
|
604
|
+
expect(subject.params).to eq(:id => 1)
|
605
|
+
end
|
583
606
|
end
|
584
607
|
end
|
585
608
|
|
@@ -591,23 +614,23 @@ describe Appsignal::Transaction do
|
|
591
614
|
context "when request is nil" do
|
592
615
|
let(:request) { nil }
|
593
616
|
|
594
|
-
it {
|
617
|
+
it { is_expected.to eq nil }
|
595
618
|
end
|
596
619
|
|
597
620
|
context "when env is nil" do
|
598
621
|
before { expect(transaction.request).to receive(:env).and_return(nil) }
|
599
622
|
|
600
|
-
it {
|
623
|
+
it { is_expected.to eq nil }
|
601
624
|
end
|
602
625
|
|
603
626
|
context "when queue start is nil" do
|
604
|
-
it {
|
627
|
+
it { is_expected.to eq nil }
|
605
628
|
end
|
606
629
|
|
607
630
|
context "when queue start is set" do
|
608
631
|
let(:env) { background_env_with_data }
|
609
632
|
|
610
|
-
it {
|
633
|
+
it { is_expected.to eq 1_389_783_590_000 }
|
611
634
|
end
|
612
635
|
end
|
613
636
|
|
@@ -620,48 +643,48 @@ describe Appsignal::Transaction do
|
|
620
643
|
context "when request is nil" do
|
621
644
|
let(:request) { nil }
|
622
645
|
|
623
|
-
it {
|
646
|
+
it { is_expected.to be_nil }
|
624
647
|
end
|
625
648
|
|
626
649
|
context "when env is nil" do
|
627
650
|
before { expect(transaction.request).to receive(:env).and_return(nil) }
|
628
651
|
|
629
|
-
it {
|
652
|
+
it { is_expected.to be_nil }
|
630
653
|
end
|
631
654
|
|
632
655
|
context "with no relevant header set" do
|
633
656
|
let(:env) { {} }
|
634
657
|
|
635
|
-
it {
|
658
|
+
it { is_expected.to be_nil }
|
636
659
|
end
|
637
660
|
|
638
661
|
context "with the HTTP_X_REQUEST_START header set" do
|
639
662
|
let(:env) { { "HTTP_X_REQUEST_START" => "t=#{slightly_earlier_time_value}" } }
|
640
663
|
|
641
|
-
it {
|
664
|
+
it { is_expected.to eq 1_389_783_599_600 }
|
642
665
|
|
643
666
|
context "with unparsable content" do
|
644
667
|
let(:env) { { "HTTP_X_REQUEST_START" => "something" } }
|
645
668
|
|
646
|
-
it {
|
669
|
+
it { is_expected.to be_nil }
|
647
670
|
end
|
648
671
|
|
649
672
|
context "with some cruft" do
|
650
673
|
let(:env) { { "HTTP_X_REQUEST_START" => "t=#{slightly_earlier_time_value}aaaa" } }
|
651
674
|
|
652
|
-
it {
|
675
|
+
it { is_expected.to eq 1_389_783_599_600 }
|
653
676
|
end
|
654
677
|
|
655
678
|
context "with a really low number" do
|
656
679
|
let(:env) { { "HTTP_X_REQUEST_START" => "t=100" } }
|
657
680
|
|
658
|
-
it {
|
681
|
+
it { is_expected.to be_nil }
|
659
682
|
end
|
660
683
|
|
661
684
|
context "with the alternate HTTP_X_QUEUE_START header set" do
|
662
685
|
let(:env) { { "HTTP_X_QUEUE_START" => "t=#{slightly_earlier_time_value}" } }
|
663
686
|
|
664
|
-
it {
|
687
|
+
it { is_expected.to eq 1_389_783_599_600 }
|
665
688
|
end
|
666
689
|
end
|
667
690
|
end
|
@@ -683,28 +706,28 @@ describe Appsignal::Transaction do
|
|
683
706
|
subject { transaction.send(:sanitized_params) }
|
684
707
|
|
685
708
|
context "without params" do
|
686
|
-
before { transaction.request.
|
709
|
+
before { allow(transaction.request).to receive(:params).and_return(nil) }
|
687
710
|
|
688
|
-
it {
|
711
|
+
it { is_expected.to be_nil }
|
689
712
|
end
|
690
713
|
|
691
714
|
context "when params crashes" do
|
692
|
-
before { transaction.request.
|
715
|
+
before { allow(transaction.request).to receive(:params).and_raise(NoMethodError) }
|
693
716
|
|
694
|
-
it {
|
717
|
+
it { is_expected.to be_nil }
|
695
718
|
end
|
696
719
|
|
697
720
|
context "when params method does not exist" do
|
698
721
|
let(:options) { { :params_method => :nonsense } }
|
699
722
|
|
700
|
-
it {
|
723
|
+
it { is_expected.to be_nil }
|
701
724
|
end
|
702
725
|
|
703
726
|
context "when not sending params" do
|
704
727
|
before { Appsignal.config.config_hash[:send_params] = false }
|
705
728
|
after { Appsignal.config.config_hash[:send_params] = true }
|
706
729
|
|
707
|
-
it {
|
730
|
+
it { is_expected.to be_nil }
|
708
731
|
end
|
709
732
|
|
710
733
|
context "with an array" do
|
@@ -712,13 +735,13 @@ describe Appsignal::Transaction do
|
|
712
735
|
Appsignal::Transaction::GenericRequest.new(background_env_with_data(:params => ["arg1", "arg2"]))
|
713
736
|
end
|
714
737
|
|
715
|
-
it {
|
738
|
+
it { is_expected.to eq ["arg1", "arg2"] }
|
716
739
|
|
717
740
|
context "with AppSignal filtering" do
|
718
741
|
before { Appsignal.config.config_hash[:filter_parameters] = %w(foo) }
|
719
742
|
after { Appsignal.config.config_hash[:filter_parameters] = [] }
|
720
743
|
|
721
|
-
it {
|
744
|
+
it { is_expected.to eq ["arg1", "arg2"] }
|
722
745
|
end
|
723
746
|
end
|
724
747
|
|
@@ -731,7 +754,7 @@ describe Appsignal::Transaction do
|
|
731
754
|
|
732
755
|
it "should call the params sanitizer" do
|
733
756
|
puts Appsignal.config.config_hash[:filter_parameters].inspect
|
734
|
-
subject.
|
757
|
+
expect(subject).to eq(:foo => :bar)
|
735
758
|
end
|
736
759
|
end
|
737
760
|
|
@@ -744,7 +767,7 @@ describe Appsignal::Transaction do
|
|
744
767
|
after { Appsignal.config.config_hash[:filter_parameters] = [] }
|
745
768
|
|
746
769
|
it "should call the params sanitizer with filtering" do
|
747
|
-
subject.
|
770
|
+
expect(subject).to eq(:foo => "[FILTERED]", :baz => :bat)
|
748
771
|
end
|
749
772
|
end
|
750
773
|
end
|
@@ -758,15 +781,13 @@ describe Appsignal::Transaction do
|
|
758
781
|
context "when request is nil" do
|
759
782
|
let(:request) { nil }
|
760
783
|
|
761
|
-
it
|
762
|
-
expect(subject).to be_nil
|
763
|
-
end
|
784
|
+
it { is_expected.to be_nil }
|
764
785
|
end
|
765
786
|
|
766
787
|
context "when env is nil" do
|
767
788
|
before { expect(transaction.request).to receive(:env).and_return(nil) }
|
768
789
|
|
769
|
-
it {
|
790
|
+
it { is_expected.to be_nil }
|
770
791
|
end
|
771
792
|
|
772
793
|
context "when env is present" do
|
@@ -778,7 +799,9 @@ describe Appsignal::Transaction do
|
|
778
799
|
end
|
779
800
|
end
|
780
801
|
|
781
|
-
|
802
|
+
it "only sets whitelisted keys" do
|
803
|
+
expect(subject.keys).to match_array(whitelisted_keys)
|
804
|
+
end
|
782
805
|
end
|
783
806
|
end
|
784
807
|
|
@@ -788,52 +811,50 @@ describe Appsignal::Transaction do
|
|
788
811
|
context "when request is nil" do
|
789
812
|
let(:request) { nil }
|
790
813
|
|
791
|
-
it
|
792
|
-
expect(subject).to be_nil
|
793
|
-
end
|
814
|
+
it { is_expected.to be_nil }
|
794
815
|
end
|
795
816
|
|
796
817
|
context "when session is nil" do
|
797
818
|
before { expect(transaction.request).to receive(:session).and_return(nil) }
|
798
819
|
|
799
|
-
it {
|
820
|
+
it { is_expected.to be_nil }
|
800
821
|
end
|
801
822
|
|
802
823
|
context "when session is empty" do
|
803
824
|
before { expect(transaction.request).to receive(:session).and_return({}) }
|
804
825
|
|
805
|
-
it {
|
826
|
+
it { is_expected.to eq({}) }
|
806
827
|
end
|
807
828
|
|
808
829
|
context "when request class does not have a session method" do
|
809
830
|
let(:request) { Appsignal::Transaction::GenericRequest.new({}) }
|
810
831
|
|
811
|
-
it {
|
832
|
+
it { is_expected.to be_nil }
|
812
833
|
end
|
813
834
|
|
814
835
|
context "when there is a session" do
|
815
836
|
before do
|
816
|
-
transaction.
|
817
|
-
transaction.
|
818
|
-
transaction.
|
837
|
+
expect(transaction).to respond_to(:request)
|
838
|
+
allow(transaction).to receive_message_chain(:request, :session => { :foo => :bar })
|
839
|
+
allow(transaction).to receive_message_chain(:request, :fullpath => :bar)
|
819
840
|
end
|
820
841
|
|
821
842
|
it "passes the session data into the params sanitizer" do
|
822
|
-
Appsignal::Utils::ParamsSanitizer.
|
843
|
+
expect(Appsignal::Utils::ParamsSanitizer).to receive(:sanitize).with(:foo => :bar)
|
823
844
|
.and_return(:sanitized_foo)
|
824
|
-
subject.
|
845
|
+
expect(subject).to eq :sanitized_foo
|
825
846
|
end
|
826
847
|
|
827
848
|
if defined? ActionDispatch::Request::Session
|
828
849
|
context "with ActionDispatch::Request::Session" do
|
829
850
|
before do
|
830
|
-
transaction.
|
831
|
-
transaction.
|
832
|
-
transaction.
|
851
|
+
expect(transaction).to respond_to(:request)
|
852
|
+
allow(transaction).to receive_message_chain(:request, :session => action_dispatch_session)
|
853
|
+
allow(transaction).to receive_message_chain(:request, :fullpath => :bar)
|
833
854
|
end
|
834
855
|
|
835
856
|
it "should return an session hash" do
|
836
|
-
Appsignal::Utils::ParamsSanitizer.
|
857
|
+
expect(Appsignal::Utils::ParamsSanitizer).to receive(:sanitize).with("foo" => :bar)
|
837
858
|
.and_return(:sanitized_foo)
|
838
859
|
subject
|
839
860
|
end
|
@@ -859,8 +880,8 @@ describe Appsignal::Transaction do
|
|
859
880
|
end
|
860
881
|
|
861
882
|
it "does not pass the session data into the params sanitizer" do
|
862
|
-
Appsignal::Utils::ParamsSanitizer.
|
863
|
-
subject.
|
883
|
+
expect(Appsignal::Utils::ParamsSanitizer).to_not receive(:sanitize)
|
884
|
+
expect(subject).to be_nil
|
864
885
|
end
|
865
886
|
end
|
866
887
|
end
|
@@ -872,19 +893,19 @@ describe Appsignal::Transaction do
|
|
872
893
|
context "when request is nil" do
|
873
894
|
let(:request) { nil }
|
874
895
|
|
875
|
-
it {
|
896
|
+
it { is_expected.to be_nil }
|
876
897
|
end
|
877
898
|
|
878
899
|
context "when env is nil" do
|
879
900
|
before { expect(transaction.request).to receive(:env).and_return(nil) }
|
880
901
|
|
881
|
-
it {
|
902
|
+
it { is_expected.to be_nil }
|
882
903
|
end
|
883
904
|
|
884
905
|
context "when env is present" do
|
885
906
|
let(:env) { { :metadata => { :key => "value" } } }
|
886
907
|
|
887
|
-
it {
|
908
|
+
it { is_expected.to eq env[:metadata] }
|
888
909
|
end
|
889
910
|
end
|
890
911
|
|
@@ -905,12 +926,12 @@ describe Appsignal::Transaction do
|
|
905
926
|
subject { transaction.send(:sanitized_tags).keys }
|
906
927
|
|
907
928
|
it "should only return whitelisted data" do
|
908
|
-
|
929
|
+
is_expected.to match_array([
|
909
930
|
:valid_key,
|
910
931
|
"valid_string_key",
|
911
932
|
:both_symbols,
|
912
933
|
:integer_value
|
913
|
-
]
|
934
|
+
])
|
914
935
|
end
|
915
936
|
end
|
916
937
|
|
@@ -938,7 +959,7 @@ describe Appsignal::Transaction do
|
|
938
959
|
subject { Appsignal::Transaction::NilTransaction.new }
|
939
960
|
|
940
961
|
it "should have method stubs" do
|
941
|
-
|
962
|
+
expect do
|
942
963
|
subject.complete
|
943
964
|
subject.pause!
|
944
965
|
subject.resume!
|
@@ -953,7 +974,7 @@ describe Appsignal::Transaction do
|
|
953
974
|
subject.set_sample_data("key", "data")
|
954
975
|
subject.sample_data
|
955
976
|
subject.set_error("a")
|
956
|
-
end.
|
977
|
+
end.to_not raise_error
|
957
978
|
end
|
958
979
|
end
|
959
980
|
end
|