appsignal 2.11.0.beta.4-java → 2.11.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.semaphore/semaphore.yml +254 -1
  3. data/CHANGELOG.md +27 -0
  4. data/README.md +20 -5
  5. data/Rakefile +27 -9
  6. data/appsignal.gemspec +1 -1
  7. data/build_matrix.yml +15 -2
  8. data/ext/Rakefile +2 -0
  9. data/ext/agent.yml +17 -25
  10. data/ext/appsignal_extension.c +1 -1
  11. data/ext/base.rb +19 -9
  12. data/ext/extconf.rb +2 -0
  13. data/gemfiles/no_dependencies.gemfile +7 -0
  14. data/gemfiles/resque-2.gemfile +0 -1
  15. data/gemfiles/webmachine.gemfile +1 -0
  16. data/lib/appsignal.rb +1 -0
  17. data/lib/appsignal/auth_check.rb +4 -2
  18. data/lib/appsignal/cli/diagnose.rb +1 -1
  19. data/lib/appsignal/cli/diagnose/utils.rb +8 -11
  20. data/lib/appsignal/cli/install.rb +5 -8
  21. data/lib/appsignal/config.rb +82 -17
  22. data/lib/appsignal/extension.rb +6 -5
  23. data/lib/appsignal/extension/jruby.rb +6 -5
  24. data/lib/appsignal/helpers/instrumentation.rb +32 -0
  25. data/lib/appsignal/hooks.rb +24 -0
  26. data/lib/appsignal/hooks/action_mailer.rb +22 -0
  27. data/lib/appsignal/hooks/active_job.rb +32 -9
  28. data/lib/appsignal/hooks/active_support_notifications.rb +72 -0
  29. data/lib/appsignal/hooks/puma.rb +0 -1
  30. data/lib/appsignal/hooks/sidekiq.rb +0 -1
  31. data/lib/appsignal/probes.rb +7 -0
  32. data/lib/appsignal/probes/puma.rb +1 -1
  33. data/lib/appsignal/probes/sidekiq.rb +3 -1
  34. data/lib/appsignal/transaction.rb +30 -2
  35. data/lib/appsignal/utils/deprecation_message.rb +1 -1
  36. data/lib/appsignal/version.rb +1 -1
  37. data/spec/lib/appsignal/auth_check_spec.rb +23 -0
  38. data/spec/lib/appsignal/capistrano2_spec.rb +1 -1
  39. data/spec/lib/appsignal/capistrano3_spec.rb +1 -1
  40. data/spec/lib/appsignal/cli/diagnose_spec.rb +42 -0
  41. data/spec/lib/appsignal/config_spec.rb +39 -1
  42. data/spec/lib/appsignal/extension/jruby_spec.rb +31 -28
  43. data/spec/lib/appsignal/extension_install_failure_spec.rb +23 -0
  44. data/spec/lib/appsignal/hooks/action_mailer_spec.rb +54 -0
  45. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +35 -0
  46. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +145 -0
  47. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +69 -0
  48. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +9 -137
  49. data/spec/lib/appsignal/hooks/activejob_spec.rb +44 -1
  50. data/spec/lib/appsignal/hooks/resque_spec.rb +10 -2
  51. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +4 -2
  52. data/spec/lib/appsignal/hooks_spec.rb +57 -0
  53. data/spec/lib/appsignal/marker_spec.rb +1 -1
  54. data/spec/lib/appsignal/transaction_spec.rb +55 -0
  55. data/spec/lib/appsignal_spec.rb +30 -0
  56. data/spec/spec_helper.rb +5 -0
  57. data/spec/support/helpers/config_helpers.rb +3 -2
  58. data/spec/support/helpers/dependency_helper.rb +4 -0
  59. data/spec/support/helpers/transaction_helpers.rb +1 -1
  60. data/spec/support/testing.rb +19 -19
  61. metadata +17 -5
@@ -60,7 +60,10 @@ describe Appsignal::Hooks::ResqueHook do
60
60
  "error" => nil,
61
61
  "namespace" => namespace,
62
62
  "metadata" => {},
63
- "sample_data" => { "tags" => { "queue" => queue } }
63
+ "sample_data" => {
64
+ "breadcrumbs" => [],
65
+ "tags" => { "queue" => queue }
66
+ }
64
67
  )
65
68
  expect(transaction_hash["events"].map { |e| e["name"] })
66
69
  .to eql(["perform.resque"])
@@ -84,7 +87,10 @@ describe Appsignal::Hooks::ResqueHook do
84
87
  },
85
88
  "namespace" => namespace,
86
89
  "metadata" => {},
87
- "sample_data" => { "tags" => { "queue" => queue } }
90
+ "sample_data" => {
91
+ "breadcrumbs" => [],
92
+ "tags" => { "queue" => queue }
93
+ }
88
94
  )
89
95
  end
90
96
  end
@@ -118,6 +124,7 @@ describe Appsignal::Hooks::ResqueHook do
118
124
  "metadata" => {},
119
125
  "sample_data" => {
120
126
  "tags" => { "queue" => queue },
127
+ "breadcrumbs" => [],
121
128
  "params" => [
122
129
  "foo",
123
130
  {
@@ -174,6 +181,7 @@ describe Appsignal::Hooks::ResqueHook do
174
181
  "namespace" => namespace,
175
182
  "metadata" => {},
176
183
  "sample_data" => {
184
+ "breadcrumbs" => [],
177
185
  "tags" => { "queue" => queue }
178
186
  # Params will be set by the ActiveJob integration
179
187
  }
@@ -262,7 +262,8 @@ describe Appsignal::Hooks::SidekiqPlugin, :with_yaml_parse_error => false do
262
262
  "sample_data" => {
263
263
  "environment" => {},
264
264
  "params" => expected_args,
265
- "tags" => {}
265
+ "tags" => {},
266
+ "breadcrumbs" => []
266
267
  }
267
268
  )
268
269
  expect_transaction_to_have_sidekiq_event(transaction_hash)
@@ -290,7 +291,8 @@ describe Appsignal::Hooks::SidekiqPlugin, :with_yaml_parse_error => false do
290
291
  "sample_data" => {
291
292
  "environment" => {},
292
293
  "params" => expected_args,
293
- "tags" => {}
294
+ "tags" => {},
295
+ "breadcrumbs" => []
294
296
  }
295
297
  )
296
298
  # TODO: Not available in transaction.to_h yet.
@@ -78,6 +78,63 @@ describe Appsignal::Hooks do
78
78
  expect(Appsignal::Hooks.hooks[:mock_error_hook].installed?).to be_falsy
79
79
  Appsignal::Hooks.hooks.delete(:mock_error_hook)
80
80
  end
81
+
82
+ describe "missing constants" do
83
+ let(:err_stream) { std_stream }
84
+ let(:stderr) { err_stream.read }
85
+ let(:log_stream) { std_stream }
86
+ let(:log) { log_contents(log_stream) }
87
+ before do
88
+ Appsignal.logger = test_logger(log_stream)
89
+ end
90
+
91
+ def call_constant(&block)
92
+ capture_std_streams(std_stream, err_stream, &block)
93
+ end
94
+
95
+ describe "SidekiqProbe" do
96
+ it "logs a deprecation message and returns the new constant" do
97
+ constant = call_constant { Appsignal::Hooks::SidekiqProbe }
98
+
99
+ expect(constant).to eql(Appsignal::Probes::SidekiqProbe)
100
+ expect(constant.name).to eql("Appsignal::Probes::SidekiqProbe")
101
+
102
+ deprecation_message =
103
+ "The constant Appsignal::Hooks::SidekiqProbe has been deprecated. " \
104
+ "Please update the constant name to Appsignal::Probes::SidekiqProbe " \
105
+ "in the following file to remove this message.\n#{__FILE__}:"
106
+ expect(stderr).to include "appsignal WARNING: #{deprecation_message}"
107
+ expect(log).to contains_log :warn, deprecation_message
108
+ end
109
+ end
110
+
111
+ describe "PumaProbe" do
112
+ it "logs a deprecation message and returns the new constant" do
113
+ constant = call_constant { Appsignal::Hooks::PumaProbe }
114
+
115
+ expect(constant).to eql(Appsignal::Probes::PumaProbe)
116
+ expect(constant.name).to eql("Appsignal::Probes::PumaProbe")
117
+
118
+ deprecation_message =
119
+ "The constant Appsignal::Hooks::PumaProbe has been deprecated. " \
120
+ "Please update the constant name to Appsignal::Probes::PumaProbe " \
121
+ "in the following file to remove this message.\n#{__FILE__}:"
122
+ expect(stderr).to include "appsignal WARNING: #{deprecation_message}"
123
+ expect(log).to contains_log :warn, deprecation_message
124
+ end
125
+ end
126
+
127
+ describe "other constant" do
128
+ it "raises a NameError like Ruby normally does" do
129
+ expect do
130
+ call_constant { Appsignal::Hooks::Unknown }
131
+ end.to raise_error(NameError)
132
+
133
+ expect(stderr).to be_empty
134
+ expect(log).to be_empty
135
+ end
136
+ end
137
+ end
81
138
  end
82
139
 
83
140
  describe Appsignal::Hooks::Helpers do
@@ -4,7 +4,7 @@ describe Appsignal::Marker do
4
4
  described_class.new(
5
5
  {
6
6
  :revision => "503ce0923ed177a3ce000005",
7
- :repository => "master",
7
+ :repository => "main",
8
8
  :user => "batman",
9
9
  :rails_env => "production"
10
10
  },
@@ -356,6 +356,57 @@ describe Appsignal::Transaction do
356
356
  end
357
357
  end
358
358
 
359
+ describe "#add_breadcrumb" do
360
+ context "when over the limit" do
361
+ before do
362
+ 22.times do |i|
363
+ transaction.add_breadcrumb(
364
+ "network",
365
+ "GET http://localhost",
366
+ "User made external network request",
367
+ { :code => i + 1 },
368
+ Time.parse("10-10-2010 10:00:00 UTC")
369
+ )
370
+ end
371
+ transaction.sample_data
372
+ end
373
+
374
+ it "stores last <LIMIT> breadcrumbs on the transaction" do
375
+ expect(transaction.to_h["sample_data"]["breadcrumbs"].length).to eql(20)
376
+ expect(transaction.to_h["sample_data"]["breadcrumbs"][0]).to eq(
377
+ "action" => "GET http://localhost",
378
+ "category" => "network",
379
+ "message" => "User made external network request",
380
+ "metadata" => { "code" => 3 },
381
+ "time" => 1286704800 # rubocop:disable Style/NumericLiterals
382
+ )
383
+ expect(transaction.to_h["sample_data"]["breadcrumbs"][19]).to eq(
384
+ "action" => "GET http://localhost",
385
+ "category" => "network",
386
+ "message" => "User made external network request",
387
+ "metadata" => { "code" => 22 },
388
+ "time" => 1286704800 # rubocop:disable Style/NumericLiterals
389
+ )
390
+ end
391
+ end
392
+
393
+ context "with defaults" do
394
+ it "stores breadcrumb with defaults on transaction" do
395
+ timeframe_start = Time.now.utc.to_i
396
+ transaction.add_breadcrumb("user_action", "clicked HOME")
397
+ transaction.sample_data
398
+ timeframe_end = Time.now.utc.to_i
399
+
400
+ breadcrumb = transaction.to_h["sample_data"]["breadcrumbs"][0]
401
+ expect(breadcrumb["category"]).to eq("user_action")
402
+ expect(breadcrumb["action"]).to eq("clicked HOME")
403
+ expect(breadcrumb["message"]).to eq("")
404
+ expect(breadcrumb["time"]).to be_between(timeframe_start, timeframe_end)
405
+ expect(breadcrumb["metadata"]).to eq({})
406
+ end
407
+ end
408
+ end
409
+
359
410
  describe "#set_action" do
360
411
  context "when the action is set" do
361
412
  it "updates the action name on the transaction" do
@@ -649,6 +700,10 @@ describe Appsignal::Transaction do
649
700
  "tags",
650
701
  Appsignal::Utils::Data.generate({})
651
702
  ).once
703
+ expect(transaction.ext).to receive(:set_sample_data).with(
704
+ "breadcrumbs",
705
+ Appsignal::Utils::Data.generate([])
706
+ ).once
652
707
 
653
708
  transaction.sample_data
654
709
  end
@@ -491,6 +491,36 @@ describe Appsignal do
491
491
  end
492
492
  end
493
493
 
494
+ describe ".add_breadcrumb" do
495
+ before { allow(Appsignal::Transaction).to receive(:current).and_return(transaction) }
496
+
497
+ context "with transaction" do
498
+ let(:transaction) { double }
499
+ it "should call add_breadcrumb on transaction" do
500
+ expect(transaction).to receive(:add_breadcrumb)
501
+ .with("Network", "http", "User made network request", { :response => 200 }, fixed_time)
502
+ end
503
+
504
+ after do
505
+ Appsignal.add_breadcrumb(
506
+ "Network",
507
+ "http",
508
+ "User made network request",
509
+ { :response => 200 },
510
+ fixed_time
511
+ )
512
+ end
513
+ end
514
+
515
+ context "without transaction" do
516
+ let(:transaction) { nil }
517
+
518
+ it "should not call add_breadcrumb on transaction" do
519
+ expect(Appsignal.add_breadcrumb("Network", "http")).to be_falsy
520
+ end
521
+ end
522
+ end
523
+
494
524
  describe "custom stats" do
495
525
  let(:tags) { { :foo => "bar" } }
496
526
 
@@ -65,6 +65,10 @@ RSpec.configure do |config|
65
65
 
66
66
  config.example_status_persistence_file_path = "spec/examples.txt"
67
67
  config.fail_if_no_examples = true
68
+ config.filter_run_excluding(
69
+ :extension_installation_failure => true,
70
+ :jruby => !DependencyHelper.running_jruby?
71
+ )
68
72
  config.mock_with :rspec do |mocks|
69
73
  mocks.syntax = :expect
70
74
  end
@@ -111,6 +115,7 @@ RSpec.configure do |config|
111
115
  # in the diagnose task, so add it manually to the list of to-be cleaned up
112
116
  # keys.
113
117
  env_keys << "_APPSIGNAL_DIAGNOSE"
118
+ env_keys << "_TEST_APPSIGNAL_EXTENSION_FAILURE"
114
119
  env_keys.each do |key|
115
120
  # First set the ENV var to an empty string and then delete the key from
116
121
  # the env. We set the env var to an empty string first as JRuby doesn't
@@ -5,12 +5,13 @@ module ConfigHelpers
5
5
  )
6
6
  end
7
7
 
8
- def project_fixture_config(env = "production", initial_config = {}, logger = Appsignal.logger)
8
+ def project_fixture_config(env = "production", initial_config = {}, logger = Appsignal.logger, config_file = nil)
9
9
  Appsignal::Config.new(
10
10
  project_fixture_path,
11
11
  env,
12
12
  initial_config,
13
- logger
13
+ logger,
14
+ config_file
14
15
  )
15
16
  end
16
17
 
@@ -37,6 +37,10 @@ module DependencyHelper
37
37
  dependency_present? "actioncable"
38
38
  end
39
39
 
40
+ def action_mailer_present?
41
+ dependency_present? "actionmailer"
42
+ end
43
+
40
44
  def active_job_present?
41
45
  dependency_present? "activejob"
42
46
  end
@@ -46,7 +46,7 @@ module TransactionHelpers
46
46
 
47
47
  # Set current transaction manually.
48
48
  # Cleared by {clear_current_transaction!}
49
- def set_current_transaction(transaction) # rubocop:disable Style/AccessorMethodName
49
+ def set_current_transaction(transaction) # rubocop:disable Naming/AccessorMethodName
50
50
  Thread.current[:appsignal_transaction] = transaction
51
51
  end
52
52
 
@@ -38,25 +38,9 @@ module Appsignal
38
38
  end
39
39
  end
40
40
 
41
- class Transaction
42
- class << self
43
- alias original_new new
44
-
45
- # Override the {Appsignal::Transaction.new} method so we can track which
46
- # transactions are created on the {Appsignal::Testing.transactions} list.
47
- #
48
- # @see TransactionHelpers#last_transaction
49
- def new(*args)
50
- transaction = original_new(*args)
51
- Appsignal::Testing.transactions << transaction
52
- transaction
53
- end
54
- end
55
- end
56
-
57
41
  class Extension
58
42
  class Transaction
59
- alias original_finish finish
43
+ alias original_finish finish if method_defined? :finish
60
44
 
61
45
  # Override default {Extension::Transaction#finish} behavior to always
62
46
  # return true, which tells the transaction to add its sample data (unless
@@ -72,7 +56,7 @@ module Appsignal
72
56
  return_value
73
57
  end
74
58
 
75
- alias original_complete complete
59
+ alias original_complete complete if method_defined? :complete
76
60
 
77
61
  # Override default {Extension::Transaction#complete} behavior to
78
62
  # store the transaction JSON before the transaction is completed
@@ -94,7 +78,7 @@ module Appsignal
94
78
  @completed || false
95
79
  end
96
80
 
97
- alias original_to_json to_json
81
+ alias original_to_json to_json if method_defined? :to_json
98
82
 
99
83
  # Override default {Extension::Transaction#to_json} behavior to
100
84
  # return the stored the transaction JSON when the transaction was
@@ -111,3 +95,19 @@ module Appsignal
111
95
  end
112
96
  end
113
97
  end
98
+
99
+ module AppsignalTest
100
+ module Transaction
101
+ # Override the {Appsignal::Transaction.new} method so we can track which
102
+ # transactions are created on the {Appsignal::Testing.transactions} list.
103
+ #
104
+ # @see TransactionHelpers#last_transaction
105
+ def new(*_args)
106
+ transaction = super
107
+ Appsignal::Testing.transactions << transaction
108
+ transaction
109
+ end
110
+ end
111
+ end
112
+
113
+ Appsignal::Transaction.extend(AppsignalTest::Transaction)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0.beta.4
4
+ version: 2.11.2
5
5
  platform: java
6
6
  authors:
7
7
  - Robert Beekman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-07-13 00:00:00.000000000 Z
13
+ date: 2021-01-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -221,6 +221,7 @@ files:
221
221
  - lib/appsignal/helpers/metrics.rb
222
222
  - lib/appsignal/hooks.rb
223
223
  - lib/appsignal/hooks/action_cable.rb
224
+ - lib/appsignal/hooks/action_mailer.rb
224
225
  - lib/appsignal/hooks/active_job.rb
225
226
  - lib/appsignal/hooks/active_support_notifications.rb
226
227
  - lib/appsignal/hooks/celluloid.rb
@@ -258,6 +259,7 @@ files:
258
259
  - lib/appsignal/logger.rb
259
260
  - lib/appsignal/marker.rb
260
261
  - lib/appsignal/minutely.rb
262
+ - lib/appsignal/probes.rb
261
263
  - lib/appsignal/probes/puma.rb
262
264
  - lib/appsignal/probes/sidekiq.rb
263
265
  - lib/appsignal/rack/generic_instrumentation.rb
@@ -304,9 +306,14 @@ files:
304
306
  - spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb
305
307
  - spec/lib/appsignal/event_formatter_spec.rb
306
308
  - spec/lib/appsignal/extension/jruby_spec.rb
309
+ - spec/lib/appsignal/extension_install_failure_spec.rb
307
310
  - spec/lib/appsignal/extension_spec.rb
308
311
  - spec/lib/appsignal/garbage_collection_profiler_spec.rb
309
312
  - spec/lib/appsignal/hooks/action_cable_spec.rb
313
+ - spec/lib/appsignal/hooks/action_mailer_spec.rb
314
+ - spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb
315
+ - spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb
316
+ - spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb
310
317
  - spec/lib/appsignal/hooks/active_support_notifications_spec.rb
311
318
  - spec/lib/appsignal/hooks/activejob_spec.rb
312
319
  - spec/lib/appsignal/hooks/celluloid_spec.rb
@@ -402,7 +409,7 @@ licenses:
402
409
  - MIT
403
410
  metadata:
404
411
  bug_tracker_uri: https://github.com/appsignal/appsignal-ruby/issues
405
- changelog_uri: https://github.com/appsignal/appsignal-ruby/blob/master/CHANGELOG.md
412
+ changelog_uri: https://github.com/appsignal/appsignal-ruby/blob/main/CHANGELOG.md
406
413
  documentation_uri: https://docs.appsignal.com/ruby/
407
414
  homepage_uri: https://docs.appsignal.com/ruby/
408
415
  source_code_uri: https://github.com/appsignal/appsignal-ruby
@@ -418,9 +425,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
418
425
  version: '1.9'
419
426
  required_rubygems_version: !ruby/object:Gem::Requirement
420
427
  requirements:
421
- - - ">"
428
+ - - ">="
422
429
  - !ruby/object:Gem::Version
423
- version: 1.3.1
430
+ version: '0'
424
431
  requirements: []
425
432
  rubygems_version: 3.1.4
426
433
  signing_key:
@@ -451,9 +458,14 @@ test_files:
451
458
  - spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb
452
459
  - spec/lib/appsignal/event_formatter_spec.rb
453
460
  - spec/lib/appsignal/extension/jruby_spec.rb
461
+ - spec/lib/appsignal/extension_install_failure_spec.rb
454
462
  - spec/lib/appsignal/extension_spec.rb
455
463
  - spec/lib/appsignal/garbage_collection_profiler_spec.rb
456
464
  - spec/lib/appsignal/hooks/action_cable_spec.rb
465
+ - spec/lib/appsignal/hooks/action_mailer_spec.rb
466
+ - spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb
467
+ - spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb
468
+ - spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb
457
469
  - spec/lib/appsignal/hooks/active_support_notifications_spec.rb
458
470
  - spec/lib/appsignal/hooks/activejob_spec.rb
459
471
  - spec/lib/appsignal/hooks/celluloid_spec.rb