appsignal 2.4.0 → 2.4.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_todo.yml +1 -1
- data/.travis.yml +1 -0
- data/CHANGELOG.md +8 -0
- data/Rakefile +1 -0
- data/ext/extconf.rb +10 -9
- data/gemfiles/que.gemfile +5 -0
- data/lib/appsignal/cli/diagnose.rb +3 -1
- data/lib/appsignal/hooks.rb +1 -0
- data/lib/appsignal/hooks/que.rb +21 -0
- data/lib/appsignal/hooks/sidekiq.rb +119 -39
- data/lib/appsignal/integrations/que.rb +43 -0
- data/lib/appsignal/system.rb +54 -0
- data/lib/appsignal/transaction.rb +7 -0
- data/lib/appsignal/version.rb +1 -1
- data/spec/lib/appsignal/cli/diagnose_spec.rb +2 -0
- data/spec/lib/appsignal/hooks/que_spec.rb +19 -0
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +336 -176
- data/spec/lib/appsignal/integrations/que_spec.rb +174 -0
- data/spec/lib/appsignal/system_spec.rb +111 -0
- data/spec/support/helpers/dependency_helper.rb +4 -0
- data/spec/support/helpers/log_helpers.rb +11 -6
- data/spec/support/helpers/transaction_helpers.rb +6 -0
- metadata +9 -2
data/lib/appsignal/version.rb
CHANGED
@@ -155,6 +155,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :report => true do
|
|
155
155
|
expect(output).to include \
|
156
156
|
"Gem version: #{Appsignal::VERSION}",
|
157
157
|
"Agent version: #{Appsignal::Extension.agent_version}",
|
158
|
+
"Agent platform: #{Appsignal::System.installed_agent_platform}",
|
158
159
|
"Gem install path: #{gem_path}"
|
159
160
|
end
|
160
161
|
|
@@ -164,6 +165,7 @@ describe Appsignal::CLI::Diagnose, :api_stub => true, :report => true do
|
|
164
165
|
"language" => "ruby",
|
165
166
|
"package_version" => Appsignal::VERSION,
|
166
167
|
"agent_version" => Appsignal::Extension.agent_version,
|
168
|
+
"agent_platform" => Appsignal::System.installed_agent_platform,
|
167
169
|
"package_install_path" => gem_path,
|
168
170
|
"extension_loaded" => true
|
169
171
|
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Appsignal::Hooks::QueHook do
|
2
|
+
if DependencyHelper.que_present?
|
3
|
+
describe "#dependencies_present?" do
|
4
|
+
subject { described_class.new.dependencies_present? }
|
5
|
+
|
6
|
+
it { is_expected.to be_truthy }
|
7
|
+
end
|
8
|
+
|
9
|
+
it "installs the QuePlugin" do
|
10
|
+
expect(Que::Job.included_modules).to include(Appsignal::Integrations::QuePlugin)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
describe "#dependencies_present?" do
|
14
|
+
subject { described_class.new.dependencies_present? }
|
15
|
+
|
16
|
+
it { is_expected.to be_falsy }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,259 +1,419 @@
|
|
1
|
-
describe Appsignal::Hooks::SidekiqPlugin do
|
2
|
-
|
3
|
-
|
4
|
-
let(:
|
5
|
-
let(:
|
1
|
+
describe Appsignal::Hooks::SidekiqPlugin, :with_yaml_parse_error => false do
|
2
|
+
class DelayedTestClass; end
|
3
|
+
|
4
|
+
let(:namespace) { Appsignal::Transaction::BACKGROUND_JOB }
|
5
|
+
let(:worker) { anything }
|
6
|
+
let(:queue) { anything }
|
7
|
+
let(:given_args) do
|
8
|
+
[
|
9
|
+
"foo",
|
10
|
+
{
|
11
|
+
:foo => "Foo",
|
12
|
+
:bar => "Bar",
|
13
|
+
"baz" => { 1 => :foo }
|
14
|
+
}
|
15
|
+
]
|
16
|
+
end
|
17
|
+
let(:expected_args) do
|
18
|
+
[
|
19
|
+
"foo",
|
20
|
+
{
|
21
|
+
"foo" => "Foo",
|
22
|
+
"bar" => "Bar",
|
23
|
+
"baz" => { "1" => "foo" }
|
24
|
+
}
|
25
|
+
]
|
26
|
+
end
|
27
|
+
let(:job_class) { "TestClass" }
|
6
28
|
let(:item) do
|
7
29
|
{
|
8
|
-
"
|
30
|
+
"jid" => "b4a577edbccf1d805744efa9",
|
31
|
+
"class" => job_class,
|
9
32
|
"retry_count" => 0,
|
10
33
|
"queue" => "default",
|
11
|
-
"
|
12
|
-
"
|
34
|
+
"created_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
35
|
+
"enqueued_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
36
|
+
"args" => given_args,
|
13
37
|
"extra" => "data"
|
14
38
|
}
|
15
39
|
end
|
16
40
|
let(:plugin) { Appsignal::Hooks::SidekiqPlugin.new }
|
17
|
-
|
41
|
+
let(:test_store) { {} }
|
42
|
+
let(:log) { StringIO.new }
|
18
43
|
before do
|
19
|
-
allow(Appsignal::Transaction).to receive(:current).and_return(current_transaction)
|
20
44
|
start_agent
|
45
|
+
Appsignal.logger = test_logger(log)
|
46
|
+
|
47
|
+
# Stub calls to extension, because that would remove the transaction
|
48
|
+
# from the extension.
|
49
|
+
allow_any_instance_of(Appsignal::Extension::Transaction).to receive(:finish).and_return(true)
|
50
|
+
allow_any_instance_of(Appsignal::Extension::Transaction).to receive(:complete)
|
51
|
+
|
52
|
+
# Stub removal of current transaction from current thread so we can fetch
|
53
|
+
# it later.
|
54
|
+
expect(Appsignal::Transaction).to receive(:clear_current_transaction!) do
|
55
|
+
transaction = Thread.current[:appsignal_transaction]
|
56
|
+
test_store[:transaction] = transaction if transaction
|
57
|
+
end
|
58
|
+
end
|
59
|
+
after :with_yaml_parse_error => false do
|
60
|
+
expect(log_contents(log)).to_not contains_log(:warn, "Unable to load YAML")
|
21
61
|
end
|
62
|
+
after { clear_current_transaction! }
|
22
63
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
64
|
+
shared_examples "sidekiq metadata" do
|
65
|
+
describe "internal Sidekiq job values" do
|
66
|
+
it "does not save internal Sidekiq values as metadata on transaction" do
|
67
|
+
perform_job
|
68
|
+
|
69
|
+
transaction_hash = transaction.to_h
|
70
|
+
expect(transaction_hash["metadata"].keys)
|
71
|
+
.to_not include(*Appsignal::Hooks::SidekiqPlugin::JOB_KEYS)
|
29
72
|
end
|
30
73
|
end
|
31
74
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
75
|
+
context "with parameter filtering" do
|
76
|
+
before do
|
77
|
+
Appsignal.config = project_fixture_config("production")
|
78
|
+
Appsignal.config[:filter_parameters] = ["foo"]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "filters selected arguments" do
|
82
|
+
perform_job
|
83
|
+
|
84
|
+
transaction_hash = transaction.to_h
|
85
|
+
expect(transaction_hash["sample_data"]).to include(
|
86
|
+
"params" => [
|
87
|
+
"foo",
|
88
|
+
{
|
89
|
+
"foo" => "[FILTERED]",
|
90
|
+
"bar" => "Bar",
|
91
|
+
"baz" => { "1" => "foo" }
|
92
|
+
}
|
93
|
+
]
|
94
|
+
)
|
95
|
+
end
|
46
96
|
end
|
47
97
|
|
48
|
-
context "with
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
:method => "perform",
|
53
|
-
:metadata => {
|
54
|
-
"retry_count" => "0",
|
55
|
-
"queue" => "default",
|
56
|
-
"extra" => "data"
|
57
|
-
},
|
58
|
-
:params => {
|
59
|
-
:foo => "Foo",
|
60
|
-
:bar => "Bar"
|
61
|
-
},
|
62
|
-
:queue_start => Time.parse("01-01-2001 10:00:00UTC"),
|
63
|
-
:queue_time => 60_000.to_f
|
64
|
-
}
|
98
|
+
context "with encrypted arguments" do
|
99
|
+
before do
|
100
|
+
item["encrypt"] = true
|
101
|
+
item["args"] << "super secret value" # Last argument will be replaced
|
65
102
|
end
|
66
|
-
|
103
|
+
|
104
|
+
it "replaces the last argument (the secret bag) with an [encrypted data] string" do
|
105
|
+
perform_job
|
106
|
+
|
107
|
+
transaction_hash = transaction.to_h
|
108
|
+
expect(transaction_hash["sample_data"]).to include(
|
109
|
+
"params" => expected_args << "[encrypted data]"
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when using the Sidekiq delayed extension" do
|
115
|
+
let(:item) do
|
67
116
|
{
|
68
|
-
|
69
|
-
|
117
|
+
"jid" => "efb140489485999d32b5504c",
|
118
|
+
"class" => "Sidekiq::Extensions::DelayedClass",
|
119
|
+
"queue" => "default",
|
120
|
+
"args" => [
|
121
|
+
"---\n- !ruby/class 'DelayedTestClass'\n- :foo_method\n- - :bar: baz\n"
|
122
|
+
],
|
123
|
+
"retry" => true,
|
124
|
+
"created_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
125
|
+
"enqueued_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
126
|
+
"extra" => "data"
|
70
127
|
}
|
71
128
|
end
|
72
129
|
|
73
|
-
it "
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
}
|
81
|
-
)
|
130
|
+
it "uses the delayed class and method name for the action" do
|
131
|
+
perform_job
|
132
|
+
|
133
|
+
transaction_hash = transaction.to_h
|
134
|
+
expect(transaction_hash["action"]).to eq("DelayedTestClass.foo_method")
|
135
|
+
expect(transaction_hash["sample_data"]).to include(
|
136
|
+
"params" => ["bar" => "baz"]
|
82
137
|
)
|
83
138
|
end
|
84
139
|
|
85
|
-
context "
|
86
|
-
before
|
87
|
-
Appsignal.config = project_fixture_config("production")
|
88
|
-
Appsignal.config[:filter_parameters] = ["foo"]
|
89
|
-
end
|
140
|
+
context "when job arguments is a malformed YAML object", :with_yaml_parse_error => true do
|
141
|
+
before { item["args"] = [] }
|
90
142
|
|
91
|
-
it "
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
99
|
-
)
|
100
|
-
)
|
143
|
+
it "logs a warning and uses the default argument" do
|
144
|
+
perform_job
|
145
|
+
|
146
|
+
transaction_hash = transaction.to_h
|
147
|
+
expect(transaction_hash["action"]).to eq("Sidekiq::Extensions::DelayedClass#perform")
|
148
|
+
expect(transaction_hash["sample_data"]).to include("params" => [])
|
149
|
+
expect(log_contents(log)).to contains_log(:warn, "Unable to load YAML")
|
101
150
|
end
|
102
151
|
end
|
103
152
|
end
|
104
153
|
|
105
|
-
context "when
|
154
|
+
context "when using ActiveJob" do
|
106
155
|
let(:item) do
|
107
156
|
{
|
108
157
|
"class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper",
|
109
|
-
"wrapped" => "
|
158
|
+
"wrapped" => "ActiveJobTestClass",
|
110
159
|
"queue" => "default",
|
111
160
|
"args" => [{
|
112
|
-
"job_class" => "
|
161
|
+
"job_class" => "ActiveJobTestJob",
|
113
162
|
"job_id" => "23e79d48-6966-40d0-b2d4-f7938463a263",
|
114
163
|
"queue_name" => "default",
|
115
|
-
"arguments" =>
|
164
|
+
"arguments" => [
|
165
|
+
"foo", { "foo" => "Foo", "bar" => "Bar", "baz" => { 1 => :bar } }
|
166
|
+
]
|
116
167
|
}],
|
117
168
|
"retry" => true,
|
118
169
|
"jid" => "efb140489485999d32b5504c",
|
119
|
-
"created_at" => Time.parse("01-01
|
120
|
-
"enqueued_at" => Time.parse("01-01
|
170
|
+
"created_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
171
|
+
"enqueued_at" => Time.parse("2001-01-01 10:00:00UTC").to_f
|
121
172
|
}
|
122
173
|
end
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
174
|
+
|
175
|
+
it "creates a transaction with events" do
|
176
|
+
perform_job
|
177
|
+
|
178
|
+
transaction_hash = transaction.to_h
|
179
|
+
expect(transaction_hash).to include(
|
180
|
+
"id" => kind_of(String),
|
181
|
+
"action" => "ActiveJobTestClass#perform",
|
182
|
+
"error" => nil,
|
183
|
+
"namespace" => namespace,
|
184
|
+
"metadata" => {
|
128
185
|
"queue" => "default"
|
129
186
|
},
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
187
|
+
"sample_data" => {
|
188
|
+
"environment" => {},
|
189
|
+
"params" => [
|
190
|
+
"foo",
|
191
|
+
{
|
192
|
+
"foo" => "Foo",
|
193
|
+
"bar" => "Bar",
|
194
|
+
"baz" => { "1" => "bar" }
|
195
|
+
}
|
196
|
+
],
|
197
|
+
"tags" => {}
|
198
|
+
}
|
139
199
|
)
|
200
|
+
# TODO: Not available in transaction.to_h yet.
|
201
|
+
# https://github.com/appsignal/appsignal-agent/issues/293
|
202
|
+
expect(transaction.request.env).to eq(
|
203
|
+
:queue_start => Time.parse("2001-01-01 10:00:00UTC").to_f
|
204
|
+
)
|
205
|
+
expect_transaction_to_have_sidekiq_event(transaction_hash)
|
140
206
|
end
|
141
207
|
|
142
|
-
context "with
|
143
|
-
let(:
|
208
|
+
context "with ActionMailer job" do
|
209
|
+
let(:item) do
|
144
210
|
{
|
145
|
-
|
146
|
-
|
211
|
+
"class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper",
|
212
|
+
"wrapped" => "ActionMailer::DeliveryJob",
|
213
|
+
"queue" => "default",
|
214
|
+
"args" => [{
|
215
|
+
"job_class" => "ActiveMailerTestJob",
|
216
|
+
"job_id" => "23e79d48-6966-40d0-b2d4-f7938463a263",
|
217
|
+
"queue_name" => "default",
|
218
|
+
"arguments" => [
|
219
|
+
"MailerClass", "mailer_method", "deliver_now",
|
220
|
+
"foo", { "foo" => "Foo", "bar" => "Bar", "baz" => { 1 => :bar } }
|
221
|
+
]
|
222
|
+
}],
|
223
|
+
"retry" => true,
|
224
|
+
"jid" => "efb140489485999d32b5504c",
|
225
|
+
"created_at" => Time.parse("2001-01-01 10:00:00UTC").to_f,
|
226
|
+
"enqueued_at" => Time.parse("2001-01-01 10:00:00UTC").to_f
|
147
227
|
}
|
148
228
|
end
|
149
229
|
|
150
|
-
it "
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
230
|
+
it "creates a transaction for the ActionMailer class" do
|
231
|
+
perform_job
|
232
|
+
|
233
|
+
transaction_hash = transaction.to_h
|
234
|
+
expect(transaction_hash).to include(
|
235
|
+
"id" => kind_of(String),
|
236
|
+
"action" => "MailerClass#mailer_method",
|
237
|
+
"error" => nil,
|
238
|
+
"namespace" => namespace,
|
239
|
+
"metadata" => {
|
240
|
+
"queue" => "default"
|
241
|
+
},
|
242
|
+
"sample_data" => {
|
243
|
+
"environment" => {},
|
244
|
+
"params" => [
|
245
|
+
"foo",
|
246
|
+
{
|
247
|
+
"foo" => "Foo",
|
248
|
+
"bar" => "Bar",
|
249
|
+
"baz" => { "1" => "bar" }
|
250
|
+
}
|
251
|
+
],
|
252
|
+
"tags" => {}
|
253
|
+
}
|
159
254
|
)
|
160
255
|
end
|
256
|
+
end
|
161
257
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
258
|
+
context "with parameter filtering" do
|
259
|
+
before do
|
260
|
+
Appsignal.config = project_fixture_config("production")
|
261
|
+
Appsignal.config[:filter_parameters] = ["foo"]
|
262
|
+
end
|
263
|
+
|
264
|
+
it "filters selected arguments" do
|
265
|
+
perform_job
|
266
|
+
|
267
|
+
transaction_hash = transaction.to_h
|
268
|
+
expect(transaction_hash["sample_data"]).to include(
|
269
|
+
"params" => [
|
270
|
+
"foo",
|
271
|
+
{
|
272
|
+
"foo" => "[FILTERED]",
|
273
|
+
"bar" => "Bar",
|
274
|
+
"baz" => { "1" => "bar" }
|
275
|
+
}
|
276
|
+
]
|
277
|
+
)
|
179
278
|
end
|
180
279
|
end
|
181
280
|
end
|
182
281
|
end
|
183
282
|
|
184
|
-
context "with an
|
283
|
+
context "with an error" do
|
185
284
|
let(:error) { ExampleException }
|
186
|
-
let(:transaction) do
|
187
|
-
Appsignal::Transaction.new(
|
188
|
-
SecureRandom.uuid,
|
189
|
-
Appsignal::Transaction::BACKGROUND_JOB,
|
190
|
-
Appsignal::Transaction::GenericRequest.new({})
|
191
|
-
)
|
192
|
-
end
|
193
|
-
before do
|
194
|
-
allow(Appsignal::Transaction).to receive(:current).and_return(transaction)
|
195
|
-
expect(Appsignal::Transaction).to receive(:create)
|
196
|
-
.with(
|
197
|
-
kind_of(String),
|
198
|
-
Appsignal::Transaction::BACKGROUND_JOB,
|
199
|
-
kind_of(Appsignal::Transaction::GenericRequest)
|
200
|
-
).and_return(transaction)
|
201
|
-
end
|
202
|
-
|
203
|
-
it "adds the error to the transaction" do
|
204
|
-
expect(transaction).to receive(:set_error).with(error)
|
205
|
-
expect(transaction).to receive(:complete)
|
206
|
-
end
|
207
285
|
|
208
|
-
|
286
|
+
it "creates a transaction and adds the error" do
|
209
287
|
expect do
|
210
|
-
|
211
|
-
Appsignal::Hooks::SidekiqPlugin.new.call(worker, item, queue) do
|
212
|
-
raise error
|
213
|
-
end
|
214
|
-
end
|
288
|
+
perform_job { raise error, "uh oh" }
|
215
289
|
end.to raise_error(error)
|
290
|
+
|
291
|
+
transaction_hash = transaction.to_h
|
292
|
+
expect(transaction_hash).to include(
|
293
|
+
"id" => kind_of(String),
|
294
|
+
"action" => "TestClass#perform",
|
295
|
+
"error" => {
|
296
|
+
"name" => "ExampleException",
|
297
|
+
"message" => "uh oh",
|
298
|
+
# TODO: backtrace should be an Array of Strings
|
299
|
+
# https://github.com/appsignal/appsignal-agent/issues/294
|
300
|
+
"backtrace" => kind_of(String)
|
301
|
+
},
|
302
|
+
"metadata" => {
|
303
|
+
"extra" => "data",
|
304
|
+
"queue" => "default",
|
305
|
+
"retry_count" => "0"
|
306
|
+
},
|
307
|
+
"namespace" => namespace,
|
308
|
+
"sample_data" => {
|
309
|
+
"environment" => {},
|
310
|
+
"params" => expected_args,
|
311
|
+
"tags" => {}
|
312
|
+
}
|
313
|
+
)
|
314
|
+
expect_transaction_to_have_sidekiq_event(transaction_hash)
|
216
315
|
end
|
316
|
+
|
317
|
+
include_examples "sidekiq metadata"
|
217
318
|
end
|
218
319
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
320
|
+
context "without an error" do
|
321
|
+
it "creates a transaction with events" do
|
322
|
+
perform_job
|
323
|
+
|
324
|
+
transaction_hash = transaction.to_h
|
325
|
+
expect(transaction_hash).to include(
|
326
|
+
"id" => kind_of(String),
|
327
|
+
"action" => "TestClass#perform",
|
328
|
+
"error" => nil,
|
329
|
+
"metadata" => {
|
330
|
+
"extra" => "data",
|
331
|
+
"queue" => "default",
|
332
|
+
"retry_count" => "0"
|
333
|
+
},
|
334
|
+
"namespace" => namespace,
|
335
|
+
"sample_data" => {
|
336
|
+
"environment" => {},
|
337
|
+
"params" => expected_args,
|
338
|
+
"tags" => {}
|
339
|
+
}
|
340
|
+
)
|
341
|
+
# TODO: Not available in transaction.to_h yet.
|
342
|
+
# https://github.com/appsignal/appsignal-agent/issues/293
|
343
|
+
expect(transaction.request.env).to eq(
|
344
|
+
:queue_start => Time.parse("2001-01-01 10:00:00UTC").to_f
|
345
|
+
)
|
346
|
+
expect_transaction_to_have_sidekiq_event(transaction_hash)
|
226
347
|
end
|
227
348
|
|
228
|
-
|
229
|
-
|
349
|
+
include_examples "sidekiq metadata"
|
350
|
+
end
|
351
|
+
|
352
|
+
def perform_job
|
353
|
+
Timecop.freeze(Time.parse("2001-01-01 10:01:00UTC")) do
|
354
|
+
plugin.call(worker, item, queue) do
|
355
|
+
yield if block_given?
|
356
|
+
end
|
230
357
|
end
|
231
358
|
end
|
359
|
+
|
360
|
+
def transaction
|
361
|
+
test_store[:transaction]
|
362
|
+
end
|
363
|
+
|
364
|
+
def expect_transaction_to_have_sidekiq_event(transaction_hash)
|
365
|
+
events = transaction_hash["events"]
|
366
|
+
expect(events.count).to eq(1)
|
367
|
+
expect(events.first).to include(
|
368
|
+
"name" => "perform_job.sidekiq",
|
369
|
+
"title" => "",
|
370
|
+
"count" => 1,
|
371
|
+
"body" => "",
|
372
|
+
"body_format" => Appsignal::EventFormatter::DEFAULT
|
373
|
+
)
|
374
|
+
end
|
232
375
|
end
|
233
376
|
|
234
377
|
describe Appsignal::Hooks::SidekiqHook do
|
235
|
-
|
236
|
-
|
237
|
-
module Sidekiq
|
238
|
-
def self.configure_server
|
239
|
-
end
|
240
|
-
end
|
241
|
-
Appsignal::Hooks::SidekiqHook.new.install
|
242
|
-
end
|
243
|
-
after(:context) { Object.send(:remove_const, :Sidekiq) }
|
378
|
+
describe "#dependencies_present?" do
|
379
|
+
subject { described_class.new.dependencies_present? }
|
244
380
|
|
245
|
-
|
246
|
-
|
381
|
+
context "when Sidekiq constant is found" do
|
382
|
+
before { Object.const_set("Sidekiq", 1) }
|
383
|
+
after { Object.send(:remove_const, "Sidekiq") }
|
247
384
|
|
248
385
|
it { is_expected.to be_truthy }
|
249
386
|
end
|
250
|
-
end
|
251
387
|
|
252
|
-
|
253
|
-
|
254
|
-
subject { described_class.new.dependencies_present? }
|
388
|
+
context "when Sidekiq constant is not found" do
|
389
|
+
before { Object.send(:remove_const, "Sidekiq") if defined?(Sidekiq) }
|
255
390
|
|
256
391
|
it { is_expected.to be_falsy }
|
257
392
|
end
|
258
393
|
end
|
394
|
+
|
395
|
+
describe "#install" do
|
396
|
+
before do
|
397
|
+
class Sidekiq
|
398
|
+
def self.middlewares
|
399
|
+
@middlewares ||= Set.new
|
400
|
+
end
|
401
|
+
|
402
|
+
def self.configure_server
|
403
|
+
yield self
|
404
|
+
end
|
405
|
+
|
406
|
+
def self.server_middleware
|
407
|
+
yield middlewares
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
411
|
+
after { Object.send(:remove_const, "Sidekiq") }
|
412
|
+
|
413
|
+
it "adds the AppSignal SidekiqPlugin to the Sidekiq middleware chain" do
|
414
|
+
described_class.new.install
|
415
|
+
|
416
|
+
expect(Sidekiq.middlewares).to include(Appsignal::Hooks::SidekiqPlugin)
|
417
|
+
end
|
418
|
+
end
|
259
419
|
end
|