appsignal 2.9.18-java → 2.10.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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: 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: 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
@@ -346,6 +346,7 @@ files:
346
346
  - spec/lib/puma/appsignal_spec.rb
347
347
  - spec/spec_helper.rb
348
348
  - spec/support/fixtures/generated_config.yml
349
+ - spec/support/fixtures/projects/broken/config/appsignal.yml
349
350
  - spec/support/fixtures/projects/valid/config/application.rb
350
351
  - spec/support/fixtures/projects/valid/config/appsignal.yml
351
352
  - spec/support/fixtures/projects/valid/config/environments/development.rb
@@ -367,7 +368,9 @@ files:
367
368
  - spec/support/helpers/time_helpers.rb
368
369
  - spec/support/helpers/transaction_helpers.rb
369
370
  - spec/support/helpers/wait_for_helper.rb
371
+ - spec/support/matchers/be_completed.rb
370
372
  - spec/support/matchers/contains_log.rb
373
+ - spec/support/matchers/have_colorized_text.rb
371
374
  - spec/support/mocks/fake_gc_profiler.rb
372
375
  - spec/support/mocks/mock_extension.rb
373
376
  - spec/support/mocks/mock_probe.rb
@@ -375,6 +378,7 @@ files:
375
378
  - spec/support/shared_examples/instrument.rb
376
379
  - spec/support/stubs/delayed_job.rb
377
380
  - spec/support/stubs/sidekiq/api.rb
381
+ - spec/support/testing.rb
378
382
  - support/bundler_wrapper
379
383
  - support/install_deps
380
384
  homepage: https://github.com/appsignal/appsignal-ruby
@@ -480,6 +484,7 @@ test_files:
480
484
  - spec/lib/puma/appsignal_spec.rb
481
485
  - spec/spec_helper.rb
482
486
  - spec/support/fixtures/generated_config.yml
487
+ - spec/support/fixtures/projects/broken/config/appsignal.yml
483
488
  - spec/support/fixtures/projects/valid/config/application.rb
484
489
  - spec/support/fixtures/projects/valid/config/appsignal.yml
485
490
  - spec/support/fixtures/projects/valid/config/environments/development.rb
@@ -501,7 +506,9 @@ test_files:
501
506
  - spec/support/helpers/time_helpers.rb
502
507
  - spec/support/helpers/transaction_helpers.rb
503
508
  - spec/support/helpers/wait_for_helper.rb
509
+ - spec/support/matchers/be_completed.rb
504
510
  - spec/support/matchers/contains_log.rb
511
+ - spec/support/matchers/have_colorized_text.rb
505
512
  - spec/support/mocks/fake_gc_profiler.rb
506
513
  - spec/support/mocks/mock_extension.rb
507
514
  - spec/support/mocks/mock_probe.rb
@@ -509,3 +516,4 @@ test_files:
509
516
  - spec/support/shared_examples/instrument.rb
510
517
  - spec/support/stubs/delayed_job.rb
511
518
  - spec/support/stubs/sidekiq/api.rb
519
+ - spec/support/testing.rb