appsignal 4.0.6-java → 4.0.7-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -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. metadata +2 -192
  12. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  13. data/.github/ISSUE_TEMPLATE/chore.md +0 -14
  14. data/.github/workflows/ci.yml +0 -3285
  15. data/.github/workflows/create_release_from_tag.yml +0 -62
  16. data/.gitignore +0 -35
  17. data/.gitmodules +0 -3
  18. data/.rspec +0 -4
  19. data/.yardopts +0 -8
  20. data/benchmark.rake +0 -139
  21. data/gemfiles/capistrano2.gemfile +0 -6
  22. data/gemfiles/capistrano3.gemfile +0 -7
  23. data/gemfiles/dry-monitor.gemfile +0 -5
  24. data/gemfiles/grape.gemfile +0 -5
  25. data/gemfiles/hanami-2.0.gemfile +0 -7
  26. data/gemfiles/hanami-2.1.gemfile +0 -7
  27. data/gemfiles/http5.gemfile +0 -5
  28. data/gemfiles/no_dependencies.gemfile +0 -10
  29. data/gemfiles/padrino.gemfile +0 -7
  30. data/gemfiles/psych-3.gemfile +0 -5
  31. data/gemfiles/psych-4.gemfile +0 -5
  32. data/gemfiles/que-1.gemfile +0 -5
  33. data/gemfiles/que-2.gemfile +0 -5
  34. data/gemfiles/rails-6.0.gemfile +0 -10
  35. data/gemfiles/rails-6.1.gemfile +0 -11
  36. data/gemfiles/rails-7.0.gemfile +0 -11
  37. data/gemfiles/rails-7.1.gemfile +0 -11
  38. data/gemfiles/rails-7.2.gemfile +0 -11
  39. data/gemfiles/redis-4.gemfile +0 -5
  40. data/gemfiles/redis-5.gemfile +0 -6
  41. data/gemfiles/resque-2.gemfile +0 -6
  42. data/gemfiles/sequel.gemfile +0 -10
  43. data/gemfiles/sinatra.gemfile +0 -5
  44. data/gemfiles/webmachine1.gemfile +0 -7
  45. data/gemfiles/webmachine2.gemfile +0 -6
  46. data/mono.yml +0 -16
  47. data/spec/.rubocop.yml +0 -7
  48. data/spec/lib/appsignal/auth_check_spec.rb +0 -84
  49. data/spec/lib/appsignal/capistrano2_spec.rb +0 -227
  50. data/spec/lib/appsignal/capistrano3_spec.rb +0 -284
  51. data/spec/lib/appsignal/check_in/cron_spec.rb +0 -210
  52. data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -557
  53. data/spec/lib/appsignal/cli/demo_spec.rb +0 -46
  54. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +0 -16
  55. data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +0 -86
  56. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1553
  57. data/spec/lib/appsignal/cli/helpers_spec.rb +0 -179
  58. data/spec/lib/appsignal/cli/install_spec.rb +0 -848
  59. data/spec/lib/appsignal/cli_spec.rb +0 -56
  60. data/spec/lib/appsignal/config_spec.rb +0 -1380
  61. data/spec/lib/appsignal/demo_spec.rb +0 -83
  62. data/spec/lib/appsignal/environment_spec.rb +0 -190
  63. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +0 -60
  64. data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -21
  65. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -21
  66. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -52
  67. data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -21
  68. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -84
  69. data/spec/lib/appsignal/event_formatter/rom/sql_formatter_spec.rb +0 -22
  70. data/spec/lib/appsignal/event_formatter/sequel/sql_formatter_spec.rb +0 -30
  71. data/spec/lib/appsignal/event_formatter/view_component/render_formatter_spec.rb +0 -41
  72. data/spec/lib/appsignal/event_formatter_spec.rb +0 -193
  73. data/spec/lib/appsignal/extension/jruby_spec.rb +0 -46
  74. data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -20
  75. data/spec/lib/appsignal/extension_spec.rb +0 -178
  76. data/spec/lib/appsignal/garbage_collection_spec.rb +0 -98
  77. data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -345
  78. data/spec/lib/appsignal/hooks/action_mailer_spec.rb +0 -55
  79. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +0 -23
  80. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +0 -99
  81. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +0 -47
  82. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +0 -47
  83. data/spec/lib/appsignal/hooks/activejob_spec.rb +0 -650
  84. data/spec/lib/appsignal/hooks/at_exit_spec.rb +0 -105
  85. data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -40
  86. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -40
  87. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -38
  88. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +0 -83
  89. data/spec/lib/appsignal/hooks/excon_spec.rb +0 -67
  90. data/spec/lib/appsignal/hooks/gvl_spec.rb +0 -145
  91. data/spec/lib/appsignal/hooks/http_spec.rb +0 -37
  92. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -46
  93. data/spec/lib/appsignal/hooks/mri_spec.rb +0 -23
  94. data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -18
  95. data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -30
  96. data/spec/lib/appsignal/hooks/puma_spec.rb +0 -80
  97. data/spec/lib/appsignal/hooks/que_spec.rb +0 -19
  98. data/spec/lib/appsignal/hooks/rake_spec.rb +0 -144
  99. data/spec/lib/appsignal/hooks/redis_client_spec.rb +0 -218
  100. data/spec/lib/appsignal/hooks/redis_spec.rb +0 -124
  101. data/spec/lib/appsignal/hooks/resque_spec.rb +0 -27
  102. data/spec/lib/appsignal/hooks/sequel_spec.rb +0 -44
  103. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -29
  104. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +0 -115
  105. data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -63
  106. data/spec/lib/appsignal/hooks/webmachine_spec.rb +0 -24
  107. data/spec/lib/appsignal/hooks_spec.rb +0 -124
  108. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -74
  109. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +0 -454
  110. data/spec/lib/appsignal/integrations/http_spec.rb +0 -111
  111. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +0 -154
  112. data/spec/lib/appsignal/integrations/net_http_spec.rb +0 -33
  113. data/spec/lib/appsignal/integrations/object_spec.rb +0 -347
  114. data/spec/lib/appsignal/integrations/puma_spec.rb +0 -150
  115. data/spec/lib/appsignal/integrations/que_spec.rb +0 -187
  116. data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -457
  117. data/spec/lib/appsignal/integrations/resque_spec.rb +0 -155
  118. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +0 -165
  119. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +0 -640
  120. data/spec/lib/appsignal/integrations/webmachine_spec.rb +0 -136
  121. data/spec/lib/appsignal/loaders/grape_spec.rb +0 -12
  122. data/spec/lib/appsignal/loaders/hanami_spec.rb +0 -92
  123. data/spec/lib/appsignal/loaders/padrino_spec.rb +0 -273
  124. data/spec/lib/appsignal/loaders/sinatra_spec.rb +0 -44
  125. data/spec/lib/appsignal/loaders_spec.rb +0 -144
  126. data/spec/lib/appsignal/logger_spec.rb +0 -205
  127. data/spec/lib/appsignal/marker_spec.rb +0 -51
  128. data/spec/lib/appsignal/probes/gvl_spec.rb +0 -164
  129. data/spec/lib/appsignal/probes/mri_spec.rb +0 -162
  130. data/spec/lib/appsignal/probes/sidekiq_spec.rb +0 -333
  131. data/spec/lib/appsignal/probes_spec.rb +0 -414
  132. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +0 -370
  133. data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -319
  134. data/spec/lib/appsignal/rack/event_handler_spec.rb +0 -441
  135. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +0 -201
  136. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +0 -36
  137. data/spec/lib/appsignal/rack/instrumentation_middleware_spec.rb +0 -38
  138. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +0 -126
  139. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +0 -217
  140. data/spec/lib/appsignal/rack_spec.rb +0 -243
  141. data/spec/lib/appsignal/sample_data_spec.rb +0 -238
  142. data/spec/lib/appsignal/span_spec.rb +0 -141
  143. data/spec/lib/appsignal/system_spec.rb +0 -126
  144. data/spec/lib/appsignal/transaction_spec.rb +0 -2115
  145. data/spec/lib/appsignal/transmitter_spec.rb +0 -198
  146. data/spec/lib/appsignal/utils/data_spec.rb +0 -166
  147. data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +0 -182
  148. data/spec/lib/appsignal/utils/integration_logger_spec.rb +0 -21
  149. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -153
  150. data/spec/lib/appsignal/utils/json_spec.rb +0 -44
  151. data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -192
  152. data/spec/lib/appsignal_spec.rb +0 -1919
  153. data/spec/lib/puma/appsignal_spec.rb +0 -334
  154. data/spec/spec_helper.rb +0 -179
  155. data/spec/support/fixtures/generated_config.yml +0 -24
  156. data/spec/support/fixtures/projects/broken/config/appsignal.yml +0 -1
  157. data/spec/support/fixtures/projects/valid/config/appsignal.yml +0 -57
  158. data/spec/support/fixtures/projects/valid/log/.gitkeep +0 -0
  159. data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +0 -16
  160. data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +0 -56
  161. data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +0 -10
  162. data/spec/support/fixtures/projects/valid_with_rails_app/log/.gitkeep +0 -0
  163. data/spec/support/fixtures/uploaded_file.txt +0 -0
  164. data/spec/support/hanami/hanami_app.rb +0 -29
  165. data/spec/support/helpers/action_mailer_helpers.rb +0 -25
  166. data/spec/support/helpers/activejob_helpers.rb +0 -27
  167. data/spec/support/helpers/api_request_helper.rb +0 -60
  168. data/spec/support/helpers/cli_helpers.rb +0 -40
  169. data/spec/support/helpers/config_helpers.rb +0 -66
  170. data/spec/support/helpers/dependency_helper.rb +0 -155
  171. data/spec/support/helpers/directory_helper.rb +0 -27
  172. data/spec/support/helpers/env_helpers.rb +0 -41
  173. data/spec/support/helpers/environment_metdata_helper.rb +0 -16
  174. data/spec/support/helpers/example_exception.rb +0 -13
  175. data/spec/support/helpers/example_standard_error.rb +0 -13
  176. data/spec/support/helpers/loader_helper.rb +0 -21
  177. data/spec/support/helpers/log_helpers.rb +0 -36
  178. data/spec/support/helpers/rails_helper.rb +0 -28
  179. data/spec/support/helpers/std_streams_helper.rb +0 -94
  180. data/spec/support/helpers/system_helpers.rb +0 -8
  181. data/spec/support/helpers/take_at_most_helper.rb +0 -21
  182. data/spec/support/helpers/time_helpers.rb +0 -11
  183. data/spec/support/helpers/transaction_helpers.rb +0 -122
  184. data/spec/support/helpers/wait_for_helper.rb +0 -39
  185. data/spec/support/matchers/contains_log.rb +0 -26
  186. data/spec/support/matchers/have_colorized_text.rb +0 -28
  187. data/spec/support/matchers/transaction.rb +0 -200
  188. data/spec/support/mocks/appsignal_mock.rb +0 -18
  189. data/spec/support/mocks/dummy_app.rb +0 -20
  190. data/spec/support/mocks/fake_gc_profiler.rb +0 -19
  191. data/spec/support/mocks/fake_gvl_tools.rb +0 -28
  192. data/spec/support/mocks/hash_like.rb +0 -10
  193. data/spec/support/mocks/mock_probe.rb +0 -13
  194. data/spec/support/mocks/puma_mock.rb +0 -43
  195. data/spec/support/shared_examples/instrument.rb +0 -48
  196. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +0 -7
  197. data/spec/support/stubs/delayed_job.rb +0 -0
  198. data/spec/support/stubs/sidekiq/api.rb +0 -4
  199. data/spec/support/testing.rb +0 -203
  200. data/support/bundler_wrapper +0 -12
  201. data/support/install_deps +0 -33
@@ -1,38 +0,0 @@
1
- describe Appsignal::Rack::InstrumentationMiddleware do
2
- let(:app) { DummyApp.new }
3
- let(:env) { Rack::MockRequest.env_for("/some/path") }
4
- let(:middleware) { described_class.new(app, {}) }
5
-
6
- before { start_agent }
7
- around { |example| keep_transactions { example.run } }
8
-
9
- def make_request(env)
10
- middleware.call(env)
11
- end
12
-
13
- context "without an exception" do
14
- it "reports a process_request_middleware.rack event" do
15
- make_request(env)
16
-
17
- expect(last_transaction).to include_event("name" => "process_request_middleware.rack")
18
- end
19
- end
20
-
21
- context "with custom action name" do
22
- let(:app) { DummyApp.new { |_env| Appsignal.set_action("MyAction") } }
23
-
24
- it "reports the custom action name" do
25
- make_request(env)
26
-
27
- expect(last_transaction).to have_action("MyAction")
28
- end
29
- end
30
-
31
- context "without action name metadata" do
32
- it "reports no action name" do
33
- make_request(env)
34
-
35
- expect(last_transaction).to_not have_action
36
- end
37
- end
38
- end
@@ -1,126 +0,0 @@
1
- if DependencyHelper.rails_present?
2
- describe Appsignal::Rack::RailsInstrumentation do
3
- class MockController; end
4
-
5
- let(:transaction) { new_transaction }
6
- let(:app) { DummyApp.new }
7
- let(:params) do
8
- {
9
- "controller" => "blog_posts",
10
- "action" => "show",
11
- "id" => "1",
12
- "my_custom_param" => "my custom secret",
13
- "password" => "super secret"
14
- }
15
- end
16
- let(:env) do
17
- http_request_env_with_data(
18
- :params => params,
19
- :with_queue_start => true,
20
- "action_dispatch.request_id" => "request_id123",
21
- "action_dispatch.parameter_filter" => [:my_custom_param, :password],
22
- "action_controller.instance" => double(
23
- :class => MockController,
24
- :action_name => "index"
25
- )
26
- )
27
- end
28
- let(:middleware) { Appsignal::Rack::RailsInstrumentation.new(app, {}) }
29
- around { |example| keep_transactions { example.run } }
30
- before do
31
- start_agent
32
- env[Appsignal::Rack::APPSIGNAL_TRANSACTION] = transaction
33
- end
34
-
35
- def make_request
36
- middleware.call(env)
37
- last_transaction&._sample
38
- end
39
-
40
- def make_request_with_error(error_class, error_message)
41
- expect { make_request }.to raise_error(error_class, error_message)
42
- end
43
-
44
- context "with a request that doesn't raise an error" do
45
- before { make_request }
46
-
47
- it "calls the next middleware in the stack" do
48
- expect(app).to be_called
49
- end
50
-
51
- it "does not instrument an event" do
52
- expect(last_transaction).to_not include_events
53
- end
54
- end
55
-
56
- context "with a request that raises an error" do
57
- let(:app) do
58
- DummyApp.new { |_env| raise ExampleException, "error message" }
59
- end
60
- before do
61
- make_request_with_error(ExampleException, "error message")
62
- end
63
-
64
- it "calls the next middleware in the stack" do
65
- expect(app).to be_called
66
- end
67
-
68
- it "reports the error on the transaction" do
69
- expect(last_transaction).to have_error("ExampleException", "error message")
70
- end
71
- end
72
-
73
- it "sets the controller action as the action name" do
74
- make_request
75
-
76
- expect(last_transaction).to have_namespace(Appsignal::Transaction::HTTP_REQUEST)
77
- expect(last_transaction).to have_action("MockController#index")
78
- end
79
-
80
- it "sets request metadata on the transaction" do
81
- make_request
82
-
83
- expect(last_transaction).to include_metadata(
84
- "method" => "GET",
85
- "path" => "/blog"
86
- )
87
- expect(last_transaction).to include_tags("request_id" => "request_id123")
88
- end
89
-
90
- it "reports Rails filter parameters" do
91
- make_request
92
-
93
- expect(last_transaction).to include_params(
94
- "controller" => "blog_posts",
95
- "action" => "show",
96
- "id" => "1",
97
- "my_custom_param" => "[FILTERED]",
98
- "password" => "[FILTERED]"
99
- )
100
- end
101
-
102
- context "with an invalid HTTP request method" do
103
- it "does not store the invalid HTTP request method" do
104
- env[:request_method] = "FOO"
105
- env["REQUEST_METHOD"] = "FOO"
106
- logs = capture_logs { make_request }
107
-
108
- expect(last_transaction).to_not include_metadata("method" => anything)
109
- expect(logs).to contains_log(
110
- :error,
111
- "Exception while fetching the HTTP request method: "
112
- )
113
- end
114
- end
115
-
116
- context "with a request path that's not a route" do
117
- it "doesn't set an action name" do
118
- env[:path] = "/unknown-route"
119
- env["action_controller.instance"] = nil
120
- make_request
121
-
122
- expect(last_transaction).to_not have_action
123
- end
124
- end
125
- end
126
- end
@@ -1,217 +0,0 @@
1
- if DependencyHelper.sinatra_present?
2
- require "appsignal/rack/sinatra_instrumentation"
3
-
4
- module SinatraRequestHelpers
5
- def make_request
6
- middleware.call(env)
7
- end
8
-
9
- def make_request_with_error(error)
10
- expect { middleware.call(env) }.to raise_error(error)
11
- end
12
- end
13
-
14
- describe Appsignal::Rack::SinatraInstrumentation do
15
- include SinatraRequestHelpers
16
-
17
- let(:settings) { double(:raise_errors => false) }
18
- let(:app) { double(:call => true, :settings => settings) }
19
- let(:env) do
20
- Rack::MockRequest.env_for("/path", "sinatra.route" => "GET /path", "REQUEST_METHOD" => "GET")
21
- end
22
- let(:middleware) { Appsignal::Rack::SinatraInstrumentation.new(app) }
23
-
24
- before { start_agent }
25
- around do |example|
26
- keep_transactions { example.run }
27
- end
28
-
29
- describe "#call" do
30
- before { allow(middleware).to receive(:raw_payload).and_return({}) }
31
-
32
- it "doesn't instrument requests" do
33
- expect { make_request }.to_not(change { created_transactions.count })
34
- end
35
- end
36
-
37
- describe ".settings" do
38
- subject { middleware.settings }
39
-
40
- it "returns the app's settings" do
41
- expect(subject).to eq(app.settings)
42
- end
43
- end
44
- end
45
-
46
- describe Appsignal::Rack::SinatraBaseInstrumentation do
47
- include SinatraRequestHelpers
48
-
49
- let(:settings) { double(:raise_errors => false) }
50
- let(:app) { double(:call => true, :settings => settings) }
51
- let(:env) do
52
- Rack::MockRequest.env_for("/path", "sinatra.route" => "GET /path", "REQUEST_METHOD" => "GET")
53
- end
54
- let(:appsignal_env) { :default }
55
- let(:options) { {} }
56
- let(:middleware) { Appsignal::Rack::SinatraBaseInstrumentation.new(app, options) }
57
-
58
- before { start_agent(:env => appsignal_env) }
59
- around { |example| keep_transactions { example.run } }
60
-
61
- describe "#initialize" do
62
- context "with no settings method in the Sinatra app" do
63
- let(:app) { double(:call => true) }
64
-
65
- it "does not raise errors" do
66
- expect(middleware.raise_errors_on).to be(false)
67
- end
68
- end
69
-
70
- context "with no raise_errors setting in the Sinatra app" do
71
- let(:app) { double(:call => true, :settings => double) }
72
-
73
- it "does not raise errors" do
74
- expect(middleware.raise_errors_on).to be(false)
75
- end
76
- end
77
-
78
- context "with raise_errors turned off in the Sinatra app" do
79
- let(:app) { double(:call => true, :settings => double(:raise_errors => false)) }
80
-
81
- it "raises errors" do
82
- expect(middleware.raise_errors_on).to be(false)
83
- end
84
- end
85
-
86
- context "with raise_errors turned on in the Sinatra app" do
87
- let(:app) { double(:call => true, :settings => double(:raise_errors => true)) }
88
-
89
- it "raises errors" do
90
- expect(middleware.raise_errors_on).to be(true)
91
- end
92
- end
93
- end
94
-
95
- describe "#call" do
96
- before { allow(middleware).to receive(:raw_payload).and_return({}) }
97
-
98
- context "when appsignal is not active" do
99
- let(:appsignal_env) { :inactive_env }
100
-
101
- it "does not instrument requests" do
102
- expect { make_request }.to_not(change { created_transactions.count })
103
- end
104
-
105
- it "calls the next middleware in the stack" do
106
- make_request
107
-
108
- expect(app).to have_received(:call).with(env)
109
- end
110
- end
111
-
112
- context "when appsignal is active" do
113
- context "without an error" do
114
- it "creates a transaction for the request" do
115
- expect { make_request }.to(change { created_transactions.count }.by(1))
116
-
117
- expect(last_transaction).to have_namespace(Appsignal::Transaction::HTTP_REQUEST)
118
- end
119
-
120
- it "reports a process_action.sinatra event" do
121
- make_request
122
-
123
- expect(last_transaction).to include_event("name" => "process_action.sinatra")
124
- end
125
- end
126
-
127
- context "with an error in sinatra.error" do
128
- let(:error) { ExampleException.new("error message") }
129
- before { env["sinatra.error"] = error }
130
-
131
- it "creates a transaction for the request" do
132
- expect { make_request }.to(change { created_transactions.count }.by(1))
133
-
134
- expect(last_transaction).to have_namespace(Appsignal::Transaction::HTTP_REQUEST)
135
- end
136
-
137
- context "when raise_errors is off" do
138
- let(:settings) { double(:raise_errors => false) }
139
-
140
- it "records the error" do
141
- make_request
142
-
143
- expect(last_transaction).to have_error("ExampleException", "error message")
144
- end
145
- end
146
-
147
- context "when raise_errors is on" do
148
- let(:settings) { double(:raise_errors => true) }
149
-
150
- it "does not record the error" do
151
- make_request
152
-
153
- expect(last_transaction).to_not have_error
154
- end
155
- end
156
-
157
- context "if sinatra.skip_appsignal_error is set" do
158
- before do
159
- env.merge!(
160
- "sinatra.error" => error,
161
- "sinatra.skip_appsignal_error" => true
162
- )
163
- end
164
-
165
- it "does not record the error" do
166
- make_request
167
-
168
- expect(last_transaction).to_not have_error
169
- end
170
- end
171
- end
172
-
173
- describe "action name" do
174
- it "sets the action to the request method and path" do
175
- make_request
176
-
177
- expect(last_transaction).to have_action("GET /path")
178
- end
179
-
180
- context "without 'sinatra.route' env" do
181
- let(:env) do
182
- Rack::MockRequest.env_for("/path", "REQUEST_METHOD" => "GET")
183
- end
184
-
185
- it "doesn't set an action name" do
186
- make_request
187
-
188
- expect(last_transaction).to_not have_action
189
- end
190
- end
191
-
192
- context "with mounted modular application" do
193
- before { env["SCRIPT_NAME"] = "/api" }
194
-
195
- it "sets the action name with an application prefix path" do
196
- make_request
197
-
198
- expect(last_transaction).to have_action("GET /api/path")
199
- end
200
-
201
- context "without 'sinatra.route' env" do
202
- let(:env) do
203
- Rack::MockRequest.env_for("/path", "REQUEST_METHOD" => "GET")
204
- end
205
-
206
- it "doesn't set an action name" do
207
- make_request
208
-
209
- expect(last_transaction).to_not have_action
210
- end
211
- end
212
- end
213
- end
214
- end
215
- end
216
- end
217
- end
@@ -1,243 +0,0 @@
1
- describe Appsignal::Rack::Utils do
2
- describe ".queue_start_from" do
3
- let(:header_time) { fixed_time - 0.4 }
4
- let(:header_time_value) { (header_time * factor).to_i }
5
- subject { described_class.queue_start_from(env) }
6
-
7
- shared_examples "HTTP queue start" do
8
- context "when env is nil" do
9
- let(:env) { nil }
10
-
11
- it { is_expected.to be_nil }
12
- end
13
-
14
- context "with no relevant header set" do
15
- let(:env) { {} }
16
-
17
- it { is_expected.to be_nil }
18
- end
19
-
20
- context "with the HTTP_X_REQUEST_START header set" do
21
- let(:env) { { "HTTP_X_REQUEST_START" => "t=#{header_time_value}" } }
22
-
23
- it { is_expected.to eq 1_389_783_599_600 }
24
-
25
- context "with unparsable content" do
26
- let(:env) { { "HTTP_X_REQUEST_START" => "something" } }
27
-
28
- it { is_expected.to be_nil }
29
- end
30
-
31
- context "with unparsable content at the end" do
32
- let(:env) { { "HTTP_X_REQUEST_START" => "t=#{header_time_value}aaaa" } }
33
-
34
- it { is_expected.to eq 1_389_783_599_600 }
35
- end
36
-
37
- context "with a really low number" do
38
- let(:env) { { "HTTP_X_REQUEST_START" => "t=100" } }
39
-
40
- it { is_expected.to be_nil }
41
- end
42
-
43
- context "with the alternate HTTP_X_QUEUE_START header set" do
44
- let(:env) { { "HTTP_X_QUEUE_START" => "t=#{header_time_value}" } }
45
-
46
- it { is_expected.to eq 1_389_783_599_600 }
47
- end
48
- end
49
- end
50
-
51
- context "time in milliseconds" do
52
- let(:factor) { 1_000 }
53
-
54
- it_should_behave_like "HTTP queue start"
55
- end
56
-
57
- context "time in microseconds" do
58
- let(:factor) { 1_000_000 }
59
-
60
- it_should_behave_like "HTTP queue start"
61
- end
62
- end
63
- end
64
-
65
- describe Appsignal::Rack::ApplyRackRequest do
66
- describe "#apply_to" do
67
- let(:merged_env) do
68
- Rack::MockRequest.env_for(
69
- "/some/path",
70
- {
71
- "REQUEST_METHOD" => "GET",
72
- :params => { "page" => 2, "query" => "lorem" },
73
- "rack.session" => { "session" => "data", "user_id" => 123 }
74
- }.merge(env)
75
- )
76
- end
77
- let(:env) { {} }
78
- let(:request) { ::Rack::Request.new(merged_env) }
79
- let(:options) { {} }
80
- let(:helper) { described_class.new(request, options) }
81
- let(:transaction) { http_request_transaction }
82
- before { start_agent }
83
-
84
- def apply_to(transaction)
85
- helper.apply_to(transaction)
86
- transaction._sample
87
- end
88
-
89
- it "sets request metadata" do
90
- apply_to(transaction)
91
-
92
- expect(transaction).to include_metadata(
93
- "method" => "GET",
94
- "path" => "/some/path"
95
- )
96
- expect(transaction).to include_environment(
97
- "REQUEST_METHOD" => "GET",
98
- "PATH_INFO" => "/some/path"
99
- # and more, but we don't need to test Rack mock defaults
100
- )
101
- end
102
-
103
- context "with an invalid HTTP request method" do
104
- let(:env) { { "REQUEST_METHOD" => "FOO" } }
105
-
106
- it "stores the invalid HTTP request method" do
107
- apply_to(transaction)
108
-
109
- expect(transaction).to include_metadata("method" => "FOO")
110
- end
111
- end
112
-
113
- context "when fetching the request method raises an error" do
114
- class BrokenRequestMethodRequest < Rack::Request
115
- def request_method
116
- raise "uh oh!"
117
- end
118
- end
119
-
120
- let(:env) { { "REQUEST_METHOD" => "FOO" } }
121
- let(:request) { BrokenRequestMethodRequest.new(merged_env) }
122
-
123
- it "does not store the invalid HTTP request method" do
124
- logs = capture_logs { apply_to(transaction) }
125
-
126
- expect(transaction).to_not include_metadata("method" => anything)
127
- expect(logs).to contains_log(
128
- :error,
129
- "Exception while fetching the HTTP request method: RuntimeError: uh oh"
130
- )
131
- end
132
- end
133
-
134
- it "sets request parameters" do
135
- apply_to(transaction)
136
-
137
- expect(transaction).to include_params(
138
- "page" => "2",
139
- "query" => "lorem"
140
- )
141
- end
142
-
143
- context "when params_method isn't set" do
144
- let(:options) { { :params_method => nil } }
145
-
146
- it "reports no params" do
147
- apply_to(transaction)
148
-
149
- expect(transaction).to_not include_params
150
- end
151
- end
152
-
153
- context "when fetching the request method raises an error" do
154
- class BrokenRequestParamsRequest < Rack::Request
155
- def params
156
- raise "uh oh!"
157
- end
158
- end
159
-
160
- let(:request) { BrokenRequestParamsRequest.new(merged_env) }
161
- let(:options) { { :params_method => :params } }
162
-
163
- it "does not store the invalid HTTP request method" do
164
- logs = capture_logs { apply_to(transaction) }
165
-
166
- expect(transaction).to_not include_params
167
- expect(logs).to contains_log(
168
- :error,
169
- "Exception while fetching params " \
170
- "from 'BrokenRequestParamsRequest#params': RuntimeError uh oh!"
171
- )
172
- end
173
- end
174
-
175
- it "sets session data" do
176
- apply_to(transaction)
177
-
178
- expect(transaction).to include_session_data("session" => "data", "user_id" => 123)
179
- end
180
-
181
- context "with Hash-like session data" do
182
- let(:env) { { "rack.session" => HashLike.new("hash-like" => "value", "user_id" => 123) } }
183
-
184
- it "sets session data" do
185
- apply_to(transaction)
186
-
187
- expect(transaction).to include_session_data("hash-like" => "value", "user_id" => 123)
188
- end
189
- end
190
-
191
- context "with queue start header" do
192
- let(:queue_start_time) { fixed_time * 1_000 }
193
- let(:env) { { "HTTP_X_REQUEST_START" => "t=#{queue_start_time.to_i}" } } # in milliseconds
194
-
195
- it "sets the queue start" do
196
- apply_to(transaction)
197
-
198
- expect(transaction).to have_queue_start(queue_start_time)
199
- end
200
- end
201
-
202
- class RackFilteredRequest
203
- attr_reader :env
204
-
205
- def initialize(env)
206
- @env = env
207
- end
208
-
209
- def path
210
- "/static/path"
211
- end
212
-
213
- def request_method
214
- "GET"
215
- end
216
-
217
- def filtered_params
218
- { "abc" => "123" }
219
- end
220
-
221
- def session
222
- { "data" => "value" }
223
- end
224
- end
225
-
226
- context "with overridden request class and params method" do
227
- let(:request) { RackFilteredRequest.new(env) }
228
- let(:options) { { :params_method => :filtered_params } }
229
-
230
- it "uses the overridden request class and params method to fetch params" do
231
- apply_to(transaction)
232
-
233
- expect(transaction).to include_params("abc" => "123")
234
- end
235
-
236
- it "uses the overridden request class to fetch session data" do
237
- apply_to(transaction)
238
-
239
- expect(transaction).to include_session_data("data" => "value")
240
- end
241
- end
242
- end
243
- end