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
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Appsignal
4
+ # @api private
5
+ class SampleData
6
+ def initialize(key, accepted_type = nil)
7
+ @key = key
8
+ @accepted_type = accepted_type
9
+ @blocks = []
10
+ end
11
+
12
+ def add(data = nil, &block)
13
+ if block_given?
14
+ @blocks << block
15
+ elsif accepted_type?(data)
16
+ @blocks << data
17
+ else
18
+ log_unsupported_data_type(data)
19
+ end
20
+ end
21
+
22
+ def value
23
+ value = nil
24
+ @blocks.map! do |block_or_value|
25
+ new_value =
26
+ if block_or_value.respond_to?(:call)
27
+ block_or_value.call
28
+ else
29
+ block_or_value
30
+ end
31
+ unless accepted_type?(new_value)
32
+ log_unsupported_data_type(new_value)
33
+ next
34
+ end
35
+
36
+ value = merge_values(value, new_value)
37
+ new_value
38
+ end
39
+
40
+ value
41
+ end
42
+
43
+ def value?
44
+ @blocks.any?
45
+ end
46
+
47
+ protected
48
+
49
+ attr_reader :blocks
50
+
51
+ private
52
+
53
+ # Method called by `dup` and `clone` to create a duplicate instance.
54
+ # Make sure the `@blocks` variable is also properly duplicated.
55
+ def initialize_copy(original)
56
+ super
57
+
58
+ @blocks = original.blocks.dup
59
+ end
60
+
61
+ def accepted_type?(value)
62
+ if @accepted_type
63
+ value.is_a?(@accepted_type)
64
+ else
65
+ value.is_a?(Hash) || value.is_a?(Array)
66
+ end
67
+ end
68
+
69
+ def merge_values(value_original, value_new)
70
+ unless value_new.instance_of?(value_original.class)
71
+ Appsignal.internal_logger.warn(
72
+ "The sample data '#{@key}' changed type from " \
73
+ "'#{value_original.class}' to '#{value_new.class}'. " \
74
+ "These types can not be merged. Using new '#{value_new.class}' type."
75
+ )
76
+ return value_new
77
+ end
78
+
79
+ case value_original
80
+ when Hash
81
+ value_original.merge(value_new)
82
+ when Array
83
+ value_original + value_new
84
+ else
85
+ value_new
86
+ end
87
+ end
88
+
89
+ def log_unsupported_data_type(value)
90
+ Appsignal.internal_logger.error(
91
+ "Sample data '#{@key}': Unsupported data type '#{value.class}' received: #{value.inspect}"
92
+ )
93
+ end
94
+ end
95
+ end