appsignal 3.13.1 → 4.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +499 -487
  3. data/CHANGELOG.md +104 -7
  4. data/Rakefile +31 -7
  5. data/benchmark.rake +4 -6
  6. data/build_matrix.yml +45 -39
  7. data/ext/agent.rb +27 -27
  8. data/ext/appsignal_extension.c +25 -0
  9. data/gemfiles/rails-7.2.gemfile +11 -0
  10. data/lib/appsignal/check_in/cron.rb +2 -15
  11. data/lib/appsignal/cli/diagnose.rb +37 -28
  12. data/lib/appsignal/cli/install.rb +5 -1
  13. data/lib/appsignal/config.rb +57 -119
  14. data/lib/appsignal/demo.rb +2 -2
  15. data/lib/appsignal/extension/jruby.rb +14 -0
  16. data/lib/appsignal/helpers/instrumentation.rb +139 -417
  17. data/lib/appsignal/helpers/metrics.rb +0 -16
  18. data/lib/appsignal/hooks/action_cable.rb +8 -8
  19. data/lib/appsignal/hooks/active_job.rb +2 -2
  20. data/lib/appsignal/hooks/at_exit.rb +37 -0
  21. data/lib/appsignal/hooks.rb +1 -16
  22. data/lib/appsignal/integrations/action_cable.rb +2 -2
  23. data/lib/appsignal/integrations/capistrano/appsignal.cap +2 -4
  24. data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +1 -4
  25. data/lib/appsignal/integrations/delayed_job_plugin.rb +3 -3
  26. data/lib/appsignal/integrations/que.rb +2 -2
  27. data/lib/appsignal/integrations/railtie.rb +26 -59
  28. data/lib/appsignal/integrations/rake.rb +2 -2
  29. data/lib/appsignal/integrations/resque.rb +2 -2
  30. data/lib/appsignal/integrations/shoryuken.rb +4 -4
  31. data/lib/appsignal/integrations/sidekiq.rb +3 -3
  32. data/lib/appsignal/integrations/webmachine.rb +2 -2
  33. data/lib/appsignal/loaders.rb +1 -1
  34. data/lib/appsignal/probes.rb +0 -9
  35. data/lib/appsignal/rack/abstract_middleware.rb +4 -26
  36. data/lib/appsignal/rack/body_wrapper.rb +0 -12
  37. data/lib/appsignal/rack/event_handler.rb +4 -4
  38. data/lib/appsignal/rack/rails_instrumentation.rb +1 -1
  39. data/lib/appsignal/rack.rb +0 -25
  40. data/lib/appsignal/sample_data.rb +95 -0
  41. data/lib/appsignal/transaction.rb +235 -361
  42. data/lib/appsignal/utils/rails_helper.rb +4 -0
  43. data/lib/appsignal/version.rb +1 -1
  44. data/lib/appsignal.rb +19 -71
  45. data/spec/lib/appsignal/auth_check_spec.rb +1 -1
  46. data/spec/lib/appsignal/capistrano2_spec.rb +1 -1
  47. data/spec/lib/appsignal/capistrano3_spec.rb +53 -13
  48. data/spec/lib/appsignal/check_in_spec.rb +1 -207
  49. data/spec/lib/appsignal/cli/demo_spec.rb +7 -27
  50. data/spec/lib/appsignal/cli/diagnose_spec.rb +145 -110
  51. data/spec/lib/appsignal/config_spec.rb +304 -379
  52. data/spec/lib/appsignal/extension_install_failure_spec.rb +5 -1
  53. data/spec/lib/appsignal/extension_spec.rb +5 -1
  54. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +1 -1
  55. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +1 -2
  56. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +1 -0
  57. data/spec/lib/appsignal/hooks/activejob_spec.rb +7 -12
  58. data/spec/lib/appsignal/hooks/at_exit_spec.rb +72 -0
  59. data/spec/lib/appsignal/hooks/gvl_spec.rb +10 -5
  60. data/spec/lib/appsignal/hooks/http_spec.rb +3 -3
  61. data/spec/lib/appsignal/hooks/net_http_spec.rb +3 -3
  62. data/spec/lib/appsignal/hooks/rake_spec.rb +6 -9
  63. data/spec/lib/appsignal/hooks/redis_client_spec.rb +5 -10
  64. data/spec/lib/appsignal/hooks/redis_spec.rb +4 -7
  65. data/spec/lib/appsignal/hooks/resque_spec.rb +3 -5
  66. data/spec/lib/appsignal/hooks_spec.rb +0 -41
  67. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +29 -20
  68. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +4 -9
  69. data/spec/lib/appsignal/integrations/railtie_spec.rb +179 -157
  70. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +3 -5
  71. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +48 -62
  72. data/spec/lib/appsignal/loaders/hanami_spec.rb +6 -9
  73. data/spec/lib/appsignal/loaders/padrino_spec.rb +6 -10
  74. data/spec/lib/appsignal/loaders/sinatra_spec.rb +6 -9
  75. data/spec/lib/appsignal/loaders_spec.rb +8 -1
  76. data/spec/lib/appsignal/marker_spec.rb +1 -1
  77. data/spec/lib/appsignal/probes_spec.rb +4 -83
  78. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +4 -63
  79. data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -48
  80. data/spec/lib/appsignal/rack/event_handler_spec.rb +18 -15
  81. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +3 -11
  82. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +4 -5
  83. data/spec/lib/appsignal/sample_data_spec.rb +174 -0
  84. data/spec/lib/appsignal/transaction_spec.rb +791 -1031
  85. data/spec/lib/appsignal/transmitter_spec.rb +6 -8
  86. data/spec/lib/appsignal_spec.rb +294 -643
  87. data/spec/spec_helper.rb +1 -3
  88. data/spec/support/fixtures/projects/valid/config/appsignal.yml +4 -7
  89. data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +16 -0
  90. data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +56 -0
  91. data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +5 -0
  92. data/spec/support/helpers/api_request_helper.rb +3 -2
  93. data/spec/support/helpers/config_helpers.rb +41 -11
  94. data/spec/support/helpers/dependency_helper.rb +8 -0
  95. data/spec/support/helpers/log_helpers.rb +1 -0
  96. data/spec/support/helpers/rails_helper.rb +6 -6
  97. data/spec/support/helpers/transaction_helpers.rb +2 -24
  98. data/spec/support/matchers/transaction.rb +3 -3
  99. data/spec/support/mocks/appsignal_mock.rb +3 -3
  100. data/spec/support/mocks/mock_probe.rb +2 -0
  101. data/spec/support/testing.rb +2 -2
  102. metadata +11 -21
  103. data/gemfiles/que_beta.gemfile +0 -5
  104. data/lib/appsignal/helpers/heartbeat.rb +0 -20
  105. data/lib/appsignal/integrations/grape.rb +0 -35
  106. data/lib/appsignal/integrations/hanami.rb +0 -13
  107. data/lib/appsignal/integrations/padrino.rb +0 -13
  108. data/lib/appsignal/integrations/sinatra.rb +0 -13
  109. data/lib/appsignal/rack/generic_instrumentation.rb +0 -22
  110. data/lib/appsignal/rack/streaming_listener.rb +0 -28
  111. data/spec/lib/appsignal/integrations/grape_spec.rb +0 -36
  112. data/spec/lib/appsignal/integrations/hanami_spec.rb +0 -17
  113. data/spec/lib/appsignal/integrations/padrino_spec.rb +0 -15
  114. data/spec/lib/appsignal/integrations/sinatra_spec.rb +0 -15
  115. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +0 -81
  116. data/spec/lib/appsignal/rack/streaming_listener_spec.rb +0 -69
  117. data/spec/support/fixtures/projects/valid/config/environments/development.rb +0 -0
  118. data/spec/support/fixtures/projects/valid/config/environments/production.rb +0 -0
  119. data/spec/support/fixtures/projects/valid/config/environments/test.rb +0 -0
  120. data/spec/support/rails/my_app.rb +0 -6
  121. /data/spec/support/fixtures/projects/{valid/config/application.rb → valid_with_rails_app/log/.gitkeep} +0 -0
@@ -1,7 +1,11 @@
1
1
  require "appsignal/integrations/sidekiq"
2
2
 
3
3
  describe Appsignal::Integrations::SidekiqDeathHandler do
4
- before { start_agent }
4
+ let(:options) { {} }
5
+ before do
6
+ stub_const("Sidekiq::VERSION", "7.1.0")
7
+ start_agent(:options => options)
8
+ end
5
9
  around { |example| keep_transactions { example.run } }
6
10
 
7
11
  let(:exception) do
@@ -28,10 +32,8 @@ describe Appsignal::Integrations::SidekiqDeathHandler do
28
32
  end
29
33
 
30
34
  context "when sidekiq_report_errors = none" do
31
- before do
32
- Appsignal.config[:sidekiq_report_errors] = "none"
33
- call_handler
34
- end
35
+ let(:options) { { :sidekiq_report_errors => "none" } }
36
+ before { call_handler }
35
37
 
36
38
  it "doesn't track the error on the transaction" do
37
39
  expect_no_error_on_transaction
@@ -39,10 +41,8 @@ describe Appsignal::Integrations::SidekiqDeathHandler do
39
41
  end
40
42
 
41
43
  context "when sidekiq_report_errors = all" do
42
- before do
43
- Appsignal.config[:sidekiq_report_errors] = "all"
44
- call_handler
45
- end
44
+ let(:options) { { :sidekiq_report_errors => "all" } }
45
+ before { call_handler }
46
46
 
47
47
  it "doesn't track the error on the transaction" do
48
48
  expect_no_error_on_transaction
@@ -50,10 +50,8 @@ describe Appsignal::Integrations::SidekiqDeathHandler do
50
50
  end
51
51
 
52
52
  context "when sidekiq_report_errors = discard" do
53
- before do
54
- Appsignal.config[:sidekiq_report_errors] = "discard"
55
- call_handler
56
- end
53
+ let(:options) { { :sidekiq_report_errors => "discard" } }
54
+ before { call_handler }
57
55
 
58
56
  it "records each occurrence of the error on the transaction" do
59
57
  expect_error_on_transaction
@@ -62,7 +60,8 @@ describe Appsignal::Integrations::SidekiqDeathHandler do
62
60
  end
63
61
 
64
62
  describe Appsignal::Integrations::SidekiqErrorHandler do
65
- before { start_agent }
63
+ let(:options) { {} }
64
+ before { start_agent(:options => options) }
66
65
  around { |example| keep_transactions { example.run } }
67
66
 
68
67
  let(:exception) do
@@ -96,7 +95,7 @@ describe Appsignal::Integrations::SidekiqErrorHandler do
96
95
  end
97
96
 
98
97
  context "when sidekiq_report_errors = none" do
99
- before { Appsignal.config[:sidekiq_report_errors] = "none" }
98
+ let(:options) { { :sidekiq_report_errors => "none" } }
100
99
 
101
100
  it "tracks the error on a new transaction" do
102
101
  expect_report_internal_error
@@ -104,7 +103,7 @@ describe Appsignal::Integrations::SidekiqErrorHandler do
104
103
  end
105
104
 
106
105
  context "when sidekiq_report_errors = all" do
107
- before { Appsignal.config[:sidekiq_report_errors] = "all" }
106
+ let(:options) { { :sidekiq_report_errors => "all" } }
108
107
 
109
108
  it "tracks the error on a new transaction" do
110
109
  expect_report_internal_error
@@ -112,7 +111,7 @@ describe Appsignal::Integrations::SidekiqErrorHandler do
112
111
  end
113
112
 
114
113
  context "when sidekiq_report_errors = discard" do
115
- before { Appsignal.config[:sidekiq_report_errors] = "discard" }
114
+ let(:options) { { :sidekiq_report_errors => "discard" } }
116
115
 
117
116
  it "tracks the error on a new transaction" do
118
117
  expect_report_internal_error
@@ -143,10 +142,8 @@ describe Appsignal::Integrations::SidekiqErrorHandler do
143
142
  end
144
143
 
145
144
  context "when sidekiq_report_errors = none" do
146
- before do
147
- Appsignal.config[:sidekiq_report_errors] = "none"
148
- call_handler
149
- end
145
+ let(:options) { { :sidekiq_report_errors => "none" } }
146
+ before { call_handler }
150
147
 
151
148
  it "doesn't track the error on the transaction" do
152
149
  expect_no_error_on_transaction
@@ -155,10 +152,8 @@ describe Appsignal::Integrations::SidekiqErrorHandler do
155
152
  end
156
153
 
157
154
  context "when sidekiq_report_errors = all" do
158
- before do
159
- Appsignal.config[:sidekiq_report_errors] = "all"
160
- call_handler
161
- end
155
+ let(:options) { { :sidekiq_report_errors => "all" } }
156
+ before { call_handler }
162
157
 
163
158
  it "records each occurrence of the error on the transaction" do
164
159
  expect_error_on_transaction
@@ -167,10 +162,8 @@ describe Appsignal::Integrations::SidekiqErrorHandler do
167
162
  end
168
163
 
169
164
  context "when sidekiq_report_errors = discard" do
170
- before do
171
- Appsignal.config[:sidekiq_report_errors] = "discard"
172
- call_handler
173
- end
165
+ let(:options) { { :sidekiq_report_errors => "discard" } }
166
+ before { call_handler }
174
167
 
175
168
  it "doesn't track the error on the transaction" do
176
169
  expect_no_error_on_transaction
@@ -180,7 +173,7 @@ describe Appsignal::Integrations::SidekiqErrorHandler do
180
173
  end
181
174
  end
182
175
 
183
- describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => false do
176
+ describe Appsignal::Integrations::SidekiqMiddleware do
184
177
  class DelayedTestClass; end
185
178
 
186
179
  let(:namespace) { Appsignal::Transaction::BACKGROUND_JOB }
@@ -221,14 +214,14 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
221
214
  }
222
215
  end
223
216
  let(:plugin) { Appsignal::Integrations::SidekiqMiddleware.new }
224
- let(:log) { StringIO.new }
217
+ let(:options) { {} }
225
218
  before do
226
- start_agent
227
- Appsignal.internal_logger = test_logger(log)
219
+ start_agent(:options => options)
228
220
  end
229
221
  around { |example| keep_transactions { example.run } }
230
- after :with_yaml_parse_error => false do
231
- expect(log_contents(log)).to_not contains_log(:warn, "Unable to load YAML")
222
+
223
+ def expect_no_yaml_parse_error(logs)
224
+ expect(logs).to_not contains_log(:warn, "Unable to load YAML")
232
225
  end
233
226
 
234
227
  describe "internal Sidekiq job values" do
@@ -242,10 +235,7 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
242
235
  end
243
236
 
244
237
  context "with parameter filtering" do
245
- before do
246
- start_agent("production")
247
- Appsignal.config[:filter_parameters] = ["foo"]
248
- end
238
+ let(:options) { { :filter_parameters => ["foo"] } }
249
239
 
250
240
  it "filters selected arguments" do
251
241
  perform_sidekiq_job
@@ -299,15 +289,15 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
299
289
  expect(transaction).to include_params(["bar" => "baz"])
300
290
  end
301
291
 
302
- context "when job arguments is a malformed YAML object", :with_yaml_parse_error => true do
292
+ context "when job arguments is a malformed YAML object" do
303
293
  before { item["args"] = [] }
304
294
 
305
295
  it "logs a warning and uses the default argument" do
306
- perform_sidekiq_job
296
+ logs = capture_logs { perform_sidekiq_job }
307
297
 
308
298
  expect(transaction).to have_action("Sidekiq::Extensions::DelayedClass#perform")
309
299
  expect(transaction).to include_params([])
310
- expect(log_contents(log)).to contains_log(:warn, "Unable to load YAML")
300
+ expect(logs).to contains_log(:warn, "Unable to load YAML")
311
301
  end
312
302
  end
313
303
  end
@@ -335,15 +325,15 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
335
325
  expect(transaction).to include_params(["bar" => "baz"])
336
326
  end
337
327
 
338
- context "when job arguments is a malformed YAML object", :with_yaml_parse_error => true do
328
+ context "when job arguments is a malformed YAML object" do
339
329
  before { item["args"] = [] }
340
330
 
341
331
  it "logs a warning and uses the default argument" do
342
- perform_sidekiq_job
332
+ logs = capture_logs { perform_sidekiq_job }
343
333
 
344
334
  expect(transaction).to have_action("Sidekiq::Extensions::DelayedModel#perform")
345
335
  expect(transaction).to include_params([])
346
- expect(log_contents(log)).to contains_log(:warn, "Unable to load YAML")
336
+ expect(logs).to contains_log(:warn, "Unable to load YAML")
347
337
  end
348
338
  end
349
339
  end
@@ -384,28 +374,24 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
384
374
  include RailsHelper
385
375
 
386
376
  it "reports the worker name as the action, copies the namespace and tags" do
387
- start_agent("production")
388
- with_rails_error_reporter do
389
- perform_sidekiq_job do
390
- Appsignal.tag_job("test_tag" => "value")
391
- Rails.error.handle do
392
- raise ExampleStandardError, "uh oh"
377
+ expect do
378
+ with_rails_error_reporter do
379
+ perform_sidekiq_job do
380
+ Appsignal.tag_job("test_tag" => "value")
381
+ Rails.error.handle do
382
+ raise ExampleStandardError, "error message"
383
+ end
393
384
  end
394
385
  end
395
- end
386
+ end.to change { created_transactions.count }.by(1)
396
387
 
397
- expect(created_transactions.count).to eq(2)
398
388
  tags = { "test_tag" => "value" }
399
- sidekiq_transaction = created_transactions.first
400
- error_reporter_transaction = created_transactions.last
401
-
402
- expect(sidekiq_transaction).to have_namespace("background_job")
403
- expect(sidekiq_transaction).to have_action("TestClass#perform")
404
- expect(sidekiq_transaction).to include_tags(tags)
389
+ transaction = last_transaction
405
390
 
406
- expect(error_reporter_transaction).to have_namespace("background_job")
407
- expect(error_reporter_transaction).to have_action("TestClass#perform")
408
- expect(error_reporter_transaction).to include_tags(tags)
391
+ expect(transaction).to have_namespace("background_job")
392
+ expect(transaction).to have_action("TestClass#perform")
393
+ expect(transaction).to have_error("ExampleStandardError", "error message")
394
+ expect(transaction).to include_tags(tags)
409
395
  end
410
396
  end
411
397
  end
@@ -1,18 +1,15 @@
1
1
  if DependencyHelper.hanami_present?
2
2
  describe "Appsignal::Loaders::HanamiLoader" do
3
- before { Appsignal.config = nil }
4
-
5
3
  describe "#on_load" do
6
4
  it "registers Hanami default config" do
7
5
  load_loader(:hanami)
8
6
 
9
- expect(Appsignal::Config.loader_defaults).to include([
10
- :hanami,
11
- {
12
- :env => :test,
13
- :root_path => Dir.pwd
14
- }
15
- ])
7
+ expect(Appsignal::Config.loader_defaults).to include(
8
+ :name => :hanami,
9
+ :root_path => Dir.pwd,
10
+ :env => :test,
11
+ :options => {}
12
+ )
16
13
  end
17
14
  end
18
15
 
@@ -1,18 +1,15 @@
1
1
  if DependencyHelper.padrino_present?
2
2
  describe "Appsignal::Loaders::PadrinoLoader" do
3
- before { Appsignal.config = nil }
4
-
5
3
  describe "#on_load" do
6
4
  it "registers Padrino default config" do
7
5
  load_loader(:padrino)
8
6
 
9
- expect(Appsignal::Config.loader_defaults).to include([
10
- :padrino,
11
- {
12
- :env => :test,
13
- :root_path => Padrino.mounted_root
14
- }
15
- ])
7
+ expect(Appsignal::Config.loader_defaults).to include(
8
+ :name => :padrino,
9
+ :root_path => Padrino.mounted_root,
10
+ :env => :test,
11
+ :options => {}
12
+ )
16
13
  end
17
14
  end
18
15
 
@@ -70,7 +67,6 @@ if DependencyHelper.padrino_present?
70
67
  # TODO: use an instance double
71
68
  let(:settings) { double(:name => "TestApp") }
72
69
  around { |example| keep_transactions { example.run } }
73
- before { Appsignal.config = nil }
74
70
 
75
71
  describe "routes" do
76
72
  let(:env) do
@@ -1,19 +1,16 @@
1
1
  if DependencyHelper.sinatra_present?
2
2
  describe "Appsignal::Loaders::SinatraLoader" do
3
- before { Appsignal.config = nil }
4
-
5
3
  describe "#on_load" do
6
4
  it "registers Sinatra default config" do
7
5
  ::Sinatra::Application.settings.root = "/some/path"
8
6
  load_loader(:sinatra)
9
7
 
10
- expect(Appsignal::Config.loader_defaults).to include([
11
- :sinatra,
12
- {
13
- :env => :test,
14
- :root_path => "/some/path"
15
- }
16
- ])
8
+ expect(Appsignal::Config.loader_defaults).to include(
9
+ :name => :sinatra,
10
+ :root_path => "/some/path",
11
+ :env => :test,
12
+ :options => {}
13
+ )
17
14
  end
18
15
  end
19
16
 
@@ -50,7 +50,14 @@ describe Appsignal::Loaders do
50
50
  end
51
51
  Appsignal::Loaders.load(:test_loader)
52
52
 
53
- expect(Appsignal::Config.loader_defaults).to eq([[:test_loader, { :my_option => true }]])
53
+ expect(Appsignal::Config.loader_defaults).to eq([
54
+ {
55
+ :name => :test_loader,
56
+ :env => nil,
57
+ :root_path => nil,
58
+ :options => { :my_option => true }
59
+ }
60
+ ])
54
61
  end
55
62
 
56
63
  it "does not load errors that aren't registered" do
@@ -1,5 +1,5 @@
1
1
  describe Appsignal::Marker do
2
- let(:config) { project_fixture_config }
2
+ let(:config) { build_config }
3
3
  let(:marker) do
4
4
  described_class.new(
5
5
  {
@@ -3,38 +3,6 @@ describe Appsignal::Probes do
3
3
 
4
4
  before { Appsignal::Probes.probes.clear }
5
5
 
6
- context "Minutely constant" do
7
- let(:err_stream) { std_stream }
8
- let(:stderr) { err_stream.read }
9
-
10
- it "returns the Probes constant calling the Minutely constant" do
11
- silence { expect(Appsignal::Minutely).to be(Appsignal::Probes) }
12
- end
13
-
14
- it "prints a deprecation warning to STDERR" do
15
- capture_std_streams(std_stream, err_stream) do
16
- expect(Appsignal::Minutely).to be(Appsignal::Probes)
17
- end
18
-
19
- expect(stderr)
20
- .to include("appsignal WARNING: The constant Appsignal::Minutely has been deprecated.")
21
- end
22
-
23
- it "logs a warning" do
24
- logs =
25
- capture_logs do
26
- silence do
27
- expect(Appsignal::Minutely).to be(Appsignal::Probes)
28
- end
29
- end
30
-
31
- expect(logs).to contains_log(
32
- :warn,
33
- "The constant Appsignal::Minutely has been deprecated."
34
- )
35
- end
36
- end
37
-
38
6
  it "returns a ProbeCollection" do
39
7
  expect(Appsignal::Probes.probes)
40
8
  .to be_instance_of(Appsignal::Probes::ProbeCollection)
@@ -128,12 +96,10 @@ describe Appsignal::Probes do
128
96
  context "with probe class" do
129
97
  it "creates an instance of the class and call that every <wait time>" do
130
98
  probe = MockProbe
131
- probe_instance = MockProbe.new
132
- expect(probe).to receive(:new).and_return(probe_instance)
133
99
  Appsignal::Probes.register :my_probe, probe
134
100
  Appsignal::Probes.start
135
101
 
136
- wait_for("enough probe calls") { probe_instance.calls >= 2 }
102
+ wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
137
103
  expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
138
104
  expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
139
105
  end
@@ -142,15 +108,13 @@ describe Appsignal::Probes do
142
108
  it "does not initialize the probe" do
143
109
  # Working probe which we can use to wait for X ticks
144
110
  working_probe = ProbeWithoutDependency
145
- working_probe_instance = working_probe.new
146
- expect(working_probe).to receive(:new).and_return(working_probe_instance)
147
111
  Appsignal::Probes.register :probe_without_dep, working_probe
148
112
 
149
113
  probe = ProbeWithMissingDependency
150
114
  Appsignal::Probes.register :probe_with_missing_dep, probe
151
115
  Appsignal::Probes.start
152
116
 
153
- wait_for("enough probe calls") { working_probe_instance.calls >= 2 }
117
+ wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
154
118
  # Only counts initialized probes
155
119
  expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
156
120
  expect(log).to contains_log :debug, "Skipping 'probe_with_missing_dep' probe, " \
@@ -162,15 +126,13 @@ describe Appsignal::Probes do
162
126
  it "logs an error" do
163
127
  # Working probe which we can use to wait for X ticks
164
128
  working_probe = ProbeWithoutDependency
165
- working_probe_instance = working_probe.new
166
- expect(working_probe).to receive(:new).and_return(working_probe_instance)
167
129
  Appsignal::Probes.register :probe_without_dep, working_probe
168
130
 
169
131
  probe = BrokenProbeOnInitialize
170
132
  Appsignal::Probes.register :broken_probe_on_initialize, probe
171
133
  Appsignal::Probes.start
172
134
 
173
- wait_for("enough probe calls") { working_probe_instance.calls >= 2 }
135
+ wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
174
136
  # Only counts initialized probes
175
137
  expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
176
138
  # Logs error
@@ -398,45 +360,6 @@ describe Appsignal::Probes do
398
360
  end
399
361
  end
400
362
 
401
- describe "#register" do
402
- it "adds the probe by key" do
403
- expect(Appsignal::Probes).to receive(:probes).and_return(collection)
404
-
405
- probe = lambda {}
406
- silence { collection.register :my_probe, probe }
407
- expect(collection[:my_probe]).to eql(probe)
408
- end
409
-
410
- context "logger" do
411
- before { start_agent }
412
-
413
- it "logs a deprecation message" do
414
- logs =
415
- capture_logs do
416
- silence { collection.register :my_probe, lambda {} }
417
- end
418
- expect(logs).to contains_log :warn,
419
- "The method 'Appsignal::Probes.probes.register' is deprecated. " \
420
- "Use 'Appsignal::Probes.register' instead."
421
- end
422
- end
423
-
424
- context "stderr" do
425
- let(:err_stream) { std_stream }
426
- let(:stderr) { err_stream.read }
427
-
428
- it "prints a deprecation warning" do
429
- capture_std_streams(std_stream, err_stream) do
430
- collection.register :my_probe, lambda {}
431
- end
432
- deprecation_message =
433
- "The method 'Appsignal::Probes.probes.register' is deprecated. " \
434
- "Use 'Appsignal::Probes.register' instead."
435
- expect(stderr).to include("appsignal WARNING: #{deprecation_message}")
436
- end
437
- end
438
- end
439
-
440
363
  describe "#internal_register" do
441
364
  let(:log_stream) { std_stream }
442
365
  let(:log) { log_contents(log_stream) }
@@ -463,10 +386,8 @@ describe Appsignal::Probes do
463
386
 
464
387
  describe "#unregister" do
465
388
  it "removes the probe from the collection" do
466
- expect(Appsignal::Probes).to receive(:probes).and_return(collection)
467
-
468
389
  probe = lambda {}
469
- silence { collection.register :my_probe, probe }
390
+ silence { collection.internal_register :my_probe, probe }
470
391
  expect(collection[:my_probe]).to eql(probe)
471
392
 
472
393
  silence { collection.unregister :my_probe }
@@ -9,10 +9,11 @@ describe Appsignal::Rack::AbstractMiddleware do
9
9
  "rack.session" => { "session" => "data", "user_id" => 123 }
10
10
  )
11
11
  end
12
- let(:options) { {} }
13
12
  let(:middleware) { described_class.new(app, options) }
14
13
 
15
- before { start_agent }
14
+ let(:appsignal_env) { :default }
15
+ let(:options) { {} }
16
+ before { start_agent(:env => appsignal_env) }
16
17
  around { |example| keep_transactions { example.run } }
17
18
 
18
19
  def make_request
@@ -25,7 +26,7 @@ describe Appsignal::Rack::AbstractMiddleware do
25
26
 
26
27
  describe "#call" do
27
28
  context "when not active" do
28
- before { allow(Appsignal).to receive(:active?).and_return(false) }
29
+ let(:appsignal_env) { :inactive_env }
29
30
 
30
31
  it "does not instrument the request" do
31
32
  expect { make_request }.to_not(change { created_transactions.count })
@@ -38,8 +39,6 @@ describe Appsignal::Rack::AbstractMiddleware do
38
39
  end
39
40
 
40
41
  context "when appsignal is active" do
41
- before { allow(Appsignal).to receive(:active?).and_return(true) }
42
-
43
42
  it "creates a transaction for the request" do
44
43
  expect { make_request }.to(change { created_transactions.count }.by(1))
45
44
 
@@ -165,64 +164,6 @@ describe Appsignal::Rack::AbstractMiddleware do
165
164
  end
166
165
  end
167
166
 
168
- context "with appsignal.route env" do
169
- before { env["appsignal.route"] = "POST /my-route" }
170
-
171
- it "reports the appsignal.route value as the action name" do
172
- make_request
173
-
174
- expect(last_transaction).to have_action("POST /my-route")
175
- end
176
-
177
- it "prints a deprecation warning" do
178
- err_stream = std_stream
179
- capture_std_streams(std_stream, err_stream) do
180
- make_request
181
- end
182
-
183
- expect(err_stream.read).to include(
184
- "Setting the action name with the request env 'appsignal.route' is deprecated."
185
- )
186
- end
187
-
188
- it "logs a deprecation warning" do
189
- logs = capture_logs { make_request }
190
- expect(logs).to contains_log(
191
- :warn,
192
- "Setting the action name with the request env 'appsignal.route' is deprecated."
193
- )
194
- end
195
- end
196
-
197
- context "with appsignal.action env" do
198
- before { env["appsignal.action"] = "POST /my-action" }
199
-
200
- it "reports the appsignal.action value as the action name" do
201
- make_request
202
-
203
- expect(last_transaction).to have_action("POST /my-action")
204
- end
205
-
206
- it "prints a deprecation warning" do
207
- err_stream = std_stream
208
- capture_std_streams(std_stream, err_stream) do
209
- make_request
210
- end
211
-
212
- expect(err_stream.read).to include(
213
- "Setting the action name with the request env 'appsignal.action' is deprecated."
214
- )
215
- end
216
-
217
- it "logs a deprecation warning" do
218
- logs = capture_logs { make_request }
219
- expect(logs).to contains_log(
220
- :warn,
221
- "Setting the action name with the request env 'appsignal.action' is deprecated."
222
- )
223
- end
224
- end
225
-
226
167
  describe "request metadata" do
227
168
  it "sets request metadata" do
228
169
  env.merge!("PATH_INFO" => "/some/path", "REQUEST_METHOD" => "GET")
@@ -72,18 +72,6 @@ describe Appsignal::Rack::BodyWrapper do
72
72
  expect(transaction).to have_error("ExampleException", "error message")
73
73
  end
74
74
 
75
- it "doesn't report EPIPE error" do
76
- fake_body = double
77
- expect(fake_body).to receive(:each).once.and_raise(Errno::EPIPE)
78
-
79
- wrapped = described_class.wrap(fake_body, transaction)
80
- expect do
81
- expect { |b| wrapped.each(&b) }.to yield_control
82
- end.to raise_error(Errno::EPIPE)
83
-
84
- expect(transaction).to_not have_error
85
- end
86
-
87
75
  it "closes the body and tracks an instrumentation event when it gets closed" do
88
76
  fake_body = double(:close => nil)
89
77
  expect(fake_body).to receive(:each).once.and_yield("a").and_yield("b").and_yield("c")
@@ -146,17 +134,6 @@ describe Appsignal::Rack::BodyWrapper do
146
134
  expect(transaction).to have_error("ExampleException", "error message")
147
135
  end
148
136
 
149
- it "doesn't report EPIPE error" do
150
- expect(fake_body).to receive(:each).once.and_raise(Errno::EPIPE)
151
-
152
- wrapped = described_class.wrap(fake_body, transaction)
153
- expect do
154
- expect { |b| wrapped.each(&b) }.to yield_control
155
- end.to raise_error(Errno::EPIPE)
156
-
157
- expect(transaction).to_not have_error
158
- end
159
-
160
137
  it "reads out the body in full using to_ary" do
161
138
  expect(fake_body).to receive(:to_ary).and_return(["one", "two", "three"])
162
139
 
@@ -230,17 +207,6 @@ describe Appsignal::Rack::BodyWrapper do
230
207
  expect(transaction).to have_error("ExampleException", "error message")
231
208
  end
232
209
 
233
- it "doesn't report EPIPE error" do
234
- expect(fake_body).to receive(:to_path).once.and_raise(Errno::EPIPE)
235
-
236
- wrapped = described_class.wrap(fake_body, transaction)
237
- expect do
238
- wrapped.to_path
239
- end.to raise_error(Errno::EPIPE)
240
-
241
- expect(transaction).to_not have_error
242
- end
243
-
244
210
  it "exposes to_path to the sender" do
245
211
  allow(fake_body).to receive(:to_path).and_return("/tmp/file.bin")
246
212
 
@@ -293,19 +259,5 @@ describe Appsignal::Rack::BodyWrapper do
293
259
 
294
260
  expect(transaction).to have_error("ExampleException", "error message")
295
261
  end
296
-
297
- it "doesn't report EPIPE error" do
298
- fake_rack_stream = double
299
- expect(fake_body).to receive(:call)
300
- .with(fake_rack_stream)
301
- .and_raise(Errno::EPIPE)
302
-
303
- wrapped = described_class.wrap(fake_body, transaction)
304
- expect do
305
- wrapped.call(fake_rack_stream)
306
- end.to raise_error(Errno::EPIPE)
307
-
308
- expect(transaction).to_not have_error
309
- end
310
262
  end
311
263
  end