appsignal 2.9.18 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +0 -6
  3. data/CHANGELOG.md +17 -1
  4. data/Rakefile +16 -2
  5. data/lib/appsignal/cli.rb +9 -2
  6. data/lib/appsignal/cli/diagnose.rb +20 -19
  7. data/lib/appsignal/cli/helpers.rb +22 -10
  8. data/lib/appsignal/cli/install.rb +2 -1
  9. data/lib/appsignal/config.rb +18 -7
  10. data/lib/appsignal/event_formatter.rb +4 -4
  11. data/lib/appsignal/minutely.rb +4 -4
  12. data/lib/appsignal/rack/js_exception_catcher.rb +6 -0
  13. data/lib/appsignal/transaction.rb +1 -1
  14. data/lib/appsignal/version.rb +1 -1
  15. data/spec/lib/appsignal/cli/diagnose_spec.rb +54 -11
  16. data/spec/lib/appsignal/cli/helpers_spec.rb +11 -3
  17. data/spec/lib/appsignal/cli/install_spec.rb +30 -1
  18. data/spec/lib/appsignal/config_spec.rb +75 -7
  19. data/spec/lib/appsignal/hooks/action_cable_spec.rb +1 -5
  20. data/spec/lib/appsignal/hooks/rake_spec.rb +41 -39
  21. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +2 -15
  22. data/spec/lib/appsignal/integrations/object_spec.rb +2 -2
  23. data/spec/lib/appsignal/integrations/que_spec.rb +26 -39
  24. data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +108 -46
  25. data/spec/lib/appsignal/integrations/resque_spec.rb +40 -39
  26. data/spec/lib/appsignal/minutely_spec.rb +3 -3
  27. data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +19 -5
  28. data/spec/lib/appsignal/transaction_spec.rb +4 -12
  29. data/spec/lib/appsignal_spec.rb +7 -8
  30. data/spec/spec_helper.rb +11 -11
  31. data/spec/support/fixtures/projects/broken/config/appsignal.yml +1 -0
  32. data/spec/support/helpers/cli_helpers.rb +15 -1
  33. data/spec/support/helpers/transaction_helpers.rb +53 -0
  34. data/spec/support/matchers/be_completed.rb +5 -0
  35. data/spec/support/matchers/have_colorized_text.rb +28 -0
  36. data/spec/support/testing.rb +113 -0
  37. metadata +10 -2
@@ -0,0 +1 @@
1
+ <%= NotExistingConstant.not_existing_method %>
@@ -1,3 +1,5 @@
1
+ require "appsignal/cli/helpers"
2
+
1
3
  module CLIHelpers
2
4
  def cli
3
5
  Appsignal::CLI
@@ -10,7 +12,7 @@ module CLIHelpers
10
12
  def format_cli_arguments_and_options(command, options = {})
11
13
  [*command].tap do |o|
12
14
  options.each do |key, value|
13
- o << "--#{key}=#{value}"
15
+ o << (value.nil? ? "--#{key}" : "--#{key}=#{value}")
14
16
  end
15
17
  end
16
18
  end
@@ -23,4 +25,16 @@ module CLIHelpers
23
25
  # Prepare the input by rewinding the pointer in the StringIO
24
26
  $stdin.rewind
25
27
  end
28
+
29
+ def colorize(*args)
30
+ ColorizeHelper.colorize(*args)
31
+ end
32
+ end
33
+
34
+ module ColorizeHelper
35
+ extend Appsignal::CLI::Helpers
36
+
37
+ def self.colorize(*_args)
38
+ super
39
+ end
26
40
  end
@@ -29,9 +29,62 @@ module TransactionHelpers
29
29
  )
30
30
  end
31
31
 
32
+ # Returns the all {Appsignal::Transaction} objects created during this test
33
+ # run so far.
34
+ #
35
+ # @return [Array<Appsignal::Transaction>]
36
+ def created_transactions
37
+ Appsignal::Testing.transactions
38
+ end
39
+
40
+ # Returns the last created {Appsignal::Transaction}.
41
+ #
42
+ # @return [Appsignal::Transaction]
43
+ def last_transaction
44
+ created_transactions.last
45
+ end
46
+
32
47
  # Use when {Appsignal::Transaction.clear_current_transaction!} is stubbed to
33
48
  # clear the current transaction on the current thread.
34
49
  def clear_current_transaction!
35
50
  Thread.current[:appsignal_transaction] = nil
36
51
  end
52
+
53
+ # Track the AppSignal transaction JSON when a transaction gets completed
54
+ # ({Appsignal::Transaction.complete}).
55
+ #
56
+ # It will also add sample data to the transaction when it gets completed.
57
+ # This can be disabled by setting the `sample` option to `false`.
58
+ #
59
+ # It will be tracked for every transaction that is started inside the
60
+ # `keep_transactions` block.
61
+ #
62
+ # @example Keep a transaction while also adding sample data
63
+ # keep_transactions do
64
+ # transaction = Appsignal::Transaction.new(...)
65
+ # transaction.complete
66
+ # transaction.to_h # => Hash with transaction data before it was completed
67
+ # end
68
+ #
69
+ # @example Keep a transaction without adding sample data
70
+ # keep_transactions :sample => false do
71
+ # transaction = Appsignal::Transaction.new(...)
72
+ # transaction.complete
73
+ # transaction.to_h
74
+ # # => Hash with transaction data before it was completed with an empty
75
+ # # Hash for the `sample_data` key.
76
+ # end
77
+ #
78
+ # @yield block to perform while the transactions are tracked.
79
+ # @param options [Hash]
80
+ # @option options [Boolean] :sample Whether or not to sample transactions.
81
+ # @return [Object] returns the block return value.
82
+ def keep_transactions(options = {})
83
+ Appsignal::Testing.keep_transactions = true
84
+ Appsignal::Testing.sample_transactions = options.fetch(:sample, true)
85
+ yield
86
+ ensure
87
+ Appsignal::Testing.keep_transactions = nil
88
+ Appsignal::Testing.sample_transactions = nil
89
+ end
37
90
  end
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :be_completed do
2
+ match do |transaction|
3
+ values_match? transaction.ext._completed?, true
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ RSpec::Matchers.define :have_colorized_text do |color, text|
2
+ match do |actual|
3
+ color_codes = Appsignal::CLI::Helpers::COLOR_CODES
4
+ reset_color_code = color_codes.fetch(:default)
5
+ color_code = color_codes.fetch(color)
6
+
7
+ @expected = "\e[#{color_code}m#{text}\e[#{reset_color_code}m"
8
+ expect(actual).to include(@expected)
9
+ end
10
+
11
+ diffable
12
+ attr_reader :expected
13
+ end
14
+
15
+ COLOR_TAG_MATCHER_REGEX = /\e\[(\d+)m/
16
+ RSpec::Matchers.define :have_color_markers do
17
+ match do |actual|
18
+ actual =~ COLOR_TAG_MATCHER_REGEX
19
+ end
20
+
21
+ failure_message do
22
+ "expected that output contains color markers: /\\e[\\d+m/"
23
+ end
24
+
25
+ failure_message_when_negated do
26
+ "expected that output does not contain color markers: /\\e[\\d+m/"
27
+ end
28
+ end
@@ -0,0 +1,113 @@
1
+ module Appsignal
2
+ class << self
3
+ remove_method :testing?
4
+
5
+ # @api private
6
+ def testing?
7
+ true
8
+ end
9
+ end
10
+
11
+ # @api private
12
+ module Testing
13
+ class << self
14
+ def transactions
15
+ @transactions ||= []
16
+ end
17
+
18
+ def clear!
19
+ transactions.clear
20
+ end
21
+
22
+ attr_writer :keep_transactions
23
+ # @see TransactionHelpers#keep_transactions
24
+ def keep_transactions?
25
+ defined?(@keep_transactions) ? @keep_transactions : nil
26
+ end
27
+
28
+ attr_writer :sample_transactions
29
+ # @see TransactionHelpers#keep_transactions
30
+ def sample_transactions?
31
+ sample = defined?(@sample_transactions) ? @sample_transactions : nil
32
+ if sample.nil?
33
+ keep_transactions?
34
+ else
35
+ @sample_transactions
36
+ end
37
+ end
38
+ end
39
+ end
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
+ class Extension
58
+ class Transaction
59
+ alias original_finish finish
60
+
61
+ # Override default {Extension::Transaction#finish} behavior to always
62
+ # return true, which tells the transaction to add its sample data (unless
63
+ # used in combination with {TransactionHelpers#keep_transactions}
64
+ # `:sample => false`). This allows us to use
65
+ # {Appsignal::Transaction#to_h} without relying on the extension sampling
66
+ # behavior.
67
+ #
68
+ # @see TransactionHelpers#keep_transactions
69
+ def finish(*args)
70
+ return_value = original_finish(*args)
71
+ return_value = true if Appsignal::Testing.sample_transactions?
72
+ return_value
73
+ end
74
+
75
+ alias original_complete complete
76
+
77
+ # Override default {Extension::Transaction#complete} behavior to
78
+ # store the transaction JSON before the transaction is completed
79
+ # and it's no longer possible to request the transaction JSON.
80
+ #
81
+ # @see TransactionHelpers#keep_transactions
82
+ # @see #_completed?
83
+ def complete
84
+ @completed = true # see {#_completed?} method
85
+ @transaction_json = to_json if Appsignal::Testing.keep_transactions?
86
+ original_complete
87
+ end
88
+
89
+ # Returns true when the Transaction was completed.
90
+ # {Appsignal::Extension::Transaction.complete} was called.
91
+ #
92
+ # @return [Boolean] returns if the transaction was completed.
93
+ def _completed?
94
+ @completed || false
95
+ end
96
+
97
+ alias original_to_json to_json
98
+
99
+ # Override default {Extension::Transaction#to_json} behavior to
100
+ # return the stored the transaction JSON when the transaction was
101
+ # completed.
102
+ #
103
+ # @see TransactionHelpers#keep_transactions
104
+ def to_json
105
+ if defined? @transaction_json
106
+ @transaction_json
107
+ else
108
+ original_to_json
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
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.9.18
4
+ version: 2.10.0
5
5
  platform: ruby
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: 2019-11-19 00:00:00.000000000 Z
13
+ date: 2019-11-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -332,6 +332,7 @@ files:
332
332
  - spec/lib/puma/appsignal_spec.rb
333
333
  - spec/spec_helper.rb
334
334
  - spec/support/fixtures/generated_config.yml
335
+ - spec/support/fixtures/projects/broken/config/appsignal.yml
335
336
  - spec/support/fixtures/projects/valid/config/application.rb
336
337
  - spec/support/fixtures/projects/valid/config/appsignal.yml
337
338
  - spec/support/fixtures/projects/valid/config/environments/development.rb
@@ -353,7 +354,9 @@ files:
353
354
  - spec/support/helpers/time_helpers.rb
354
355
  - spec/support/helpers/transaction_helpers.rb
355
356
  - spec/support/helpers/wait_for_helper.rb
357
+ - spec/support/matchers/be_completed.rb
356
358
  - spec/support/matchers/contains_log.rb
359
+ - spec/support/matchers/have_colorized_text.rb
357
360
  - spec/support/mocks/fake_gc_profiler.rb
358
361
  - spec/support/mocks/mock_extension.rb
359
362
  - spec/support/mocks/mock_probe.rb
@@ -361,6 +364,7 @@ files:
361
364
  - spec/support/shared_examples/instrument.rb
362
365
  - spec/support/stubs/delayed_job.rb
363
366
  - spec/support/stubs/sidekiq/api.rb
367
+ - spec/support/testing.rb
364
368
  - support/bundler_wrapper
365
369
  - support/install_deps
366
370
  homepage: https://github.com/appsignal/appsignal-ruby
@@ -466,6 +470,7 @@ test_files:
466
470
  - spec/lib/puma/appsignal_spec.rb
467
471
  - spec/spec_helper.rb
468
472
  - spec/support/fixtures/generated_config.yml
473
+ - spec/support/fixtures/projects/broken/config/appsignal.yml
469
474
  - spec/support/fixtures/projects/valid/config/application.rb
470
475
  - spec/support/fixtures/projects/valid/config/appsignal.yml
471
476
  - spec/support/fixtures/projects/valid/config/environments/development.rb
@@ -487,7 +492,9 @@ test_files:
487
492
  - spec/support/helpers/time_helpers.rb
488
493
  - spec/support/helpers/transaction_helpers.rb
489
494
  - spec/support/helpers/wait_for_helper.rb
495
+ - spec/support/matchers/be_completed.rb
490
496
  - spec/support/matchers/contains_log.rb
497
+ - spec/support/matchers/have_colorized_text.rb
491
498
  - spec/support/mocks/fake_gc_profiler.rb
492
499
  - spec/support/mocks/mock_extension.rb
493
500
  - spec/support/mocks/mock_probe.rb
@@ -495,3 +502,4 @@ test_files:
495
502
  - spec/support/shared_examples/instrument.rb
496
503
  - spec/support/stubs/delayed_job.rb
497
504
  - spec/support/stubs/sidekiq/api.rb
505
+ - spec/support/testing.rb