appsignal 4.0.6 → 4.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/Rakefile +9 -9
  4. data/appsignal.gemspec +22 -1
  5. data/ext/agent.rb +27 -27
  6. data/lib/appsignal/check_in.rb +1 -1
  7. data/lib/appsignal/config.rb +1 -3
  8. data/lib/appsignal/integrations/resque.rb +1 -6
  9. data/lib/appsignal/utils/hash_sanitizer.rb +4 -0
  10. data/lib/appsignal/version.rb +1 -1
  11. data/lib/appsignal.rb +10 -8
  12. metadata +2 -192
  13. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  14. data/.github/ISSUE_TEMPLATE/chore.md +0 -14
  15. data/.github/workflows/ci.yml +0 -3285
  16. data/.github/workflows/create_release_from_tag.yml +0 -62
  17. data/.gitignore +0 -35
  18. data/.gitmodules +0 -3
  19. data/.rspec +0 -4
  20. data/.yardopts +0 -8
  21. data/benchmark.rake +0 -139
  22. data/gemfiles/capistrano2.gemfile +0 -6
  23. data/gemfiles/capistrano3.gemfile +0 -7
  24. data/gemfiles/dry-monitor.gemfile +0 -5
  25. data/gemfiles/grape.gemfile +0 -5
  26. data/gemfiles/hanami-2.0.gemfile +0 -7
  27. data/gemfiles/hanami-2.1.gemfile +0 -7
  28. data/gemfiles/http5.gemfile +0 -5
  29. data/gemfiles/no_dependencies.gemfile +0 -10
  30. data/gemfiles/padrino.gemfile +0 -7
  31. data/gemfiles/psych-3.gemfile +0 -5
  32. data/gemfiles/psych-4.gemfile +0 -5
  33. data/gemfiles/que-1.gemfile +0 -5
  34. data/gemfiles/que-2.gemfile +0 -5
  35. data/gemfiles/rails-6.0.gemfile +0 -10
  36. data/gemfiles/rails-6.1.gemfile +0 -11
  37. data/gemfiles/rails-7.0.gemfile +0 -11
  38. data/gemfiles/rails-7.1.gemfile +0 -11
  39. data/gemfiles/rails-7.2.gemfile +0 -11
  40. data/gemfiles/redis-4.gemfile +0 -5
  41. data/gemfiles/redis-5.gemfile +0 -6
  42. data/gemfiles/resque-2.gemfile +0 -6
  43. data/gemfiles/sequel.gemfile +0 -10
  44. data/gemfiles/sinatra.gemfile +0 -5
  45. data/gemfiles/webmachine1.gemfile +0 -7
  46. data/gemfiles/webmachine2.gemfile +0 -6
  47. data/mono.yml +0 -16
  48. data/spec/.rubocop.yml +0 -7
  49. data/spec/lib/appsignal/auth_check_spec.rb +0 -84
  50. data/spec/lib/appsignal/capistrano2_spec.rb +0 -227
  51. data/spec/lib/appsignal/capistrano3_spec.rb +0 -284
  52. data/spec/lib/appsignal/check_in/cron_spec.rb +0 -210
  53. data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -557
  54. data/spec/lib/appsignal/cli/demo_spec.rb +0 -46
  55. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +0 -16
  56. data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +0 -86
  57. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1553
  58. data/spec/lib/appsignal/cli/helpers_spec.rb +0 -179
  59. data/spec/lib/appsignal/cli/install_spec.rb +0 -848
  60. data/spec/lib/appsignal/cli_spec.rb +0 -56
  61. data/spec/lib/appsignal/config_spec.rb +0 -1380
  62. data/spec/lib/appsignal/demo_spec.rb +0 -83
  63. data/spec/lib/appsignal/environment_spec.rb +0 -190
  64. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +0 -60
  65. data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -21
  66. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -21
  67. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -52
  68. data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -21
  69. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -84
  70. data/spec/lib/appsignal/event_formatter/rom/sql_formatter_spec.rb +0 -22
  71. data/spec/lib/appsignal/event_formatter/sequel/sql_formatter_spec.rb +0 -30
  72. data/spec/lib/appsignal/event_formatter/view_component/render_formatter_spec.rb +0 -41
  73. data/spec/lib/appsignal/event_formatter_spec.rb +0 -193
  74. data/spec/lib/appsignal/extension/jruby_spec.rb +0 -46
  75. data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -20
  76. data/spec/lib/appsignal/extension_spec.rb +0 -178
  77. data/spec/lib/appsignal/garbage_collection_spec.rb +0 -98
  78. data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -345
  79. data/spec/lib/appsignal/hooks/action_mailer_spec.rb +0 -55
  80. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +0 -23
  81. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +0 -99
  82. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +0 -47
  83. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +0 -47
  84. data/spec/lib/appsignal/hooks/activejob_spec.rb +0 -650
  85. data/spec/lib/appsignal/hooks/at_exit_spec.rb +0 -105
  86. data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -40
  87. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -40
  88. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -38
  89. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +0 -83
  90. data/spec/lib/appsignal/hooks/excon_spec.rb +0 -67
  91. data/spec/lib/appsignal/hooks/gvl_spec.rb +0 -145
  92. data/spec/lib/appsignal/hooks/http_spec.rb +0 -37
  93. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -46
  94. data/spec/lib/appsignal/hooks/mri_spec.rb +0 -23
  95. data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -18
  96. data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -30
  97. data/spec/lib/appsignal/hooks/puma_spec.rb +0 -80
  98. data/spec/lib/appsignal/hooks/que_spec.rb +0 -19
  99. data/spec/lib/appsignal/hooks/rake_spec.rb +0 -144
  100. data/spec/lib/appsignal/hooks/redis_client_spec.rb +0 -218
  101. data/spec/lib/appsignal/hooks/redis_spec.rb +0 -124
  102. data/spec/lib/appsignal/hooks/resque_spec.rb +0 -27
  103. data/spec/lib/appsignal/hooks/sequel_spec.rb +0 -44
  104. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -29
  105. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +0 -115
  106. data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -63
  107. data/spec/lib/appsignal/hooks/webmachine_spec.rb +0 -24
  108. data/spec/lib/appsignal/hooks_spec.rb +0 -124
  109. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -74
  110. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +0 -454
  111. data/spec/lib/appsignal/integrations/http_spec.rb +0 -111
  112. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +0 -154
  113. data/spec/lib/appsignal/integrations/net_http_spec.rb +0 -33
  114. data/spec/lib/appsignal/integrations/object_spec.rb +0 -347
  115. data/spec/lib/appsignal/integrations/puma_spec.rb +0 -150
  116. data/spec/lib/appsignal/integrations/que_spec.rb +0 -187
  117. data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -457
  118. data/spec/lib/appsignal/integrations/resque_spec.rb +0 -155
  119. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +0 -165
  120. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +0 -640
  121. data/spec/lib/appsignal/integrations/webmachine_spec.rb +0 -136
  122. data/spec/lib/appsignal/loaders/grape_spec.rb +0 -12
  123. data/spec/lib/appsignal/loaders/hanami_spec.rb +0 -92
  124. data/spec/lib/appsignal/loaders/padrino_spec.rb +0 -273
  125. data/spec/lib/appsignal/loaders/sinatra_spec.rb +0 -44
  126. data/spec/lib/appsignal/loaders_spec.rb +0 -144
  127. data/spec/lib/appsignal/logger_spec.rb +0 -205
  128. data/spec/lib/appsignal/marker_spec.rb +0 -51
  129. data/spec/lib/appsignal/probes/gvl_spec.rb +0 -164
  130. data/spec/lib/appsignal/probes/mri_spec.rb +0 -162
  131. data/spec/lib/appsignal/probes/sidekiq_spec.rb +0 -333
  132. data/spec/lib/appsignal/probes_spec.rb +0 -414
  133. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +0 -370
  134. data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -319
  135. data/spec/lib/appsignal/rack/event_handler_spec.rb +0 -441
  136. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +0 -201
  137. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +0 -36
  138. data/spec/lib/appsignal/rack/instrumentation_middleware_spec.rb +0 -38
  139. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +0 -126
  140. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +0 -217
  141. data/spec/lib/appsignal/rack_spec.rb +0 -243
  142. data/spec/lib/appsignal/sample_data_spec.rb +0 -238
  143. data/spec/lib/appsignal/span_spec.rb +0 -141
  144. data/spec/lib/appsignal/system_spec.rb +0 -126
  145. data/spec/lib/appsignal/transaction_spec.rb +0 -2115
  146. data/spec/lib/appsignal/transmitter_spec.rb +0 -198
  147. data/spec/lib/appsignal/utils/data_spec.rb +0 -166
  148. data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +0 -182
  149. data/spec/lib/appsignal/utils/integration_logger_spec.rb +0 -21
  150. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -153
  151. data/spec/lib/appsignal/utils/json_spec.rb +0 -44
  152. data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -192
  153. data/spec/lib/appsignal_spec.rb +0 -1919
  154. data/spec/lib/puma/appsignal_spec.rb +0 -334
  155. data/spec/spec_helper.rb +0 -179
  156. data/spec/support/fixtures/generated_config.yml +0 -24
  157. data/spec/support/fixtures/projects/broken/config/appsignal.yml +0 -1
  158. data/spec/support/fixtures/projects/valid/config/appsignal.yml +0 -57
  159. data/spec/support/fixtures/projects/valid/log/.gitkeep +0 -0
  160. data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +0 -16
  161. data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +0 -56
  162. data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +0 -10
  163. data/spec/support/fixtures/projects/valid_with_rails_app/log/.gitkeep +0 -0
  164. data/spec/support/fixtures/uploaded_file.txt +0 -0
  165. data/spec/support/hanami/hanami_app.rb +0 -29
  166. data/spec/support/helpers/action_mailer_helpers.rb +0 -25
  167. data/spec/support/helpers/activejob_helpers.rb +0 -27
  168. data/spec/support/helpers/api_request_helper.rb +0 -60
  169. data/spec/support/helpers/cli_helpers.rb +0 -40
  170. data/spec/support/helpers/config_helpers.rb +0 -66
  171. data/spec/support/helpers/dependency_helper.rb +0 -155
  172. data/spec/support/helpers/directory_helper.rb +0 -27
  173. data/spec/support/helpers/env_helpers.rb +0 -41
  174. data/spec/support/helpers/environment_metdata_helper.rb +0 -16
  175. data/spec/support/helpers/example_exception.rb +0 -13
  176. data/spec/support/helpers/example_standard_error.rb +0 -13
  177. data/spec/support/helpers/loader_helper.rb +0 -21
  178. data/spec/support/helpers/log_helpers.rb +0 -36
  179. data/spec/support/helpers/rails_helper.rb +0 -28
  180. data/spec/support/helpers/std_streams_helper.rb +0 -94
  181. data/spec/support/helpers/system_helpers.rb +0 -8
  182. data/spec/support/helpers/take_at_most_helper.rb +0 -21
  183. data/spec/support/helpers/time_helpers.rb +0 -11
  184. data/spec/support/helpers/transaction_helpers.rb +0 -122
  185. data/spec/support/helpers/wait_for_helper.rb +0 -39
  186. data/spec/support/matchers/contains_log.rb +0 -26
  187. data/spec/support/matchers/have_colorized_text.rb +0 -28
  188. data/spec/support/matchers/transaction.rb +0 -200
  189. data/spec/support/mocks/appsignal_mock.rb +0 -18
  190. data/spec/support/mocks/dummy_app.rb +0 -20
  191. data/spec/support/mocks/fake_gc_profiler.rb +0 -19
  192. data/spec/support/mocks/fake_gvl_tools.rb +0 -28
  193. data/spec/support/mocks/hash_like.rb +0 -10
  194. data/spec/support/mocks/mock_probe.rb +0 -13
  195. data/spec/support/mocks/puma_mock.rb +0 -43
  196. data/spec/support/shared_examples/instrument.rb +0 -48
  197. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +0 -7
  198. data/spec/support/stubs/delayed_job.rb +0 -0
  199. data/spec/support/stubs/sidekiq/api.rb +0 -4
  200. data/spec/support/testing.rb +0 -203
  201. data/support/bundler_wrapper +0 -12
  202. data/support/install_deps +0 -33
@@ -1,136 +0,0 @@
1
- if DependencyHelper.webmachine_present?
2
- require "appsignal/integrations/webmachine"
3
-
4
- class Response
5
- attr_accessor :code
6
-
7
- def body
8
- ""
9
- end
10
-
11
- def headers
12
- {}
13
- end
14
- end
15
-
16
- describe Appsignal::Integrations::WebmachineIntegration do
17
- let(:request) do
18
- Webmachine::Request.new(
19
- "GET",
20
- "http://google.com:80/foo?param1=value1&param2=value2",
21
- {
22
- "REQUEST_METHOD" => "GET",
23
- "PATH_INFO" => "/some/path",
24
- "ignored_header" => "something"
25
- },
26
- nil
27
- )
28
- end
29
- let(:app) do
30
- proc do
31
- def to_html
32
- "Some HTML"
33
- end
34
- end
35
- end
36
- let(:resource) do
37
- app_block = app
38
- Class.new(Webmachine::Resource) do
39
- class_eval(&app_block) if app_block
40
-
41
- def self.name
42
- "MyResource"
43
- end
44
- end
45
- end
46
- let(:resource_instance) { resource.new(request, response) }
47
- let(:response) { Webmachine::Response.new }
48
- let(:fsm) { Webmachine::Decision::FSM.new(resource_instance, request, response) }
49
- before { start_agent }
50
- around { |example| keep_transactions { example.run } }
51
-
52
- describe "#run" do
53
- it "creates a transaction" do
54
- expect { fsm.run }.to(change { created_transactions.count }.by(1))
55
- end
56
-
57
- it "sets the action" do
58
- fsm.run
59
- expect(last_transaction).to have_action("MyResource#GET")
60
- end
61
-
62
- context "with action already set" do
63
- let(:app) do
64
- proc do
65
- def to_html
66
- Appsignal.set_action("Custom Action")
67
- "Some HTML"
68
- end
69
- end
70
- end
71
-
72
- it "doesn't overwrite the action" do
73
- fsm.run
74
- expect(last_transaction).to have_action("Custom Action")
75
- end
76
- end
77
-
78
- it "records an instrumentation event" do
79
- fsm.run
80
- expect(last_transaction).to include_event("name" => "process_action.webmachine")
81
- end
82
-
83
- it "sets the params" do
84
- fsm.run
85
- expect(last_transaction).to include_params("param1" => "value1", "param2" => "value2")
86
- end
87
-
88
- it "sets the headers" do
89
- fsm.run
90
- expect(last_transaction).to include_environment(
91
- "REQUEST_METHOD" => "GET",
92
- "PATH_INFO" => "/some/path"
93
- )
94
- end
95
-
96
- it "closes the transaction" do
97
- fsm.run
98
- expect(last_transaction).to be_completed
99
- expect(current_transaction?).to be_falsy
100
- end
101
-
102
- context "with parent transaction" do
103
- let(:transaction) { http_request_transaction }
104
- before { set_current_transaction(transaction) }
105
-
106
- it "sets the action" do
107
- fsm.run
108
- expect(last_transaction).to have_action("MyResource#GET")
109
- end
110
-
111
- it "sets the params" do
112
- fsm.run
113
- last_transaction._sample
114
- expect(last_transaction).to include_params("param1" => "value1", "param2" => "value2")
115
- end
116
-
117
- it "does not close the transaction" do
118
- expect(last_transaction).to_not be_completed
119
- end
120
- end
121
- end
122
-
123
- describe "#handle_exceptions" do
124
- let(:error) { ExampleException.new("error message") }
125
- let(:transaction) { http_request_transaction }
126
-
127
- it "tracks the error" do
128
- with_current_transaction(transaction) do
129
- fsm.send(:handle_exceptions) { raise error }
130
- end
131
-
132
- expect(last_transaction).to have_error("ExampleException", "error message")
133
- end
134
- end
135
- end
136
- end
@@ -1,12 +0,0 @@
1
- if DependencyHelper.grape_present?
2
- describe "Appsignal::Loaders::PadrinoLoader" do
3
- describe "#on_load" do
4
- it "ensures the Grape middleware is loaded" do
5
- load_loader(:grape)
6
-
7
- # Calling this doesn't raise a NameError
8
- Appsignal::Rack::GrapeMiddleware
9
- end
10
- end
11
- end
12
- end
@@ -1,92 +0,0 @@
1
- if DependencyHelper.hanami_present?
2
- describe "Appsignal::Loaders::HanamiLoader" do
3
- describe "#on_load" do
4
- it "registers Hanami default config" do
5
- load_loader(:hanami)
6
-
7
- expect(Appsignal::Config.loader_defaults).to include(
8
- :name => :hanami,
9
- :root_path => Dir.pwd,
10
- :env => :test,
11
- :options => {}
12
- )
13
- end
14
- end
15
-
16
- describe "#on_start" do
17
- before do
18
- allow(::Hanami::Action).to receive(:prepend)
19
- load_loader(:hanami)
20
- start_loader(:hanami)
21
- end
22
- after { uninstall_hanami_middleware }
23
-
24
- def uninstall_hanami_middleware
25
- middleware_stack = ::Hanami.app.config.middleware.stack[::Hanami::Router::DEFAULT_PREFIX]
26
- middleware_stack.delete_if do |middleware|
27
- middleware.first == Appsignal::Rack::HanamiMiddleware ||
28
- middleware.first == Rack::Events
29
- end
30
- end
31
-
32
- it "adds the instrumentation middleware to Sinatra::Base" do
33
- expect(::Hanami.app.config.middleware.stack[::Hanami::Router::DEFAULT_PREFIX])
34
- .to include(
35
- [Rack::Events, [[kind_of(Appsignal::Rack::EventHandler)]], *hanami_middleware_options],
36
- [Appsignal::Rack::HanamiMiddleware, [], *hanami_middleware_options]
37
- )
38
- end
39
-
40
- it "prepends the integration to Hanami::Action" do
41
- expect(::Hanami::Action)
42
- .to have_received(:prepend).with(Appsignal::Loaders::HanamiLoader::HanamiIntegration)
43
- end
44
-
45
- def hanami_middleware_options
46
- if DependencyHelper.hanami2_1_present?
47
- [{}, nil]
48
- else
49
- [nil]
50
- end
51
- end
52
- end
53
-
54
- describe "Appsignal::Loaders::HanamiLoader::HanamiIntegration" do
55
- let(:transaction) { http_request_transaction }
56
- let(:app) { HanamiApp::Actions::Books::Index }
57
- around { |example| keep_transactions { example.run } }
58
- before do
59
- expect(::Hanami.app.config).to receive(:root).and_return(project_fixture_path)
60
- Appsignal.load(:hanami)
61
- start_agent
62
- end
63
-
64
- def make_request(env)
65
- action = app.new
66
- action.call(env)
67
- end
68
-
69
- describe "#call" do
70
- context "without an active transaction" do
71
- let(:env) { {} }
72
-
73
- it "does not set the action name" do
74
- make_request(env)
75
-
76
- expect(transaction).to_not have_action
77
- end
78
- end
79
-
80
- context "with an active transaction" do
81
- let(:env) { { Appsignal::Rack::APPSIGNAL_TRANSACTION => transaction } }
82
-
83
- it "sets action name on the transaction" do
84
- make_request(env)
85
-
86
- expect(transaction).to have_action("HanamiApp::Actions::Books::Index")
87
- end
88
- end
89
- end
90
- end
91
- end
92
- end
@@ -1,273 +0,0 @@
1
- if DependencyHelper.padrino_present?
2
- describe "Appsignal::Loaders::PadrinoLoader" do
3
- describe "#on_load" do
4
- it "registers Padrino default config" do
5
- load_loader(:padrino)
6
-
7
- expect(Appsignal::Config.loader_defaults).to include(
8
- :name => :padrino,
9
- :root_path => Padrino.mounted_root,
10
- :env => :test,
11
- :options => {}
12
- )
13
- end
14
- end
15
-
16
- describe "#on_start" do
17
- let(:callbacks) { { :before_load => nil } }
18
- before do
19
- allow(Padrino).to receive(:before_load)
20
- .and_wrap_original do |original_method, *args, &block|
21
- callbacks[:before_load] = block
22
- original_method.call(*args, &block)
23
- end
24
- end
25
- after { uninstall_padrino_integration }
26
-
27
- def uninstall_padrino_integration
28
- expected_middleware = [
29
- Rack::Events,
30
- Appsignal::Rack::SinatraBaseInstrumentation
31
- ]
32
- Padrino.middleware.delete_if do |middleware|
33
- expected_middleware.include?(middleware.first)
34
- end
35
- end
36
-
37
- it "adds the instrumentation middleware to Padrino" do
38
- load_loader(:padrino)
39
- start_loader(:padrino)
40
-
41
- callbacks[:before_load].call
42
-
43
- middlewares = Padrino.middleware
44
- expect(middlewares).to include(
45
- [Rack::Events, [[instance_of(Appsignal::Rack::EventHandler)]], nil]
46
- )
47
- expect(middlewares).to include(
48
- [
49
- Appsignal::Rack::SinatraBaseInstrumentation,
50
- [
51
- :instrument_event_name => "process_action.padrino"
52
- ],
53
- nil
54
- ]
55
- )
56
- end
57
- end
58
-
59
- describe "Padrino integration" do
60
- class PadrinoClassWithRouter
61
- include Padrino::Routing
62
- end
63
-
64
- let(:base) { double }
65
- let(:router) { PadrinoClassWithRouter.new }
66
- let(:env) { {} }
67
- # TODO: use an instance double
68
- let(:settings) { double(:name => "TestApp") }
69
- around { |example| keep_transactions { example.run } }
70
-
71
- describe "routes" do
72
- let(:env) do
73
- {
74
- "REQUEST_METHOD" => "GET",
75
- "PATH_INFO" => path,
76
- "REQUEST_PATH" => path,
77
- "rack.input" => StringIO.new
78
- }
79
- end
80
- let(:app) do
81
- Class.new(Padrino::Application) do
82
- def self.name
83
- "PadrinoTestApp"
84
- end
85
- end
86
- end
87
- let(:response) { app.call(env) }
88
-
89
- def fetch_body(body)
90
- if body.respond_to?(:response)
91
- _, _, nested_body = body.response.to_a
92
- fetch_body(nested_body)
93
- elsif body.respond_to?(:to_ary)
94
- body.to_ary
95
- else
96
- body
97
- end
98
- end
99
-
100
- RSpec::Matchers.define :match_response do |expected_status, expected_body|
101
- match do |response|
102
- status, _headers, potential_body = response
103
- body = fetch_body(potential_body)
104
-
105
- matches_body =
106
- if expected_body.is_a?(Regexp)
107
- body.join =~ expected_body
108
- else
109
- body == [expected_body].compact
110
- end
111
- status == expected_status && matches_body
112
- end
113
- end
114
-
115
- context "when AppSignal is not active" do
116
- let(:path) { "/foo" }
117
- before { app.controllers { get(:foo) { "content" } } }
118
-
119
- it "does not instrument the request" do
120
- expect do
121
- expect(response).to match_response(200, "content")
122
- end.to_not(change { created_transactions.count })
123
- end
124
- end
125
-
126
- context "when AppSignal is active" do
127
- let(:transaction) { http_request_transaction }
128
- before do
129
- start_agent
130
- set_current_transaction(transaction)
131
- end
132
-
133
- context "with not existing route" do
134
- let(:path) { "/404" }
135
-
136
- it "instruments the request" do
137
- expect(response).to match_response(404, /^GET /404/)
138
- expect(last_transaction).to have_action("PadrinoTestApp#unknown")
139
- end
140
- end
141
-
142
- context "when Sinatra tells us it's a static file" do
143
- let(:path) { "/static" }
144
- before do
145
- env["sinatra.static_file"] = true
146
- app.controllers { get(:static) { "Static!" } }
147
- end
148
-
149
- it "does not instrument the request" do
150
- expect(response).to match_response(200, "Static!")
151
- expect(last_transaction).to_not have_action
152
- end
153
- end
154
-
155
- # Older Padrino versions don't support `action` (v11.0+)
156
- context "without #action on Sinatra::Request" do
157
- let(:path) { "/my_original_path/10" }
158
- before do
159
- allow_any_instance_of(Sinatra::Request).to receive(:action).and_return(nil)
160
- app.controllers { get(:my_original_path, :with => :id) { "content" } }
161
- end
162
-
163
- it "falls back on Sinatra::Request#route_obj.original_path" do
164
- expect(response).to match_response(200, "content")
165
- expect(last_transaction).to have_action("PadrinoTestApp:/my_original_path/:id")
166
- end
167
- end
168
-
169
- context "without Sinatra::Request#route_obj.original_path" do
170
- let(:path) { "/my_original_path" }
171
- before do
172
- allow_any_instance_of(Sinatra::Request).to receive(:action).and_return(nil)
173
- allow_any_instance_of(Sinatra::Request).to receive(:route_obj).and_return(nil)
174
- app.controllers { get(:my_original_path) { "content" } }
175
- end
176
-
177
- it "falls back on app name" do
178
- expect(response).to match_response(200, "content")
179
- expect(last_transaction).to have_action("PadrinoTestApp#unknown")
180
- end
181
- end
182
-
183
- context "with existing route" do
184
- let(:path) { "/" }
185
- def make_request
186
- expect(response).to match_response(200, "content")
187
- end
188
-
189
- context "with action name as symbol" do
190
- context "with :index helper" do
191
- before do
192
- # :index == "/"
193
- app.controllers { get(:index) { "content" } }
194
- end
195
-
196
- it "sets the action with the app name and action name" do
197
- make_request
198
- expect(last_transaction).to have_action("PadrinoTestApp:#index")
199
- end
200
- end
201
-
202
- context "with custom action name" do
203
- let(:path) { "/foo" }
204
- before do
205
- app.controllers { get(:foo) { "content" } }
206
- end
207
-
208
- it "sets the action with the app name and action name" do
209
- make_request
210
- expect(last_transaction).to have_action("PadrinoTestApp:#foo")
211
- end
212
- end
213
- end
214
-
215
- context "with an action defined with a path" do
216
- context "with root path" do
217
- before do
218
- # :index == "/"
219
- app.controllers { get("/") { "content" } }
220
- end
221
-
222
- it "sets the action with the app name and action path" do
223
- make_request
224
- expect(last_transaction).to have_action("PadrinoTestApp:#/")
225
- end
226
- end
227
-
228
- context "with custom path" do
229
- let(:path) { "/foo" }
230
- before do
231
- app.controllers { get("/foo") { "content" } }
232
- end
233
-
234
- it "sets the action with the app name and action path" do
235
- make_request
236
- expect(last_transaction).to have_action("PadrinoTestApp:#/foo")
237
- end
238
- end
239
- end
240
-
241
- context "with controller" do
242
- let(:path) { "/my_controller" }
243
-
244
- context "with controller as name" do
245
- before do
246
- # :index == "/"
247
- app.controllers(:my_controller) { get(:index) { "content" } }
248
- end
249
-
250
- it "sets the action with the app name, controller name and action name" do
251
- make_request
252
- expect(last_transaction).to have_action("PadrinoTestApp:my_controller#index")
253
- end
254
- end
255
-
256
- context "with controller as path" do
257
- before do
258
- # :index == "/"
259
- app.controllers("/my_controller") { get(:index) { "content" } }
260
- end
261
-
262
- it "sets the action with the app name, controller name and action path" do
263
- make_request
264
- expect(last_transaction).to have_action("PadrinoTestApp:/my_controller#index")
265
- end
266
- end
267
- end
268
- end
269
- end
270
- end
271
- end
272
- end
273
- end
@@ -1,44 +0,0 @@
1
- if DependencyHelper.sinatra_present?
2
- describe "Appsignal::Loaders::SinatraLoader" do
3
- describe "#on_load" do
4
- it "registers Sinatra default config" do
5
- ::Sinatra::Application.settings.root = "/some/path"
6
- load_loader(:sinatra)
7
-
8
- expect(Appsignal::Config.loader_defaults).to include(
9
- :name => :sinatra,
10
- :root_path => "/some/path",
11
- :env => :test,
12
- :options => {}
13
- )
14
- end
15
- end
16
-
17
- describe "#on_start" do
18
- after { uninstall_sinatra_integration }
19
-
20
- def uninstall_sinatra_integration
21
- expected_middleware = [
22
- Rack::Events,
23
- Appsignal::Rack::SinatraBaseInstrumentation
24
- ]
25
- Sinatra::Base.instance_variable_get(:@middleware).delete_if do |middleware|
26
- expected_middleware.include?(middleware.first)
27
- end
28
- end
29
-
30
- it "adds the instrumentation middleware to Sinatra::Base" do
31
- load_loader(:sinatra)
32
- start_loader(:sinatra)
33
-
34
- middlewares = Sinatra::Base.middleware.to_a
35
- expect(middlewares).to include(
36
- [Rack::Events, [[instance_of(Appsignal::Rack::EventHandler)]], nil]
37
- )
38
- expect(middlewares).to include(
39
- [Appsignal::Rack::SinatraBaseInstrumentation, [], nil]
40
- )
41
- end
42
- end
43
- end
44
- end
@@ -1,144 +0,0 @@
1
- describe Appsignal::Loaders do
2
- describe ".register" do
3
- before do
4
- define_loader(:test_loader) do
5
- def on_load
6
- puts "do something on_load"
7
- register_config_defaults(
8
- :root_path => "/some/path",
9
- :env => "test env",
10
- :active => false
11
- )
12
- end
13
- end
14
- end
15
-
16
- it "registers a loader" do
17
- define_loader(:test_loader)
18
- expect(Appsignal::Loaders.loaders).to have_key(:test_loader)
19
- end
20
- end
21
-
22
- describe ".unregister" do
23
- it "unregisters a loader" do
24
- define_loader(:test_loader)
25
- expect(Appsignal::Loaders.loaders).to have_key(:test_loader)
26
-
27
- Appsignal::Loaders.unregister(:test_loader)
28
- expect(Appsignal::Loaders.loaders).to_not have_key(:test_loader)
29
- end
30
- end
31
-
32
- describe ".load" do
33
- it "calls the Loader's on_loader method" do
34
- Appsignal::Testing.store[:loader_loaded] = 0
35
- define_loader(:test_loader) do
36
- def on_load
37
- Appsignal::Testing.store[:loader_loaded] += 1
38
- end
39
- end
40
- Appsignal::Loaders.load(:test_loader)
41
-
42
- expect(Appsignal::Testing.store[:loader_loaded]).to eq(1)
43
- end
44
-
45
- it "registers config defaults" do
46
- define_loader(:test_loader) do
47
- def on_load
48
- register_config_defaults(:my_option => true)
49
- end
50
- end
51
- Appsignal::Loaders.load(:test_loader)
52
-
53
- expect(Appsignal::Config.loader_defaults).to eq([
54
- {
55
- :name => :test_loader,
56
- :env => nil,
57
- :root_path => nil,
58
- :options => { :my_option => true }
59
- }
60
- ])
61
- end
62
-
63
- it "does not load errors that aren't registered" do
64
- logs =
65
- capture_logs do
66
- Appsignal::Loaders.load(:unknown_loader)
67
- end
68
-
69
- expect(logs).to contains_log(:warn, "No loader found with the name 'unknown_loader'.")
70
- end
71
-
72
- it "loads the loader file on load" do
73
- expect(Appsignal::Loaders.registered?(:loader_stub)).to be_falsy
74
- Appsignal::Loaders.load(:loader_stub)
75
-
76
- expect(Appsignal::Loaders.registered?(:loader_stub)).to be_truthy
77
- end
78
-
79
- it "does not error when a loader has no on_load method" do
80
- define_loader(:test_loader) do
81
- # Do nothing
82
- end
83
- Appsignal::Loaders.load(:test_loader)
84
- end
85
-
86
- it "logs an error when an error occurs on load" do
87
- define_loader(:test_loader) do
88
- def on_load
89
- raise ExampleStandardError, "uh oh"
90
- end
91
- end
92
- logs =
93
- capture_logs do
94
- Appsignal::Loaders.load(:test_loader)
95
- end
96
-
97
- expect(logs).to contains_log(
98
- :error,
99
- "An error occurred while loading the 'test_loader' loader: ExampleStandardError: uh oh"
100
- )
101
- end
102
- end
103
-
104
- describe ".start" do
105
- it "starts all loaded loaders" do
106
- Appsignal::Testing.store[:loader_started] = 0
107
- define_loader(:test_loader) do
108
- def on_start
109
- Appsignal::Testing.store[:loader_started] += 1
110
- end
111
- end
112
- Appsignal::Loaders.load(:test_loader)
113
- Appsignal::Loaders.start
114
-
115
- expect(Appsignal::Testing.store[:loader_started]).to eq(1)
116
- end
117
-
118
- it "does not error when a loader has no on_start method" do
119
- define_loader(:test_loader) do
120
- # Do nothing
121
- end
122
- Appsignal::Loaders.load(:test_loader)
123
- Appsignal::Loaders.start
124
- end
125
-
126
- it "logs an error when an error occurs on start" do
127
- define_loader(:test_loader) do
128
- def on_start
129
- raise ExampleStandardError, "uh oh"
130
- end
131
- end
132
- logs =
133
- capture_logs do
134
- Appsignal::Loaders.load(:test_loader)
135
- Appsignal::Loaders.start
136
- end
137
-
138
- expect(logs).to contains_log(
139
- :error,
140
- "An error occurred while starting the 'test_loader' loader: ExampleStandardError: uh oh"
141
- )
142
- end
143
- end
144
- end