appsignal 3.10.0 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +197 -0
  4. data/Gemfile +1 -0
  5. data/Rakefile +1 -1
  6. data/benchmark.rake +99 -42
  7. data/lib/appsignal/cli/demo.rb +0 -1
  8. data/lib/appsignal/cli/diagnose.rb +1 -1
  9. data/lib/appsignal/config.rb +204 -130
  10. data/lib/appsignal/demo.rb +16 -26
  11. data/lib/appsignal/event_formatter/rom/sql_formatter.rb +1 -0
  12. data/lib/appsignal/event_formatter.rb +3 -2
  13. data/lib/appsignal/helpers/instrumentation.rb +331 -19
  14. data/lib/appsignal/hooks/action_cable.rb +21 -16
  15. data/lib/appsignal/hooks/active_job.rb +14 -8
  16. data/lib/appsignal/hooks/delayed_job.rb +1 -1
  17. data/lib/appsignal/hooks/shoryuken.rb +3 -63
  18. data/lib/appsignal/integrations/action_cable.rb +5 -7
  19. data/lib/appsignal/integrations/active_support_notifications.rb +1 -0
  20. data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +36 -35
  21. data/lib/appsignal/integrations/data_mapper.rb +1 -0
  22. data/lib/appsignal/integrations/delayed_job_plugin.rb +27 -33
  23. data/lib/appsignal/integrations/dry_monitor.rb +1 -0
  24. data/lib/appsignal/integrations/excon.rb +1 -0
  25. data/lib/appsignal/integrations/grape.rb +7 -0
  26. data/lib/appsignal/integrations/hanami.rb +8 -43
  27. data/lib/appsignal/integrations/http.rb +1 -0
  28. data/lib/appsignal/integrations/net_http.rb +1 -0
  29. data/lib/appsignal/integrations/object.rb +6 -0
  30. data/lib/appsignal/integrations/padrino.rb +8 -73
  31. data/lib/appsignal/integrations/que.rb +13 -20
  32. data/lib/appsignal/integrations/railtie.rb +36 -14
  33. data/lib/appsignal/integrations/rake.rb +1 -5
  34. data/lib/appsignal/integrations/redis.rb +1 -0
  35. data/lib/appsignal/integrations/redis_client.rb +1 -0
  36. data/lib/appsignal/integrations/resque.rb +2 -5
  37. data/lib/appsignal/integrations/shoryuken.rb +75 -0
  38. data/lib/appsignal/integrations/sidekiq.rb +7 -15
  39. data/lib/appsignal/integrations/sinatra.rb +8 -19
  40. data/lib/appsignal/integrations/unicorn.rb +1 -0
  41. data/lib/appsignal/integrations/webmachine.rb +2 -5
  42. data/lib/appsignal/loaders/grape.rb +13 -0
  43. data/lib/appsignal/loaders/hanami.rb +40 -0
  44. data/lib/appsignal/loaders/padrino.rb +68 -0
  45. data/lib/appsignal/loaders/sinatra.rb +24 -0
  46. data/lib/appsignal/loaders.rb +92 -0
  47. data/lib/appsignal/logger.rb +7 -3
  48. data/lib/appsignal/probes/helpers.rb +1 -0
  49. data/lib/appsignal/probes/mri.rb +1 -0
  50. data/lib/appsignal/probes/sidekiq.rb +1 -0
  51. data/lib/appsignal/probes.rb +3 -0
  52. data/lib/appsignal/rack/abstract_middleware.rb +20 -13
  53. data/lib/appsignal/rack/event_handler.rb +44 -13
  54. data/lib/appsignal/rack/generic_instrumentation.rb +1 -0
  55. data/lib/appsignal/rack/grape_middleware.rb +2 -1
  56. data/lib/appsignal/rack/streaming_listener.rb +1 -0
  57. data/lib/appsignal/rack.rb +35 -0
  58. data/lib/appsignal/span.rb +1 -0
  59. data/lib/appsignal/transaction.rb +308 -101
  60. data/lib/appsignal/utils/data.rb +0 -1
  61. data/lib/appsignal/utils/hash_sanitizer.rb +0 -1
  62. data/lib/appsignal/utils/integration_logger.rb +0 -13
  63. data/lib/appsignal/utils/integration_memory_logger.rb +0 -13
  64. data/lib/appsignal/utils/json.rb +0 -1
  65. data/lib/appsignal/utils/query_params_sanitizer.rb +0 -1
  66. data/lib/appsignal/utils/stdout_and_logger_message.rb +0 -1
  67. data/lib/appsignal/utils.rb +6 -0
  68. data/lib/appsignal/version.rb +1 -1
  69. data/lib/appsignal.rb +169 -14
  70. data/spec/lib/appsignal/capistrano2_spec.rb +1 -1
  71. data/spec/lib/appsignal/cli/demo_spec.rb +0 -1
  72. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +1 -1
  73. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1
  74. data/spec/lib/appsignal/config_spec.rb +291 -44
  75. data/spec/lib/appsignal/demo_spec.rb +1 -2
  76. data/spec/lib/appsignal/environment_spec.rb +4 -2
  77. data/spec/lib/appsignal/hooks/action_cable_spec.rb +43 -74
  78. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +3 -6
  79. data/spec/lib/appsignal/hooks/activejob_spec.rb +12 -3
  80. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +2 -443
  81. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +4 -7
  82. data/spec/lib/appsignal/hooks/excon_spec.rb +3 -6
  83. data/spec/lib/appsignal/hooks/gvl_spec.rb +2 -2
  84. data/spec/lib/appsignal/hooks/http_spec.rb +1 -3
  85. data/spec/lib/appsignal/hooks/net_http_spec.rb +1 -1
  86. data/spec/lib/appsignal/hooks/redis_client_spec.rb +5 -8
  87. data/spec/lib/appsignal/hooks/redis_spec.rb +3 -6
  88. data/spec/lib/appsignal/hooks/resque_spec.rb +1 -1
  89. data/spec/lib/appsignal/hooks/sequel_spec.rb +3 -5
  90. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -171
  91. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +1 -1
  92. data/spec/lib/appsignal/hooks/webmachine_spec.rb +1 -1
  93. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +459 -0
  94. data/spec/lib/appsignal/integrations/grape_spec.rb +36 -0
  95. data/spec/lib/appsignal/integrations/hanami_spec.rb +9 -178
  96. data/spec/lib/appsignal/integrations/http_spec.rb +1 -5
  97. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +4 -2
  98. data/spec/lib/appsignal/integrations/net_http_spec.rb +1 -1
  99. data/spec/lib/appsignal/integrations/object_spec.rb +1 -3
  100. data/spec/lib/appsignal/integrations/padrino_spec.rb +8 -330
  101. data/spec/lib/appsignal/integrations/que_spec.rb +3 -4
  102. data/spec/lib/appsignal/integrations/railtie_spec.rb +275 -191
  103. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +167 -0
  104. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +15 -13
  105. data/spec/lib/appsignal/integrations/sinatra_spec.rb +9 -104
  106. data/spec/lib/appsignal/integrations/webmachine_spec.rb +13 -1
  107. data/spec/lib/appsignal/loaders/grape_spec.rb +12 -0
  108. data/spec/lib/appsignal/loaders/hanami_spec.rb +95 -0
  109. data/spec/lib/appsignal/loaders/padrino_spec.rb +277 -0
  110. data/spec/lib/appsignal/loaders/sinatra_spec.rb +47 -0
  111. data/spec/lib/appsignal/loaders_spec.rb +137 -0
  112. data/spec/lib/appsignal/probes/sidekiq_spec.rb +1 -1
  113. data/spec/lib/appsignal/probes_spec.rb +6 -5
  114. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +51 -5
  115. data/spec/lib/appsignal/rack/event_handler_spec.rb +114 -10
  116. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +1 -1
  117. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +2 -35
  118. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +1 -1
  119. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +4 -2
  120. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +3 -3
  121. data/spec/lib/appsignal/rack_spec.rb +63 -0
  122. data/spec/lib/appsignal/span_spec.rb +1 -3
  123. data/spec/lib/appsignal/transaction_spec.rb +1640 -1075
  124. data/spec/lib/appsignal/utils/integration_logger_spec.rb +12 -16
  125. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -10
  126. data/spec/lib/appsignal_spec.rb +601 -36
  127. data/spec/lib/puma/appsignal_spec.rb +0 -3
  128. data/spec/spec_helper.rb +5 -4
  129. data/spec/support/helpers/config_helpers.rb +2 -1
  130. data/spec/support/helpers/loader_helper.rb +21 -0
  131. data/spec/support/helpers/transaction_helpers.rb +44 -20
  132. data/spec/support/matchers/transaction.rb +15 -1
  133. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +7 -0
  134. data/spec/support/testing.rb +47 -1
  135. metadata +19 -2
@@ -76,9 +76,6 @@ RSpec.describe "Puma plugin" do
76
76
  let(:hostname) { Socket.gethostname }
77
77
  let(:expected_default_tags) { { "hostname" => hostname } }
78
78
  let(:stats_data) { { :backlog => 1 } }
79
- before :context do
80
- Appsignal.stop
81
- end
82
79
  before do
83
80
  module Puma
84
81
  def self.stats
data/spec/spec_helper.rb CHANGED
@@ -66,6 +66,7 @@ RSpec.configure do |config|
66
66
  config.include ApiRequestHelper
67
67
  config.include SystemHelpers
68
68
  config.include LogHelpers
69
+ config.include LoaderHelper
69
70
  config.extend DependencyHelper
70
71
 
71
72
  config.example_status_persistence_file_path = "spec/examples.txt"
@@ -92,6 +93,10 @@ RSpec.configure do |config|
92
93
  end
93
94
 
94
95
  config.before do
96
+ Appsignal.clear!
97
+ Appsignal::Testing.clear!
98
+ Appsignal::Loaders.clear!
99
+ clear_current_transaction!
95
100
  stop_minutely_probes
96
101
  ENV["RAILS_ENV"] ||= "test"
97
102
  ENV["RACK_ENV"] ||= "test"
@@ -157,15 +162,11 @@ RSpec.configure do |config|
157
162
  end
158
163
 
159
164
  config.after do
160
- Appsignal::Testing.clear!
161
- clear_current_transaction!
162
165
  stop_minutely_probes
163
166
  end
164
167
 
165
168
  config.after :context do
166
169
  FileUtils.rm_f(File.join(project_fixture_path, "log/appsignal.log"))
167
- Appsignal.config = nil
168
- Appsignal.internal_logger = nil
169
170
  end
170
171
 
171
172
  def stop_minutely_probes
@@ -4,6 +4,7 @@ module ConfigHelpers
4
4
  File.join(File.dirname(__FILE__), "../fixtures/projects/valid")
5
5
  )
6
6
  end
7
+ module_function :project_fixture_path
7
8
 
8
9
  def project_fixture_config( # rubocop:disable Metrics/ParameterLists
9
10
  env = "production",
@@ -22,7 +23,7 @@ module ConfigHelpers
22
23
  module_function :project_fixture_config, :project_fixture_path
23
24
 
24
25
  def start_agent(env = "production")
25
- Appsignal.config = project_fixture_config(env)
26
+ Appsignal._config = project_fixture_config(env)
26
27
  Appsignal.start
27
28
  end
28
29
  end
@@ -0,0 +1,21 @@
1
+ module LoaderHelper
2
+ def load_loader(name)
3
+ Appsignal.load(name)
4
+ end
5
+
6
+ def start_loader(name)
7
+ Appsignal::Loaders.instances.fetch(name).on_start
8
+ end
9
+
10
+ def unregister_loader(name)
11
+ Appsignal::Loaders.unregister(name)
12
+ end
13
+
14
+ def define_loader(name, &block)
15
+ Appsignal::Testing.registered_loaders << name
16
+ Class.new(Appsignal::Loaders::Loader) do
17
+ register name
18
+ class_eval(&block) if block_given?
19
+ end
20
+ end
21
+ end
@@ -7,26 +7,50 @@ module TransactionHelpers
7
7
  end
8
8
  end
9
9
 
10
- def background_job_transaction(args = {})
11
- Appsignal::Transaction.new(
12
- "1",
13
- Appsignal::Transaction::BACKGROUND_JOB,
14
- Appsignal::Transaction::GenericRequest.new({
15
- "SERVER_NAME" => "localhost",
16
- "action_dispatch.routes" => "not_available"
17
- }.merge(args))
18
- )
19
- end
20
-
21
- def http_request_transaction(args = {})
22
- Appsignal::Transaction.new(
23
- "1",
24
- Appsignal::Transaction::HTTP_REQUEST,
25
- Appsignal::Transaction::GenericRequest.new({
26
- "SERVER_NAME" => "localhost",
27
- "action_dispatch.routes" => "not_available"
28
- }.merge(args))
29
- )
10
+ def default_namespace
11
+ Appsignal::Transaction::HTTP_REQUEST
12
+ end
13
+
14
+ def create_transaction(namespace = default_namespace)
15
+ Appsignal::Transaction.create(namespace)
16
+ end
17
+
18
+ def new_transaction(namespace = default_namespace)
19
+ Appsignal::Transaction.new(SecureRandom.uuid, namespace)
20
+ end
21
+
22
+ def legacy_create_transaction(
23
+ id: "mock_transaction_id",
24
+ namespace: "mock_namespace",
25
+ request: legacy_request,
26
+ options: {}
27
+ )
28
+ Appsignal::Transaction.create(id, namespace, request, options)
29
+ end
30
+
31
+ def legacy_new_transaction(
32
+ id: "mock_transaction_id",
33
+ namespace: "mock_namespace",
34
+ request: legacy_request,
35
+ options: {}
36
+ )
37
+ Appsignal::Transaction.new(id, namespace, request, options)
38
+ end
39
+
40
+ def legacy_request(env = {})
41
+ Appsignal::Transaction::InternalGenericRequest.new(env)
42
+ end
43
+
44
+ def rack_request(env)
45
+ Rack::Request.new(env)
46
+ end
47
+
48
+ def background_job_transaction
49
+ new_transaction(Appsignal::Transaction::BACKGROUND_JOB)
50
+ end
51
+
52
+ def http_request_transaction
53
+ new_transaction(Appsignal::Transaction::HTTP_REQUEST)
30
54
  end
31
55
 
32
56
  # Returns the all {Appsignal::Transaction} objects created during this test
@@ -180,6 +180,20 @@ RSpec::Matchers.alias_matcher :include_breadcrumbs, :include_breadcrumb
180
180
 
181
181
  RSpec::Matchers.define :have_queue_start do |queue_start_time|
182
182
  match(:notify_expectation_failures => true) do |transaction|
183
- expect(transaction.ext.queue_start).to eq(queue_start_time)
183
+ actual_start = transaction.ext.queue_start
184
+ if queue_start_time
185
+ expect(actual_start).to eq(queue_start_time)
186
+ else
187
+ expect(actual_start).to_not be_nil
188
+ end
189
+ end
190
+
191
+ match_when_negated(:notify_expectation_failures => true) do |transaction|
192
+ actual_start = transaction.ext.queue_start
193
+ if queue_start_time
194
+ expect(actual_start).to_not eq(queue_start_time)
195
+ else
196
+ expect(actual_start).to be_nil
197
+ end
184
198
  end
185
199
  end
@@ -0,0 +1,7 @@
1
+ module Appsignal
2
+ module Loaders
3
+ class LoaderStub < Loader
4
+ register :loader_stub
5
+ end
6
+ end
7
+ end
@@ -9,11 +9,55 @@ module Appsignal
9
9
  @testing = true unless defined?(@testing)
10
10
  @testing
11
11
  end
12
+
13
+ # @api private
14
+ def clear_started!
15
+ return unless instance_variable_defined?(:@started)
16
+
17
+ remove_instance_variable(:@started)
18
+ end
19
+
20
+ # @api private
21
+ def clear_config!
22
+ @config = nil
23
+ end
24
+
25
+ # @api private
26
+ def clear!
27
+ Appsignal.internal_logger = nil
28
+
29
+ clear_started!
30
+ clear_config!
31
+ end
32
+ end
33
+
34
+ class Config
35
+ def self.clear_loader_defaults!
36
+ @loader_defaults = nil
37
+ end
38
+ end
39
+
40
+ module Loaders
41
+ def self.clear!
42
+ Appsignal::Config.clear_loader_defaults!
43
+ loaders.reject! do |key, _value|
44
+ Appsignal::Testing.registered_loaders.include?(key)
45
+ end
46
+ @instances = nil
47
+ end
12
48
  end
13
49
 
14
50
  # @api private
15
51
  module Testing
16
52
  class << self
53
+ def store
54
+ @store ||= {}
55
+ end
56
+
57
+ def registered_loaders
58
+ @registered_loaders ||= Set.new
59
+ end
60
+
17
61
  def without_testing
18
62
  original_testing = Appsignal.testing?
19
63
  Appsignal.testing = false
@@ -27,7 +71,9 @@ module Appsignal
27
71
  end
28
72
 
29
73
  def clear!
74
+ store.clear
30
75
  transactions.clear
76
+ registered_loaders.clear
31
77
  end
32
78
 
33
79
  attr_writer :keep_transactions, :sample_transactions
@@ -134,7 +180,7 @@ module AppsignalTest
134
180
 
135
181
  module InstanceMethods
136
182
  def _sample
137
- sample_data
183
+ _sample_data
138
184
  end
139
185
  end
140
186
  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: 3.10.0
4
+ version: 3.12.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: 2024-07-08 00:00:00.000000000 Z
13
+ date: 2024-07-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -261,10 +261,16 @@ files:
261
261
  - lib/appsignal/integrations/redis.rb
262
262
  - lib/appsignal/integrations/redis_client.rb
263
263
  - lib/appsignal/integrations/resque.rb
264
+ - lib/appsignal/integrations/shoryuken.rb
264
265
  - lib/appsignal/integrations/sidekiq.rb
265
266
  - lib/appsignal/integrations/sinatra.rb
266
267
  - lib/appsignal/integrations/unicorn.rb
267
268
  - lib/appsignal/integrations/webmachine.rb
269
+ - lib/appsignal/loaders.rb
270
+ - lib/appsignal/loaders/grape.rb
271
+ - lib/appsignal/loaders/hanami.rb
272
+ - lib/appsignal/loaders/padrino.rb
273
+ - lib/appsignal/loaders/sinatra.rb
268
274
  - lib/appsignal/logger.rb
269
275
  - lib/appsignal/marker.rb
270
276
  - lib/appsignal/probes.rb
@@ -362,6 +368,8 @@ files:
362
368
  - spec/lib/appsignal/hooks/webmachine_spec.rb
363
369
  - spec/lib/appsignal/hooks_spec.rb
364
370
  - spec/lib/appsignal/integrations/data_mapper_spec.rb
371
+ - spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb
372
+ - spec/lib/appsignal/integrations/grape_spec.rb
365
373
  - spec/lib/appsignal/integrations/hanami_spec.rb
366
374
  - spec/lib/appsignal/integrations/http_spec.rb
367
375
  - spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb
@@ -370,9 +378,15 @@ files:
370
378
  - spec/lib/appsignal/integrations/padrino_spec.rb
371
379
  - spec/lib/appsignal/integrations/que_spec.rb
372
380
  - spec/lib/appsignal/integrations/railtie_spec.rb
381
+ - spec/lib/appsignal/integrations/shoryuken_spec.rb
373
382
  - spec/lib/appsignal/integrations/sidekiq_spec.rb
374
383
  - spec/lib/appsignal/integrations/sinatra_spec.rb
375
384
  - spec/lib/appsignal/integrations/webmachine_spec.rb
385
+ - spec/lib/appsignal/loaders/grape_spec.rb
386
+ - spec/lib/appsignal/loaders/hanami_spec.rb
387
+ - spec/lib/appsignal/loaders/padrino_spec.rb
388
+ - spec/lib/appsignal/loaders/sinatra_spec.rb
389
+ - spec/lib/appsignal/loaders_spec.rb
376
390
  - spec/lib/appsignal/logger_spec.rb
377
391
  - spec/lib/appsignal/marker_spec.rb
378
392
  - spec/lib/appsignal/probes/gvl_spec.rb
@@ -389,6 +403,7 @@ files:
389
403
  - spec/lib/appsignal/rack/rails_instrumentation_spec.rb
390
404
  - spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb
391
405
  - spec/lib/appsignal/rack/streaming_listener_spec.rb
406
+ - spec/lib/appsignal/rack_spec.rb
392
407
  - spec/lib/appsignal/span_spec.rb
393
408
  - spec/lib/appsignal/system_spec.rb
394
409
  - spec/lib/appsignal/transaction_spec.rb
@@ -423,6 +438,7 @@ files:
423
438
  - spec/support/helpers/environment_metdata_helper.rb
424
439
  - spec/support/helpers/example_exception.rb
425
440
  - spec/support/helpers/example_standard_error.rb
441
+ - spec/support/helpers/loader_helper.rb
426
442
  - spec/support/helpers/log_helpers.rb
427
443
  - spec/support/helpers/rails_helper.rb
428
444
  - spec/support/helpers/std_streams_helper.rb
@@ -440,6 +456,7 @@ files:
440
456
  - spec/support/mocks/mock_probe.rb
441
457
  - spec/support/rails/my_app.rb
442
458
  - spec/support/shared_examples/instrument.rb
459
+ - spec/support/stubs/appsignal/loaders/loader_stub.rb
443
460
  - spec/support/stubs/delayed_job.rb
444
461
  - spec/support/stubs/sidekiq/api.rb
445
462
  - spec/support/testing.rb