appsignal 3.10.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +197 -0
- data/Gemfile +1 -0
- data/Rakefile +1 -1
- data/benchmark.rake +99 -42
- data/lib/appsignal/cli/demo.rb +0 -1
- data/lib/appsignal/cli/diagnose.rb +1 -1
- data/lib/appsignal/config.rb +204 -130
- data/lib/appsignal/demo.rb +16 -26
- data/lib/appsignal/event_formatter/rom/sql_formatter.rb +1 -0
- data/lib/appsignal/event_formatter.rb +3 -2
- data/lib/appsignal/helpers/instrumentation.rb +331 -19
- data/lib/appsignal/hooks/action_cable.rb +21 -16
- data/lib/appsignal/hooks/active_job.rb +14 -8
- data/lib/appsignal/hooks/delayed_job.rb +1 -1
- data/lib/appsignal/hooks/shoryuken.rb +3 -63
- data/lib/appsignal/integrations/action_cable.rb +5 -7
- data/lib/appsignal/integrations/active_support_notifications.rb +1 -0
- data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +36 -35
- data/lib/appsignal/integrations/data_mapper.rb +1 -0
- data/lib/appsignal/integrations/delayed_job_plugin.rb +27 -33
- data/lib/appsignal/integrations/dry_monitor.rb +1 -0
- data/lib/appsignal/integrations/excon.rb +1 -0
- data/lib/appsignal/integrations/grape.rb +7 -0
- data/lib/appsignal/integrations/hanami.rb +8 -43
- data/lib/appsignal/integrations/http.rb +1 -0
- data/lib/appsignal/integrations/net_http.rb +1 -0
- data/lib/appsignal/integrations/object.rb +6 -0
- data/lib/appsignal/integrations/padrino.rb +8 -73
- data/lib/appsignal/integrations/que.rb +13 -20
- data/lib/appsignal/integrations/railtie.rb +36 -14
- data/lib/appsignal/integrations/rake.rb +1 -5
- data/lib/appsignal/integrations/redis.rb +1 -0
- data/lib/appsignal/integrations/redis_client.rb +1 -0
- data/lib/appsignal/integrations/resque.rb +2 -5
- data/lib/appsignal/integrations/shoryuken.rb +75 -0
- data/lib/appsignal/integrations/sidekiq.rb +7 -15
- data/lib/appsignal/integrations/sinatra.rb +8 -19
- data/lib/appsignal/integrations/unicorn.rb +1 -0
- data/lib/appsignal/integrations/webmachine.rb +2 -5
- data/lib/appsignal/loaders/grape.rb +13 -0
- data/lib/appsignal/loaders/hanami.rb +40 -0
- data/lib/appsignal/loaders/padrino.rb +68 -0
- data/lib/appsignal/loaders/sinatra.rb +24 -0
- data/lib/appsignal/loaders.rb +92 -0
- data/lib/appsignal/logger.rb +7 -3
- data/lib/appsignal/probes/helpers.rb +1 -0
- data/lib/appsignal/probes/mri.rb +1 -0
- data/lib/appsignal/probes/sidekiq.rb +1 -0
- data/lib/appsignal/probes.rb +3 -0
- data/lib/appsignal/rack/abstract_middleware.rb +20 -13
- data/lib/appsignal/rack/event_handler.rb +44 -13
- data/lib/appsignal/rack/generic_instrumentation.rb +1 -0
- data/lib/appsignal/rack/grape_middleware.rb +2 -1
- data/lib/appsignal/rack/streaming_listener.rb +1 -0
- data/lib/appsignal/rack.rb +35 -0
- data/lib/appsignal/span.rb +1 -0
- data/lib/appsignal/transaction.rb +308 -101
- data/lib/appsignal/utils/data.rb +0 -1
- data/lib/appsignal/utils/hash_sanitizer.rb +0 -1
- data/lib/appsignal/utils/integration_logger.rb +0 -13
- data/lib/appsignal/utils/integration_memory_logger.rb +0 -13
- data/lib/appsignal/utils/json.rb +0 -1
- data/lib/appsignal/utils/query_params_sanitizer.rb +0 -1
- data/lib/appsignal/utils/stdout_and_logger_message.rb +0 -1
- data/lib/appsignal/utils.rb +6 -0
- data/lib/appsignal/version.rb +1 -1
- data/lib/appsignal.rb +169 -14
- data/spec/lib/appsignal/capistrano2_spec.rb +1 -1
- data/spec/lib/appsignal/cli/demo_spec.rb +0 -1
- data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +1 -1
- data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1
- data/spec/lib/appsignal/config_spec.rb +291 -44
- data/spec/lib/appsignal/demo_spec.rb +1 -2
- data/spec/lib/appsignal/environment_spec.rb +4 -2
- data/spec/lib/appsignal/hooks/action_cable_spec.rb +43 -74
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +3 -6
- data/spec/lib/appsignal/hooks/activejob_spec.rb +12 -3
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +2 -443
- data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +4 -7
- data/spec/lib/appsignal/hooks/excon_spec.rb +3 -6
- data/spec/lib/appsignal/hooks/gvl_spec.rb +2 -2
- data/spec/lib/appsignal/hooks/http_spec.rb +1 -3
- data/spec/lib/appsignal/hooks/net_http_spec.rb +1 -1
- data/spec/lib/appsignal/hooks/redis_client_spec.rb +5 -8
- data/spec/lib/appsignal/hooks/redis_spec.rb +3 -6
- data/spec/lib/appsignal/hooks/resque_spec.rb +1 -1
- data/spec/lib/appsignal/hooks/sequel_spec.rb +3 -5
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -171
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +1 -1
- data/spec/lib/appsignal/hooks/webmachine_spec.rb +1 -1
- data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +459 -0
- data/spec/lib/appsignal/integrations/grape_spec.rb +36 -0
- data/spec/lib/appsignal/integrations/hanami_spec.rb +9 -178
- data/spec/lib/appsignal/integrations/http_spec.rb +1 -5
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +4 -2
- data/spec/lib/appsignal/integrations/net_http_spec.rb +1 -1
- data/spec/lib/appsignal/integrations/object_spec.rb +1 -3
- data/spec/lib/appsignal/integrations/padrino_spec.rb +8 -330
- data/spec/lib/appsignal/integrations/que_spec.rb +3 -4
- data/spec/lib/appsignal/integrations/railtie_spec.rb +275 -191
- data/spec/lib/appsignal/integrations/shoryuken_spec.rb +167 -0
- data/spec/lib/appsignal/integrations/sidekiq_spec.rb +15 -13
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +9 -104
- data/spec/lib/appsignal/integrations/webmachine_spec.rb +13 -1
- data/spec/lib/appsignal/loaders/grape_spec.rb +12 -0
- data/spec/lib/appsignal/loaders/hanami_spec.rb +95 -0
- data/spec/lib/appsignal/loaders/padrino_spec.rb +277 -0
- data/spec/lib/appsignal/loaders/sinatra_spec.rb +47 -0
- data/spec/lib/appsignal/loaders_spec.rb +137 -0
- data/spec/lib/appsignal/probes/sidekiq_spec.rb +1 -1
- data/spec/lib/appsignal/probes_spec.rb +6 -5
- data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +51 -5
- data/spec/lib/appsignal/rack/event_handler_spec.rb +114 -10
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +1 -1
- data/spec/lib/appsignal/rack/grape_middleware_spec.rb +2 -35
- data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +1 -1
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +4 -2
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +3 -3
- data/spec/lib/appsignal/rack_spec.rb +63 -0
- data/spec/lib/appsignal/span_spec.rb +1 -3
- data/spec/lib/appsignal/transaction_spec.rb +1640 -1075
- data/spec/lib/appsignal/utils/integration_logger_spec.rb +12 -16
- data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -10
- data/spec/lib/appsignal_spec.rb +601 -36
- data/spec/lib/puma/appsignal_spec.rb +0 -3
- data/spec/spec_helper.rb +5 -4
- data/spec/support/helpers/config_helpers.rb +2 -1
- data/spec/support/helpers/loader_helper.rb +21 -0
- data/spec/support/helpers/transaction_helpers.rb +44 -20
- data/spec/support/matchers/transaction.rb +15 -1
- data/spec/support/stubs/appsignal/loaders/loader_stub.rb +7 -0
- data/spec/support/testing.rb +47 -1
- metadata +19 -2
@@ -1,186 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
if DependencyHelper.
|
3
|
+
if DependencyHelper.hanami_present?
|
4
4
|
describe "Hanami integration" do
|
5
|
-
|
5
|
+
it "loads the Hanami loader" do
|
6
|
+
ENV["APPSIGNAL_APP_NAME"] = "test/sinatra"
|
7
|
+
ENV["APPSIGNAL_PUSH_API_KEY"] = "test-key"
|
6
8
|
|
7
|
-
|
8
|
-
Appsignal.config = nil
|
9
|
-
allow(::Hanami::Action).to receive(:prepend)
|
10
|
-
uninstall_hanami_middleware
|
11
|
-
ENV["APPSIGNAL_APP_NAME"] = "hanamia-test-app"
|
12
|
-
ENV["APPSIGNAL_APP_ENV"] = "test"
|
13
|
-
ENV["APPSIGNAL_PUSH_API_KEY"] = "0000"
|
14
|
-
end
|
15
|
-
|
16
|
-
def uninstall_hanami_middleware
|
17
|
-
middleware_stack = ::Hanami.app.config.middleware.stack[::Hanami::Router::DEFAULT_PREFIX]
|
18
|
-
middleware_stack.delete_if do |middleware|
|
19
|
-
middleware.first == Appsignal::Rack::HanamiMiddleware ||
|
20
|
-
middleware.first == Rack::Events
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe Appsignal::Integrations::HanamiPlugin do
|
25
|
-
it "starts AppSignal on init" do
|
26
|
-
expect(Appsignal.active?).to be_falsey
|
27
|
-
|
28
|
-
Appsignal::Integrations::HanamiPlugin.init
|
29
|
-
|
30
|
-
expect(Appsignal.active?).to be_truthy
|
31
|
-
end
|
32
|
-
|
33
|
-
it "prepends the integration to Hanami::Action" do
|
34
|
-
Appsignal::Integrations::HanamiPlugin.init
|
35
|
-
|
36
|
-
expect(::Hanami::Action)
|
37
|
-
.to have_received(:prepend).with(Appsignal::Integrations::HanamiIntegration)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "adds middleware to the Hanami app" do
|
41
|
-
Appsignal::Integrations::HanamiPlugin.init
|
42
|
-
|
43
|
-
expect(::Hanami.app.config.middleware.stack[::Hanami::Router::DEFAULT_PREFIX])
|
44
|
-
.to include(
|
45
|
-
[Rack::Events, [[kind_of(Appsignal::Rack::EventHandler)]], *hanami_middleware_options],
|
46
|
-
[Appsignal::Rack::HanamiMiddleware, [], *hanami_middleware_options]
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when not active" do
|
51
|
-
before do
|
52
|
-
ENV.delete("APPSIGNAL_APP_NAME")
|
53
|
-
ENV.delete("APPSIGNAL_APP_ENV")
|
54
|
-
ENV.delete("APPSIGNAL_PUSH_API_KEY")
|
55
|
-
end
|
56
|
-
|
57
|
-
it "does not prepend the integration to Hanami::Action" do
|
58
|
-
Appsignal::Integrations::HanamiPlugin.init
|
59
|
-
|
60
|
-
expect(::Hanami::Action).to_not have_received(:prepend)
|
61
|
-
.with(Appsignal::Integrations::HanamiIntegration)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "does not add the middleware to the Hanami app" do
|
65
|
-
Appsignal::Integrations::HanamiPlugin.init
|
66
|
-
|
67
|
-
middleware_stack = ::Hanami.app.config.middleware.stack[::Hanami::Router::DEFAULT_PREFIX]
|
68
|
-
expect(middleware_stack).to_not include(
|
69
|
-
[Rack::Events, [[kind_of(Appsignal::Rack::EventHandler)]], *hanami_middleware_options]
|
70
|
-
)
|
71
|
-
expect(middleware_stack).to_not include(
|
72
|
-
[Appsignal::Rack::HanamiMiddleware, [], *hanami_middleware_options]
|
73
|
-
)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when AppSignal is already active" do
|
78
|
-
before do
|
79
|
-
expect(Appsignal).to receive(:active?).at_least(1).and_return(true)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "does not initialize AppSignal again" do
|
83
|
-
expect(Appsignal).to_not receive(:start)
|
84
|
-
|
85
|
-
Appsignal::Integrations::HanamiPlugin.init
|
86
|
-
end
|
87
|
-
|
88
|
-
it "prepends the integration to Hanami::Action" do
|
89
|
-
Appsignal::Integrations::HanamiPlugin.init
|
90
|
-
|
91
|
-
expect(::Hanami::Action)
|
92
|
-
.to have_received(:prepend).with(Appsignal::Integrations::HanamiIntegration)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "adds middleware to the Hanami app" do
|
96
|
-
Appsignal::Integrations::HanamiPlugin.init
|
97
|
-
|
98
|
-
expect(::Hanami.app.config.middleware.stack[::Hanami::Router::DEFAULT_PREFIX])
|
99
|
-
.to include(
|
100
|
-
[
|
101
|
-
Rack::Events,
|
102
|
-
[[kind_of(Appsignal::Rack::EventHandler)]],
|
103
|
-
*hanami_middleware_options
|
104
|
-
],
|
105
|
-
[Appsignal::Rack::HanamiMiddleware, [], *hanami_middleware_options]
|
106
|
-
)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context "when APPSIGNAL_APP_ENV ENV var is provided" do
|
111
|
-
it "uses this as the environment" do
|
112
|
-
ENV["APPSIGNAL_APP_ENV"] = "custom"
|
113
|
-
|
114
|
-
# Reset the plugin to pull down the latest data
|
115
|
-
Appsignal::Integrations::HanamiPlugin.init
|
116
|
-
|
117
|
-
expect(Appsignal.config.env).to eq("custom")
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "when APPSIGNAL_APP_ENV ENV var is not provided" do
|
122
|
-
it "uses the Hanami environment" do
|
123
|
-
# Reset the plugin to pull down the latest data
|
124
|
-
Appsignal::Integrations::HanamiPlugin.init
|
125
|
-
|
126
|
-
expect(Appsignal.config.env).to eq("test")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe Appsignal::Integrations::HanamiIntegration do
|
132
|
-
let(:transaction) { http_request_transaction }
|
133
|
-
let(:app) do
|
134
|
-
Class.new(HanamiApp::Actions::Books::Index) do
|
135
|
-
def self.name
|
136
|
-
"HanamiApp::Actions::Books::Index::TestClass"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
around { |example| keep_transactions { example.run } }
|
141
|
-
before do
|
142
|
-
ENV["APPSIGNAL_APP_NAME"] = "hanamia-test-app"
|
143
|
-
ENV["APPSIGNAL_APP_ENV"] = "test"
|
144
|
-
ENV["APPSIGNAL_PUSH_API_KEY"] = "0000"
|
145
|
-
Appsignal::Integrations::HanamiPlugin.init
|
146
|
-
allow(app).to receive(:prepend).and_call_original
|
147
|
-
app.prepend(Appsignal::Integrations::HanamiIntegration)
|
148
|
-
end
|
149
|
-
|
150
|
-
def make_request(env)
|
151
|
-
action = app.new
|
152
|
-
action.call(env)
|
153
|
-
end
|
154
|
-
|
155
|
-
describe "#call" do
|
156
|
-
context "without an active transaction" do
|
157
|
-
let(:env) { {} }
|
158
|
-
|
159
|
-
it "does not set the action name" do
|
160
|
-
make_request(env)
|
161
|
-
|
162
|
-
expect(transaction).to_not have_action
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context "with an active transaction" do
|
167
|
-
let(:env) { { Appsignal::Rack::APPSIGNAL_TRANSACTION => transaction } }
|
168
|
-
|
169
|
-
it "sets action name on the transaction" do
|
170
|
-
make_request(env)
|
171
|
-
|
172
|
-
expect(transaction).to have_action("HanamiApp::Actions::Books::Index::TestClass")
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
9
|
+
require "appsignal/integrations/hanami"
|
177
10
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
[nil]
|
183
|
-
end
|
11
|
+
expect(Appsignal::Loaders.instances).to include(
|
12
|
+
:hanami => kind_of(Appsignal::Loaders::HanamiLoader)
|
13
|
+
)
|
14
|
+
expect(Appsignal.active?).to be(true)
|
184
15
|
end
|
185
16
|
end
|
186
17
|
end
|
@@ -3,8 +3,10 @@ describe Appsignal::Hooks::MongoMonitorSubscriber do
|
|
3
3
|
let(:subscriber) { Appsignal::Hooks::MongoMonitorSubscriber.new }
|
4
4
|
|
5
5
|
context "with transaction" do
|
6
|
-
let
|
7
|
-
|
6
|
+
let(:transaction) { http_request_transaction }
|
7
|
+
before do
|
8
|
+
start_agent
|
9
|
+
set_current_transaction(transaction)
|
8
10
|
end
|
9
11
|
|
10
12
|
describe "#started" do
|
@@ -2,7 +2,7 @@ require "appsignal/integrations/net_http"
|
|
2
2
|
|
3
3
|
describe Appsignal::Integrations::NetHttpIntegration do
|
4
4
|
let(:transaction) { http_request_transaction }
|
5
|
-
before
|
5
|
+
before { start_agent }
|
6
6
|
before { set_current_transaction transaction }
|
7
7
|
around { |example| keep_transactions { example.run } }
|
8
8
|
|
@@ -29,7 +29,6 @@ describe Object do
|
|
29
29
|
start_agent
|
30
30
|
set_current_transaction(transaction)
|
31
31
|
end
|
32
|
-
after { Appsignal.config = nil }
|
33
32
|
|
34
33
|
context "with different kind of arguments" do
|
35
34
|
let(:klass) do
|
@@ -195,10 +194,9 @@ describe Object do
|
|
195
194
|
context "when active" do
|
196
195
|
let(:transaction) { http_request_transaction }
|
197
196
|
before do
|
198
|
-
|
197
|
+
start_agent
|
199
198
|
set_current_transaction(transaction)
|
200
199
|
end
|
201
|
-
after { Appsignal.config = nil }
|
202
200
|
|
203
201
|
context "with different kind of arguments" do
|
204
202
|
let(:klass) do
|
@@ -1,337 +1,15 @@
|
|
1
1
|
if DependencyHelper.padrino_present?
|
2
2
|
describe "Padrino integration" do
|
3
|
-
|
3
|
+
it "loads the Padrino loader" do
|
4
|
+
ENV["APPSIGNAL_APP_NAME"] = "test/sinatra"
|
5
|
+
ENV["APPSIGNAL_PUSH_API_KEY"] = "test-key"
|
4
6
|
|
5
|
-
|
6
|
-
let(:callbacks) { { :before_load => nil } }
|
7
|
-
before do
|
8
|
-
Appsignal.config = nil
|
9
|
-
allow(Padrino).to receive(:before_load)
|
10
|
-
.and_wrap_original do |original_method, *args, &block|
|
11
|
-
callbacks[:before_load] = block
|
12
|
-
original_method.call(*args, &block)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
after { uninstall_padrino_integration }
|
7
|
+
require "appsignal/integrations/padrino"
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
]
|
22
|
-
Padrino.middleware.delete_if do |middleware|
|
23
|
-
expected_middleware.include?(middleware.first)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "when already active" do
|
28
|
-
before { allow(Appsignal).to receive(:active?).and_return(true) }
|
29
|
-
|
30
|
-
it "does not start AppSignal again" do
|
31
|
-
expect(Appsignal::Config).to_not receive(:new)
|
32
|
-
expect(Appsignal).to_not receive(:start)
|
33
|
-
|
34
|
-
Appsignal::Integrations::PadrinoPlugin.init
|
35
|
-
callbacks[:before_load].call
|
36
|
-
end
|
37
|
-
|
38
|
-
it "adds the instrumentation middleware to Sinatra::Base" do
|
39
|
-
Appsignal::Integrations::PadrinoPlugin.init
|
40
|
-
callbacks[:before_load].call
|
41
|
-
|
42
|
-
middlewares = Padrino.middleware
|
43
|
-
expect(middlewares).to include(
|
44
|
-
[Rack::Events, [[instance_of(Appsignal::Rack::EventHandler)]], nil]
|
45
|
-
)
|
46
|
-
expect(middlewares).to include(
|
47
|
-
[
|
48
|
-
Appsignal::Rack::SinatraBaseInstrumentation,
|
49
|
-
[
|
50
|
-
:instrument_event_name => "process_action.padrino"
|
51
|
-
],
|
52
|
-
nil
|
53
|
-
]
|
54
|
-
)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "with active config" do
|
59
|
-
before do
|
60
|
-
ENV["APPSIGNAL_APP_NAME"] = "My Padrino app name"
|
61
|
-
ENV["APPSIGNAL_APP_ENV"] = "test"
|
62
|
-
ENV["APPSIGNAL_PUSH_API_KEY"] = "my-key"
|
63
|
-
end
|
64
|
-
|
65
|
-
it "starts AppSignal on init" do
|
66
|
-
expect(Appsignal).to_not be_active
|
67
|
-
|
68
|
-
Appsignal::Integrations::PadrinoPlugin.init
|
69
|
-
callbacks[:before_load].call
|
70
|
-
|
71
|
-
expect(Appsignal).to be_active
|
72
|
-
middlewares = Padrino.middleware
|
73
|
-
expect(middlewares).to include(
|
74
|
-
[Rack::Events, [[instance_of(Appsignal::Rack::EventHandler)]], nil]
|
75
|
-
)
|
76
|
-
expect(middlewares).to include(
|
77
|
-
[
|
78
|
-
Appsignal::Rack::SinatraBaseInstrumentation,
|
79
|
-
[
|
80
|
-
:instrument_event_name => "process_action.padrino"
|
81
|
-
],
|
82
|
-
nil
|
83
|
-
]
|
84
|
-
)
|
85
|
-
end
|
86
|
-
|
87
|
-
context "when APPSIGNAL_APP_ENV ENV var is provided" do
|
88
|
-
it "uses this as the environment" do
|
89
|
-
ENV["APPSIGNAL_APP_ENV"] = "custom"
|
90
|
-
|
91
|
-
Appsignal::Integrations::PadrinoPlugin.init
|
92
|
-
callbacks[:before_load].call
|
93
|
-
|
94
|
-
expect(Appsignal.config.env).to eq("custom")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context "when APPSIGNAL_APP_ENV ENV var is not provided" do
|
99
|
-
it "uses the Padrino environment" do
|
100
|
-
Appsignal::Integrations::PadrinoPlugin.init
|
101
|
-
callbacks[:before_load].call
|
102
|
-
|
103
|
-
expect(Padrino.env.to_s).to eq("test")
|
104
|
-
expect(Appsignal.config.env).to eq(Padrino.env.to_s)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "when not active" do
|
110
|
-
it "does not add the listener middleware to the stack" do
|
111
|
-
expect(Appsignal).to_not be_active
|
112
|
-
|
113
|
-
Appsignal::Integrations::PadrinoPlugin.init
|
114
|
-
callbacks[:before_load].call
|
115
|
-
|
116
|
-
expect(Appsignal).to_not be_active
|
117
|
-
middlewares = Padrino.middleware
|
118
|
-
expect(middlewares).to_not include(
|
119
|
-
[Rack::Events, [[instance_of(Appsignal::Rack::EventHandler)]], nil]
|
120
|
-
)
|
121
|
-
expect(middlewares).to_not include(
|
122
|
-
[
|
123
|
-
Appsignal::Rack::SinatraBaseInstrumentation,
|
124
|
-
[
|
125
|
-
:request_class => ::Sinatra::Request,
|
126
|
-
:instrument_event_name => "process_action.padrino"
|
127
|
-
],
|
128
|
-
nil
|
129
|
-
]
|
130
|
-
)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
describe Padrino::Routing::InstanceMethods do
|
136
|
-
class PadrinoClassWithRouter
|
137
|
-
include Padrino::Routing
|
138
|
-
end
|
139
|
-
|
140
|
-
let(:base) { double }
|
141
|
-
let(:router) { PadrinoClassWithRouter.new }
|
142
|
-
let(:env) { {} }
|
143
|
-
# TODO: use an instance double
|
144
|
-
let(:settings) { double(:name => "TestApp") }
|
145
|
-
around { |example| keep_transactions { example.run } }
|
146
|
-
before { Appsignal.config = nil }
|
147
|
-
|
148
|
-
describe "routes" do
|
149
|
-
let(:env) do
|
150
|
-
{
|
151
|
-
"REQUEST_METHOD" => "GET",
|
152
|
-
"PATH_INFO" => path,
|
153
|
-
"REQUEST_PATH" => path,
|
154
|
-
"rack.input" => StringIO.new
|
155
|
-
}
|
156
|
-
end
|
157
|
-
let(:app) do
|
158
|
-
Class.new(Padrino::Application) do
|
159
|
-
def self.name
|
160
|
-
"PadrinoTestApp"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
let(:response) { app.call(env) }
|
165
|
-
|
166
|
-
RSpec::Matchers.define :match_response do |expected_status, expected_content|
|
167
|
-
match do |response|
|
168
|
-
status, _headers, content = response
|
169
|
-
matches_content =
|
170
|
-
if expected_content.is_a?(Regexp)
|
171
|
-
content.join =~ expected_content
|
172
|
-
else
|
173
|
-
content == [expected_content].compact
|
174
|
-
end
|
175
|
-
status == expected_status && matches_content
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context "when AppSignal is not active" do
|
180
|
-
let(:path) { "/foo" }
|
181
|
-
before { app.controllers { get(:foo) { "content" } } }
|
182
|
-
|
183
|
-
it "does not instrument the request" do
|
184
|
-
expect do
|
185
|
-
expect(response).to match_response(200, "content")
|
186
|
-
end.to_not(change { created_transactions.count })
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context "when AppSignal is active" do
|
191
|
-
let(:transaction) { http_request_transaction }
|
192
|
-
before do
|
193
|
-
start_agent
|
194
|
-
set_current_transaction(transaction)
|
195
|
-
end
|
196
|
-
|
197
|
-
context "with not existing route" do
|
198
|
-
let(:path) { "/404" }
|
199
|
-
|
200
|
-
it "instruments the request" do
|
201
|
-
expect(response).to match_response(404, /^GET /404/)
|
202
|
-
expect(last_transaction).to have_action("PadrinoTestApp#unknown")
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
context "when Sinatra tells us it's a static file" do
|
207
|
-
let(:path) { "/static" }
|
208
|
-
before do
|
209
|
-
env["sinatra.static_file"] = true
|
210
|
-
app.controllers { get(:static) { "Static!" } }
|
211
|
-
end
|
212
|
-
|
213
|
-
it "does not instrument the request" do
|
214
|
-
expect(response).to match_response(200, "Static!")
|
215
|
-
expect(last_transaction).to_not have_action
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
# Older Padrino versions don't support `action` (v11.0+)
|
220
|
-
context "without #action on Sinatra::Request" do
|
221
|
-
let(:path) { "/my_original_path/10" }
|
222
|
-
before do
|
223
|
-
allow_any_instance_of(Sinatra::Request).to receive(:action).and_return(nil)
|
224
|
-
app.controllers { get(:my_original_path, :with => :id) { "content" } }
|
225
|
-
end
|
226
|
-
|
227
|
-
it "falls back on Sinatra::Request#route_obj.original_path" do
|
228
|
-
expect(response).to match_response(200, "content")
|
229
|
-
expect(last_transaction).to have_action("PadrinoTestApp:/my_original_path/:id")
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context "without Sinatra::Request#route_obj.original_path" do
|
234
|
-
let(:path) { "/my_original_path" }
|
235
|
-
before do
|
236
|
-
allow_any_instance_of(Sinatra::Request).to receive(:action).and_return(nil)
|
237
|
-
allow_any_instance_of(Sinatra::Request).to receive(:route_obj).and_return(nil)
|
238
|
-
app.controllers { get(:my_original_path) { "content" } }
|
239
|
-
end
|
240
|
-
|
241
|
-
it "falls back on app name" do
|
242
|
-
expect(response).to match_response(200, "content")
|
243
|
-
expect(last_transaction).to have_action("PadrinoTestApp#unknown")
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
context "with existing route" do
|
248
|
-
let(:path) { "/" }
|
249
|
-
def make_request
|
250
|
-
expect(response).to match_response(200, "content")
|
251
|
-
end
|
252
|
-
|
253
|
-
context "with action name as symbol" do
|
254
|
-
context "with :index helper" do
|
255
|
-
before do
|
256
|
-
# :index == "/"
|
257
|
-
app.controllers { get(:index) { "content" } }
|
258
|
-
end
|
259
|
-
|
260
|
-
it "sets the action with the app name and action name" do
|
261
|
-
make_request
|
262
|
-
expect(last_transaction).to have_action("PadrinoTestApp:#index")
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
context "with custom action name" do
|
267
|
-
let(:path) { "/foo" }
|
268
|
-
before do
|
269
|
-
app.controllers { get(:foo) { "content" } }
|
270
|
-
end
|
271
|
-
|
272
|
-
it "sets the action with the app name and action name" do
|
273
|
-
make_request
|
274
|
-
expect(last_transaction).to have_action("PadrinoTestApp:#foo")
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
context "with an action defined with a path" do
|
280
|
-
context "with root path" do
|
281
|
-
before do
|
282
|
-
# :index == "/"
|
283
|
-
app.controllers { get("/") { "content" } }
|
284
|
-
end
|
285
|
-
|
286
|
-
it "sets the action with the app name and action path" do
|
287
|
-
make_request
|
288
|
-
expect(last_transaction).to have_action("PadrinoTestApp:#/")
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context "with custom path" do
|
293
|
-
let(:path) { "/foo" }
|
294
|
-
before do
|
295
|
-
app.controllers { get("/foo") { "content" } }
|
296
|
-
end
|
297
|
-
|
298
|
-
it "sets the action with the app name and action path" do
|
299
|
-
make_request
|
300
|
-
expect(last_transaction).to have_action("PadrinoTestApp:#/foo")
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
context "with controller" do
|
306
|
-
let(:path) { "/my_controller" }
|
307
|
-
|
308
|
-
context "with controller as name" do
|
309
|
-
before do
|
310
|
-
# :index == "/"
|
311
|
-
app.controllers(:my_controller) { get(:index) { "content" } }
|
312
|
-
end
|
313
|
-
|
314
|
-
it "sets the action with the app name, controller name and action name" do
|
315
|
-
make_request
|
316
|
-
expect(last_transaction).to have_action("PadrinoTestApp:my_controller#index")
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
context "with controller as path" do
|
321
|
-
before do
|
322
|
-
# :index == "/"
|
323
|
-
app.controllers("/my_controller") { get(:index) { "content" } }
|
324
|
-
end
|
325
|
-
|
326
|
-
it "sets the action with the app name, controller name and action path" do
|
327
|
-
make_request
|
328
|
-
expect(last_transaction).to have_action("PadrinoTestApp:/my_controller#index")
|
329
|
-
end
|
330
|
-
end
|
331
|
-
end
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|
9
|
+
expect(Appsignal::Loaders.instances).to include(
|
10
|
+
:padrino => kind_of(Appsignal::Loaders::PadrinoLoader)
|
11
|
+
)
|
12
|
+
expect(Appsignal.active?).to be(true)
|
335
13
|
end
|
336
14
|
end
|
337
15
|
end
|
@@ -39,7 +39,6 @@ if DependencyHelper.que_present?
|
|
39
39
|
allow(Que).to receive(:execute)
|
40
40
|
|
41
41
|
start_agent
|
42
|
-
expect(Appsignal.active?).to be_truthy
|
43
42
|
end
|
44
43
|
around { |example| keep_transactions { example.run } }
|
45
44
|
|
@@ -66,7 +65,7 @@ if DependencyHelper.que_present?
|
|
66
65
|
"title" => ""
|
67
66
|
)
|
68
67
|
expect(transaction).to include_params(%w[1 birds])
|
69
|
-
expect(transaction).to
|
68
|
+
expect(transaction).to include_tags(
|
70
69
|
"attempts" => 0,
|
71
70
|
"id" => 123,
|
72
71
|
"priority" => 100,
|
@@ -95,7 +94,7 @@ if DependencyHelper.que_present?
|
|
95
94
|
expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
|
96
95
|
expect(transaction).to have_error(error.class.name, error.message)
|
97
96
|
expect(transaction).to include_params(%w[1 birds])
|
98
|
-
expect(transaction).to
|
97
|
+
expect(transaction).to include_tags(
|
99
98
|
"attempts" => 0,
|
100
99
|
"id" => 123,
|
101
100
|
"priority" => 100,
|
@@ -120,7 +119,7 @@ if DependencyHelper.que_present?
|
|
120
119
|
expect(transaction).to have_namespace(Appsignal::Transaction::BACKGROUND_JOB)
|
121
120
|
expect(transaction).to have_error(error.class.name, error.message)
|
122
121
|
expect(transaction).to include_params(%w[1 birds])
|
123
|
-
expect(transaction).to
|
122
|
+
expect(transaction).to include_tags(
|
124
123
|
"attempts" => 0,
|
125
124
|
"id" => 123,
|
126
125
|
"priority" => 100,
|