appsignal 2.5.0.alpha.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +33 -0
  3. data/.rspec +4 -0
  4. data/.rubocop.yml +66 -0
  5. data/.rubocop_todo.yml +124 -0
  6. data/.travis.yml +72 -0
  7. data/.yardopts +8 -0
  8. data/CHANGELOG.md +639 -0
  9. data/Gemfile +3 -0
  10. data/LICENSE +20 -0
  11. data/README.md +264 -0
  12. data/Rakefile +214 -0
  13. data/appsignal.gemspec +42 -0
  14. data/benchmark.rake +77 -0
  15. data/bin/appsignal +13 -0
  16. data/ext/Rakefile +27 -0
  17. data/ext/agent.yml +64 -0
  18. data/ext/appsignal_extension.c +692 -0
  19. data/ext/base.rb +79 -0
  20. data/ext/extconf.rb +35 -0
  21. data/gemfiles/capistrano2.gemfile +7 -0
  22. data/gemfiles/capistrano3.gemfile +7 -0
  23. data/gemfiles/grape.gemfile +7 -0
  24. data/gemfiles/no_dependencies.gemfile +5 -0
  25. data/gemfiles/padrino.gemfile +7 -0
  26. data/gemfiles/que.gemfile +5 -0
  27. data/gemfiles/rails-3.2.gemfile +6 -0
  28. data/gemfiles/rails-4.0.gemfile +6 -0
  29. data/gemfiles/rails-4.1.gemfile +6 -0
  30. data/gemfiles/rails-4.2.gemfile +10 -0
  31. data/gemfiles/rails-5.0.gemfile +5 -0
  32. data/gemfiles/rails-5.1.gemfile +5 -0
  33. data/gemfiles/resque.gemfile +12 -0
  34. data/gemfiles/sequel-435.gemfile +11 -0
  35. data/gemfiles/sequel.gemfile +11 -0
  36. data/gemfiles/sinatra.gemfile +6 -0
  37. data/gemfiles/webmachine.gemfile +5 -0
  38. data/lib/appsignal.rb +804 -0
  39. data/lib/appsignal/auth_check.rb +65 -0
  40. data/lib/appsignal/capistrano.rb +10 -0
  41. data/lib/appsignal/cli.rb +108 -0
  42. data/lib/appsignal/cli/demo.rb +63 -0
  43. data/lib/appsignal/cli/diagnose.rb +500 -0
  44. data/lib/appsignal/cli/helpers.rb +72 -0
  45. data/lib/appsignal/cli/install.rb +277 -0
  46. data/lib/appsignal/cli/notify_of_deploy.rb +113 -0
  47. data/lib/appsignal/config.rb +287 -0
  48. data/lib/appsignal/demo.rb +107 -0
  49. data/lib/appsignal/event_formatter.rb +74 -0
  50. data/lib/appsignal/event_formatter/action_view/render_formatter.rb +24 -0
  51. data/lib/appsignal/event_formatter/active_record/instantiation_formatter.rb +14 -0
  52. data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +14 -0
  53. data/lib/appsignal/event_formatter/elastic_search/search_formatter.rb +32 -0
  54. data/lib/appsignal/event_formatter/faraday/request_formatter.rb +19 -0
  55. data/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb +89 -0
  56. data/lib/appsignal/event_formatter/moped/query_formatter.rb +80 -0
  57. data/lib/appsignal/extension.rb +63 -0
  58. data/lib/appsignal/extension/jruby.rb +460 -0
  59. data/lib/appsignal/garbage_collection_profiler.rb +48 -0
  60. data/lib/appsignal/hooks.rb +105 -0
  61. data/lib/appsignal/hooks/action_cable.rb +113 -0
  62. data/lib/appsignal/hooks/active_support_notifications.rb +52 -0
  63. data/lib/appsignal/hooks/celluloid.rb +30 -0
  64. data/lib/appsignal/hooks/data_mapper.rb +18 -0
  65. data/lib/appsignal/hooks/delayed_job.rb +19 -0
  66. data/lib/appsignal/hooks/mongo_ruby_driver.rb +21 -0
  67. data/lib/appsignal/hooks/net_http.rb +29 -0
  68. data/lib/appsignal/hooks/passenger.rb +22 -0
  69. data/lib/appsignal/hooks/puma.rb +35 -0
  70. data/lib/appsignal/hooks/que.rb +21 -0
  71. data/lib/appsignal/hooks/rake.rb +39 -0
  72. data/lib/appsignal/hooks/redis.rb +30 -0
  73. data/lib/appsignal/hooks/sequel.rb +60 -0
  74. data/lib/appsignal/hooks/shoryuken.rb +43 -0
  75. data/lib/appsignal/hooks/sidekiq.rb +144 -0
  76. data/lib/appsignal/hooks/unicorn.rb +40 -0
  77. data/lib/appsignal/hooks/webmachine.rb +23 -0
  78. data/lib/appsignal/integrations/capistrano/appsignal.cap +39 -0
  79. data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +52 -0
  80. data/lib/appsignal/integrations/data_mapper.rb +33 -0
  81. data/lib/appsignal/integrations/delayed_job_plugin.rb +54 -0
  82. data/lib/appsignal/integrations/grape.rb +53 -0
  83. data/lib/appsignal/integrations/mongo_ruby_driver.rb +55 -0
  84. data/lib/appsignal/integrations/object.rb +35 -0
  85. data/lib/appsignal/integrations/padrino.rb +84 -0
  86. data/lib/appsignal/integrations/que.rb +43 -0
  87. data/lib/appsignal/integrations/railtie.rb +41 -0
  88. data/lib/appsignal/integrations/rake.rb +2 -0
  89. data/lib/appsignal/integrations/resque.rb +20 -0
  90. data/lib/appsignal/integrations/resque_active_job.rb +30 -0
  91. data/lib/appsignal/integrations/sinatra.rb +17 -0
  92. data/lib/appsignal/integrations/webmachine.rb +38 -0
  93. data/lib/appsignal/js_exception_transaction.rb +54 -0
  94. data/lib/appsignal/marker.rb +63 -0
  95. data/lib/appsignal/minutely.rb +42 -0
  96. data/lib/appsignal/rack/generic_instrumentation.rb +49 -0
  97. data/lib/appsignal/rack/js_exception_catcher.rb +70 -0
  98. data/lib/appsignal/rack/rails_instrumentation.rb +51 -0
  99. data/lib/appsignal/rack/sinatra_instrumentation.rb +99 -0
  100. data/lib/appsignal/rack/streaming_listener.rb +73 -0
  101. data/lib/appsignal/system.rb +81 -0
  102. data/lib/appsignal/transaction.rb +498 -0
  103. data/lib/appsignal/transmitter.rb +107 -0
  104. data/lib/appsignal/utils.rb +127 -0
  105. data/lib/appsignal/utils/params_sanitizer.rb +59 -0
  106. data/lib/appsignal/utils/query_params_sanitizer.rb +55 -0
  107. data/lib/appsignal/version.rb +3 -0
  108. data/lib/sequel/extensions/appsignal_integration.rb +3 -0
  109. data/resources/appsignal.yml.erb +39 -0
  110. data/resources/cacert.pem +3866 -0
  111. data/spec/.rubocop.yml +7 -0
  112. data/spec/lib/appsignal/auth_check_spec.rb +80 -0
  113. data/spec/lib/appsignal/capistrano2_spec.rb +224 -0
  114. data/spec/lib/appsignal/capistrano3_spec.rb +237 -0
  115. data/spec/lib/appsignal/cli/demo_spec.rb +67 -0
  116. data/spec/lib/appsignal/cli/diagnose_spec.rb +988 -0
  117. data/spec/lib/appsignal/cli/helpers_spec.rb +171 -0
  118. data/spec/lib/appsignal/cli/install_spec.rb +632 -0
  119. data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +168 -0
  120. data/spec/lib/appsignal/cli_spec.rb +56 -0
  121. data/spec/lib/appsignal/config_spec.rb +637 -0
  122. data/spec/lib/appsignal/demo_spec.rb +87 -0
  123. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +44 -0
  124. data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +21 -0
  125. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +21 -0
  126. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +52 -0
  127. data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +21 -0
  128. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +113 -0
  129. data/spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb +112 -0
  130. data/spec/lib/appsignal/event_formatter_spec.rb +100 -0
  131. data/spec/lib/appsignal/extension/jruby_spec.rb +43 -0
  132. data/spec/lib/appsignal/extension_spec.rb +137 -0
  133. data/spec/lib/appsignal/garbage_collection_profiler_spec.rb +66 -0
  134. data/spec/lib/appsignal/hooks/action_cable_spec.rb +370 -0
  135. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +92 -0
  136. data/spec/lib/appsignal/hooks/celluloid_spec.rb +35 -0
  137. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +39 -0
  138. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +358 -0
  139. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +44 -0
  140. data/spec/lib/appsignal/hooks/net_http_spec.rb +53 -0
  141. data/spec/lib/appsignal/hooks/passenger_spec.rb +30 -0
  142. data/spec/lib/appsignal/hooks/puma_spec.rb +80 -0
  143. data/spec/lib/appsignal/hooks/que_spec.rb +19 -0
  144. data/spec/lib/appsignal/hooks/rake_spec.rb +73 -0
  145. data/spec/lib/appsignal/hooks/redis_spec.rb +55 -0
  146. data/spec/lib/appsignal/hooks/sequel_spec.rb +46 -0
  147. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +192 -0
  148. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +419 -0
  149. data/spec/lib/appsignal/hooks/unicorn_spec.rb +52 -0
  150. data/spec/lib/appsignal/hooks/webmachine_spec.rb +35 -0
  151. data/spec/lib/appsignal/hooks_spec.rb +195 -0
  152. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +65 -0
  153. data/spec/lib/appsignal/integrations/grape_spec.rb +225 -0
  154. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +127 -0
  155. data/spec/lib/appsignal/integrations/object_spec.rb +249 -0
  156. data/spec/lib/appsignal/integrations/padrino_spec.rb +323 -0
  157. data/spec/lib/appsignal/integrations/que_spec.rb +174 -0
  158. data/spec/lib/appsignal/integrations/railtie_spec.rb +129 -0
  159. data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +83 -0
  160. data/spec/lib/appsignal/integrations/resque_spec.rb +92 -0
  161. data/spec/lib/appsignal/integrations/sinatra_spec.rb +73 -0
  162. data/spec/lib/appsignal/integrations/webmachine_spec.rb +69 -0
  163. data/spec/lib/appsignal/js_exception_transaction_spec.rb +128 -0
  164. data/spec/lib/appsignal/marker_spec.rb +51 -0
  165. data/spec/lib/appsignal/minutely_spec.rb +50 -0
  166. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +90 -0
  167. data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +147 -0
  168. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +117 -0
  169. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +213 -0
  170. data/spec/lib/appsignal/rack/streaming_listener_spec.rb +161 -0
  171. data/spec/lib/appsignal/system_spec.rb +131 -0
  172. data/spec/lib/appsignal/transaction_spec.rb +1146 -0
  173. data/spec/lib/appsignal/transmitter_spec.rb +152 -0
  174. data/spec/lib/appsignal/utils/params_sanitizer_spec.rb +136 -0
  175. data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +192 -0
  176. data/spec/lib/appsignal/utils_spec.rb +150 -0
  177. data/spec/lib/appsignal_spec.rb +1049 -0
  178. data/spec/spec_helper.rb +116 -0
  179. data/spec/support/fixtures/containers/cgroups/docker +14 -0
  180. data/spec/support/fixtures/containers/cgroups/docker_systemd +8 -0
  181. data/spec/support/fixtures/containers/cgroups/lxc +10 -0
  182. data/spec/support/fixtures/containers/cgroups/no_permission +0 -0
  183. data/spec/support/fixtures/containers/cgroups/none +1 -0
  184. data/spec/support/fixtures/generated_config.yml +24 -0
  185. data/spec/support/fixtures/uploaded_file.txt +0 -0
  186. data/spec/support/helpers/api_request_helper.rb +19 -0
  187. data/spec/support/helpers/cli_helpers.rb +26 -0
  188. data/spec/support/helpers/config_helpers.rb +21 -0
  189. data/spec/support/helpers/dependency_helper.rb +73 -0
  190. data/spec/support/helpers/directory_helper.rb +27 -0
  191. data/spec/support/helpers/env_helpers.rb +33 -0
  192. data/spec/support/helpers/example_exception.rb +13 -0
  193. data/spec/support/helpers/example_standard_error.rb +13 -0
  194. data/spec/support/helpers/log_helpers.rb +22 -0
  195. data/spec/support/helpers/std_streams_helper.rb +66 -0
  196. data/spec/support/helpers/system_helpers.rb +8 -0
  197. data/spec/support/helpers/time_helpers.rb +11 -0
  198. data/spec/support/helpers/transaction_helpers.rb +37 -0
  199. data/spec/support/matchers/contains_log.rb +7 -0
  200. data/spec/support/mocks/fake_gc_profiler.rb +19 -0
  201. data/spec/support/mocks/mock_extension.rb +6 -0
  202. data/spec/support/project_fixture/config/application.rb +0 -0
  203. data/spec/support/project_fixture/config/appsignal.yml +32 -0
  204. data/spec/support/project_fixture/config/environments/development.rb +0 -0
  205. data/spec/support/project_fixture/config/environments/production.rb +0 -0
  206. data/spec/support/project_fixture/config/environments/test.rb +0 -0
  207. data/spec/support/project_fixture/log/.gitkeep +0 -0
  208. data/spec/support/rails/my_app.rb +6 -0
  209. data/spec/support/shared_examples/instrument.rb +43 -0
  210. data/spec/support/stubs/delayed_job.rb +0 -0
  211. metadata +483 -0
@@ -0,0 +1,73 @@
1
+ if DependencyHelper.sinatra_present?
2
+ require "appsignal/integrations/sinatra"
3
+
4
+ def install_sinatra_integration
5
+ load File.expand_path("lib/appsignal/integrations/sinatra.rb", project_dir)
6
+ end
7
+
8
+ # "Uninstall" the AppSignal integration
9
+ def uninstall_sinatra_integration
10
+ Sinatra::Base.instance_variable_get(:@middleware).delete_if do |middleware|
11
+ middleware.first == Appsignal::Rack::SinatraBaseInstrumentation
12
+ end
13
+ end
14
+
15
+ describe "Sinatra integration" do
16
+ before { allow(Appsignal).to receive(:active?).and_return(true) }
17
+ after { uninstall_sinatra_integration }
18
+
19
+ context "Appsignal.logger" do
20
+ subject { Appsignal.logger }
21
+
22
+ it "sets a logger" do
23
+ install_sinatra_integration
24
+ is_expected.to be_a Logger
25
+ end
26
+ end
27
+
28
+ describe "middleware" do
29
+ context "when AppSignal is not active" do
30
+ before { allow(Appsignal).to receive(:active?).and_return(false) }
31
+
32
+ it "does not add the instrumentation middleware to Sinatra::Base" do
33
+ install_sinatra_integration
34
+ expect(Sinatra::Base.middleware.to_a).to_not include(
35
+ [Appsignal::Rack::SinatraBaseInstrumentation, [], nil]
36
+ )
37
+ end
38
+ end
39
+
40
+ context "when AppSignal is active" do
41
+ it "adds the instrumentation middleware to Sinatra::Base" do
42
+ install_sinatra_integration
43
+ expect(Sinatra::Base.middleware.to_a).to include(
44
+ [Appsignal::Rack::SinatraBaseInstrumentation, [], nil]
45
+ )
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "environment" do
51
+ subject { Appsignal.config.env }
52
+
53
+ context "without APPSIGNAL_APP_ENV" do
54
+ before { install_sinatra_integration }
55
+
56
+ it "uses the app environment" do
57
+ expect(subject).to eq("test")
58
+ end
59
+ end
60
+
61
+ context "with APPSIGNAL_APP_ENV" do
62
+ before do
63
+ ENV["APPSIGNAL_APP_ENV"] = "env-staging"
64
+ install_sinatra_integration
65
+ end
66
+
67
+ it "uses the environment variable" do
68
+ expect(subject).to eq("env-staging")
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,69 @@
1
+ if DependencyHelper.webmachine_present?
2
+ require "appsignal/integrations/webmachine"
3
+
4
+ describe Appsignal::Integrations::WebmachinePlugin::FSM do
5
+ let(:request) do
6
+ Webmachine::Request.new("GET", "http://google.com:80/foo", {}, nil)
7
+ end
8
+ let(:resource) { double(:trace? => false, :handle_exception => true) }
9
+ let(:response) { double }
10
+ let(:transaction) { double(:set_action_if_nil => true) }
11
+ let(:fsm) { Webmachine::Decision::FSM.new(resource, request, response) }
12
+ before(:context) { start_agent }
13
+
14
+ # Make sure the request responds to the method we need to get query params.
15
+ describe "request" do
16
+ it "should respond to `query`" do
17
+ expect(request).to respond_to(:query)
18
+ end
19
+ end
20
+
21
+ describe "#run_with_appsignal" do
22
+ before do
23
+ allow(fsm).to receive(:request).and_return(request)
24
+ allow(fsm).to receive(:run_without_appsignal).and_return(true)
25
+ allow(SecureRandom).to receive(:uuid).and_return("uuid")
26
+ allow(Appsignal::Transaction).to receive(:create).and_return(transaction)
27
+ end
28
+
29
+ it "should create a transaction" do
30
+ expect(Appsignal::Transaction).to receive(:create).with(
31
+ "uuid",
32
+ Appsignal::Transaction::HTTP_REQUEST,
33
+ request,
34
+ :params_method => :query
35
+ ).and_return(transaction)
36
+ end
37
+
38
+ it "should set the action" do
39
+ expect(transaction).to receive(:set_action_if_nil).with("RSpec::Mocks::Double#GET")
40
+ end
41
+
42
+ it "should call the original method" do
43
+ expect(fsm).to receive(:run_without_appsignal)
44
+ end
45
+
46
+ it "should instrument the original method" do
47
+ expect(Appsignal).to receive(:instrument).with("process_action.webmachine")
48
+ end
49
+
50
+ it "should close the transaction" do
51
+ expect(Appsignal::Transaction).to receive(:complete_current!)
52
+ end
53
+
54
+ after { fsm.run }
55
+ end
56
+
57
+ describe "#handle_exceptions_with_appsignal" do
58
+ let(:error) { ExampleException }
59
+
60
+ it "should catch the error and send it to AppSignal" do
61
+ expect(Appsignal).to receive(:set_error).with(error)
62
+ end
63
+
64
+ after do
65
+ fsm.send(:handle_exceptions) { raise error }
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,128 @@
1
+ describe Appsignal::JSExceptionTransaction do
2
+ before { allow(SecureRandom).to receive(:uuid).and_return("123abc") }
3
+
4
+ let!(:transaction) { Appsignal::JSExceptionTransaction.new(data) }
5
+ let(:data) do
6
+ {
7
+ "name" => "TypeError",
8
+ "message" => "foo is not a valid method",
9
+ "action" => "ExceptionIncidentComponent",
10
+ "path" => "foo.bar/moo",
11
+ "environment" => "development",
12
+ "backtrace" => [
13
+ "foo.bar/js:11:1",
14
+ "foo.bar/js:22:2"
15
+ ],
16
+ "tags" => [
17
+ "tag1"
18
+ ]
19
+ }
20
+ end
21
+
22
+ describe "#initialize" do
23
+ it "should call all required methods" do
24
+ expect(Appsignal::Extension).to receive(:start_transaction).with("123abc", "frontend", 0).and_return(1)
25
+
26
+ expect(transaction).to receive(:set_action)
27
+ expect(transaction).to receive(:set_metadata)
28
+ expect(transaction).to receive(:set_error)
29
+ expect(transaction).to receive(:set_sample_data)
30
+
31
+ transaction.send :initialize, data
32
+
33
+ expect(transaction.ext).to_not be_nil
34
+ end
35
+ end
36
+
37
+ describe "#set_action" do
38
+ it "should call `Appsignal::Extension.set_action`" do
39
+ expect(transaction.ext).to receive(:set_action).with(
40
+ "ExceptionIncidentComponent"
41
+ )
42
+
43
+ transaction.set_action
44
+ end
45
+ end
46
+
47
+ describe "#set_metadata" do
48
+ it "should call `Appsignal::Extension.set_transaction_metadata`" do
49
+ expect(transaction.ext).to receive(:set_metadata).with(
50
+ "path",
51
+ "foo.bar/moo"
52
+ )
53
+
54
+ transaction.set_metadata
55
+ end
56
+ end
57
+
58
+ describe "#set_error" do
59
+ it "should call `Appsignal::Extension.set_transaction_error`" do
60
+ expect(transaction.ext).to receive(:set_error).with(
61
+ "TypeError",
62
+ "foo is not a valid method",
63
+ Appsignal::Utils.data_generate(["foo.bar/js:11:1", "foo.bar/js:22:2"])
64
+ )
65
+
66
+ transaction.set_error
67
+ end
68
+ end
69
+
70
+ describe "#set_sample_data" do
71
+ it "should call `Appsignal::Extension.set_transaction_error_data`" do
72
+ expect(transaction.ext).to receive(:set_sample_data).with(
73
+ "tags",
74
+ Appsignal::Utils.data_generate(["tag1"])
75
+ )
76
+
77
+ transaction.set_sample_data
78
+ end
79
+ end
80
+
81
+ context "when sending just the name" do
82
+ let(:data) { { "name" => "TypeError" } }
83
+
84
+ describe "#set_action" do
85
+ it "should not call `Appsignal::Extension.set_action`" do
86
+ expect(transaction.ext).to_not receive(:set_action)
87
+
88
+ transaction.set_action
89
+ end
90
+ end
91
+
92
+ describe "#set_metadata" do
93
+ it "should not call `Appsignal::Extension.set_transaction_metadata`" do
94
+ expect(transaction.ext).to_not receive(:set_metadata)
95
+
96
+ transaction.set_metadata
97
+ end
98
+ end
99
+
100
+ describe "#set_error" do
101
+ it "should call `Appsignal::Extension.set_transaction_error` with just the name" do
102
+ expect(transaction.ext).to receive(:set_error).with(
103
+ "TypeError",
104
+ "",
105
+ Appsignal::Utils.data_generate([])
106
+ )
107
+
108
+ transaction.set_error
109
+ end
110
+ end
111
+
112
+ describe "#set_sample_data" do
113
+ it "should not call `Appsignal::Extension.set_transaction_error_data`" do
114
+ expect(transaction.ext).to_not receive(:set_sample_data)
115
+
116
+ transaction.set_sample_data
117
+ end
118
+ end
119
+ end
120
+
121
+ describe "#complete!" do
122
+ it "should call all required methods" do
123
+ expect(transaction.ext).to receive(:finish).and_call_original
124
+ expect(transaction.ext).to receive(:complete).and_call_original
125
+ transaction.complete!
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,51 @@
1
+ describe Appsignal::Marker do
2
+ let(:config) { project_fixture_config }
3
+ let(:marker) do
4
+ described_class.new(
5
+ {
6
+ :revision => "503ce0923ed177a3ce000005",
7
+ :repository => "master",
8
+ :user => "batman",
9
+ :rails_env => "production"
10
+ },
11
+ config
12
+ )
13
+ end
14
+ let(:out_stream) { std_stream }
15
+ let(:output) { out_stream.read }
16
+
17
+ describe "#transmit" do
18
+ def stub_marker_request
19
+ stub_api_request config, "markers", marker.marker_data
20
+ end
21
+
22
+ def run
23
+ capture_stdout(out_stream) { marker.transmit }
24
+ end
25
+
26
+ context "when request is valid" do
27
+ before { stub_marker_request.to_return(:status => 200) }
28
+
29
+ it "outputs success" do
30
+ run
31
+ expect(output).to include \
32
+ "Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman",
33
+ "AppSignal has been notified of this deploy!"
34
+ end
35
+ end
36
+
37
+ context "when request is invalid" do
38
+ before { stub_marker_request.to_return(:status => 500) }
39
+
40
+ it "outputs failure" do
41
+ run
42
+ expect(output).to include \
43
+ "Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman",
44
+ "Something went wrong while trying to notify AppSignal: 500 at "\
45
+ "#{config[:endpoint]}/1/markers"
46
+ expect(output).to_not include \
47
+ "AppSignal has been notified of this deploy!"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,50 @@
1
+ describe Appsignal::Minutely do
2
+ before do
3
+ Appsignal::Minutely.probes.clear
4
+ end
5
+
6
+ it "should have a list of probes" do
7
+ expect(Appsignal::Minutely.probes).to be_instance_of(Array)
8
+ end
9
+
10
+ describe ".start" do
11
+ it "should call the probes periodically" do
12
+ probe = double
13
+ expect(probe).to receive(:call).at_least(:twice)
14
+ Appsignal::Minutely.probes << probe
15
+ allow(Appsignal::Minutely).to receive(:wait_time).and_return(0.1)
16
+
17
+ Appsignal::Minutely.start
18
+
19
+ sleep 0.5
20
+ end
21
+ end
22
+
23
+ describe ".wait_time" do
24
+ it "should get the time to the next minute" do
25
+ allow_any_instance_of(Time).to receive(:sec).and_return(30)
26
+ expect(Appsignal::Minutely.wait_time).to eq 30
27
+ end
28
+ end
29
+
30
+ describe ".add_gc_probe" do
31
+ it "should add the gc probe to the list" do
32
+ expect(Appsignal::Minutely.probes).to be_empty
33
+
34
+ Appsignal::Minutely.add_gc_probe
35
+
36
+ expect(Appsignal::Minutely.probes.size).to eq(1)
37
+ expect(Appsignal::Minutely.probes[0]).to be_instance_of(Appsignal::Minutely::GCProbe)
38
+ end
39
+ end
40
+
41
+ describe Appsignal::Minutely::GCProbe do
42
+ describe "#call" do
43
+ it "should collect GC metrics" do
44
+ expect(Appsignal).to receive(:set_process_gauge).at_least(8).times
45
+
46
+ Appsignal::Minutely::GCProbe.new.call
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,90 @@
1
+ describe Appsignal::Rack::GenericInstrumentation do
2
+ before :context do
3
+ start_agent
4
+ end
5
+
6
+ let(:app) { double(:call => true) }
7
+ let(:env) { { :path => "/", :method => "GET" } }
8
+ let(:options) { {} }
9
+ let(:middleware) { Appsignal::Rack::GenericInstrumentation.new(app, options) }
10
+
11
+ describe "#call" do
12
+ before do
13
+ allow(middleware).to receive(:raw_payload).and_return({})
14
+ end
15
+
16
+ context "when appsignal is active" do
17
+ before { allow(Appsignal).to receive(:active?).and_return(true) }
18
+
19
+ it "should call with monitoring" do
20
+ expect(middleware).to receive(:call_with_appsignal_monitoring).with(env)
21
+ end
22
+ end
23
+
24
+ context "when appsignal is not active" do
25
+ before { allow(Appsignal).to receive(:active?).and_return(false) }
26
+
27
+ it "should not call with monitoring" do
28
+ expect(middleware).to_not receive(:call_with_appsignal_monitoring)
29
+ end
30
+
31
+ it "should call the stack" do
32
+ expect(app).to receive(:call).with(env)
33
+ end
34
+ end
35
+
36
+ after { middleware.call(env) }
37
+ end
38
+
39
+ describe "#call_with_appsignal_monitoring", :error => false do
40
+ it "should create a transaction" do
41
+ expect(Appsignal::Transaction).to receive(:create).with(
42
+ kind_of(String),
43
+ Appsignal::Transaction::HTTP_REQUEST,
44
+ kind_of(Rack::Request)
45
+ ).and_return(double(:set_action_if_nil => nil, :set_http_or_background_queue_start => nil, :set_metadata => nil))
46
+ end
47
+
48
+ it "should call the app" do
49
+ expect(app).to receive(:call).with(env)
50
+ end
51
+
52
+ context "with an exception", :error => true do
53
+ let(:error) { ExampleException }
54
+ let(:app) do
55
+ double.tap do |d|
56
+ allow(d).to receive(:call).and_raise(error)
57
+ end
58
+ end
59
+
60
+ it "records the exception" do
61
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_error).with(error)
62
+ end
63
+ end
64
+
65
+ it "should set the action to unknown" do
66
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_action_if_nil).with("unknown")
67
+ end
68
+
69
+ context "with a route specified in the env" do
70
+ before do
71
+ env["appsignal.route"] = "GET /"
72
+ end
73
+
74
+ it "should set the action" do
75
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_action_if_nil).with("GET /")
76
+ end
77
+ end
78
+
79
+ it "should set metadata" do
80
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_metadata).twice
81
+ end
82
+
83
+ it "should set the queue start" do
84
+ expect_any_instance_of(Appsignal::Transaction).to receive(:set_http_or_background_queue_start)
85
+ end
86
+
87
+ after(:error => false) { middleware.call(env) }
88
+ after(:error => true) { expect { middleware.call(env) }.to raise_error(error) }
89
+ end
90
+ end