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,174 @@
1
+ if DependencyHelper.que_present?
2
+ require "appsignal/integrations/que"
3
+
4
+ describe Appsignal::Integrations::QuePlugin do
5
+ describe "#_run" do
6
+ let(:job_attrs) do
7
+ {
8
+ :job_id => 123,
9
+ :queue => "dfl",
10
+ :job_class => "MyQueJob",
11
+ :priority => 100,
12
+ :args => %w[1 birds],
13
+ :run_at => fixed_time,
14
+ :error_count => 0
15
+ }
16
+ end
17
+
18
+ let(:env) do
19
+ {
20
+ :class => "MyQueJob",
21
+ :method => "run",
22
+ :metadata => {
23
+ :id => 123,
24
+ :queue => "dfl",
25
+ :priority => 100,
26
+ :run_at => fixed_time.to_s,
27
+ :attempts => 0
28
+ },
29
+ :params => %w[1 birds]
30
+ }
31
+ end
32
+
33
+ let(:job) do
34
+ Class.new(::Que::Job) do
35
+ def run(*args)
36
+ end
37
+ end
38
+ end
39
+ let(:instance) { job.new(job_attrs) }
40
+ let(:transaction) do
41
+ Appsignal::Transaction.new(
42
+ SecureRandom.uuid,
43
+ Appsignal::Transaction::BACKGROUND_JOB,
44
+ Appsignal::Transaction::GenericRequest.new(env)
45
+ )
46
+ end
47
+
48
+ before do
49
+ allow(Que).to receive(:execute)
50
+
51
+ start_agent
52
+ expect(Appsignal.active?).to be_truthy
53
+ transaction
54
+
55
+ expect(Appsignal::Transaction).to receive(:create)
56
+ .with(
57
+ kind_of(String),
58
+ Appsignal::Transaction::BACKGROUND_JOB,
59
+ kind_of(Appsignal::Transaction::GenericRequest)
60
+ ).and_return(transaction)
61
+ allow(Appsignal::Transaction).to receive(:current).and_return(transaction)
62
+ expect(transaction.ext).to receive(:finish).and_return(true)
63
+ expect(transaction.ext).to receive(:complete)
64
+ end
65
+
66
+ subject { transaction.to_h }
67
+
68
+ context "success" do
69
+ it "creates a transaction for a job" do
70
+ expect do
71
+ instance._run
72
+ end.to_not raise_exception
73
+
74
+ expect(subject).to include(
75
+ "action" => "MyQueJob#run",
76
+ "id" => instance_of(String),
77
+ "namespace" => Appsignal::Transaction::BACKGROUND_JOB
78
+ )
79
+ expect(subject["error"]).to be_nil
80
+ expect(subject["events"].first).to include(
81
+ "allocation_count" => kind_of(Integer),
82
+ "body" => "",
83
+ "body_format" => Appsignal::EventFormatter::DEFAULT,
84
+ "child_allocation_count" => kind_of(Integer),
85
+ "child_duration" => kind_of(Float),
86
+ "child_gc_duration" => kind_of(Float),
87
+ "count" => 1,
88
+ "gc_duration" => kind_of(Float),
89
+ "start" => kind_of(Float),
90
+ "duration" => kind_of(Float),
91
+ "name" => "perform_job.que",
92
+ "title" => ""
93
+ )
94
+ expect(subject["sample_data"]).to include(
95
+ "params" => %w[1 birds],
96
+ "metadata" => {
97
+ "attempts" => 0,
98
+ "id" => 123,
99
+ "priority" => 100,
100
+ "queue" => "dfl",
101
+ "run_at" => fixed_time.to_s
102
+ }
103
+ )
104
+ end
105
+ end
106
+
107
+ context "with exception" do
108
+ let(:error) { ExampleException.new("oh no!") }
109
+
110
+ it "should report exceptions and re-raise them" do
111
+ allow(instance).to receive(:run).and_raise(error)
112
+
113
+ expect do
114
+ instance._run
115
+ end.to raise_error(ExampleException)
116
+
117
+ expect(subject).to include(
118
+ "action" => "MyQueJob#run",
119
+ "id" => instance_of(String),
120
+ "namespace" => Appsignal::Transaction::BACKGROUND_JOB
121
+ )
122
+ expect(subject["error"]).to include(
123
+ "backtrace" => kind_of(String),
124
+ "name" => error.class.name,
125
+ "message" => error.message
126
+ )
127
+ expect(subject["sample_data"]).to include(
128
+ "params" => %w[1 birds],
129
+ "metadata" => {
130
+ "attempts" => 0,
131
+ "id" => 123,
132
+ "priority" => 100,
133
+ "queue" => "dfl",
134
+ "run_at" => fixed_time.to_s
135
+ }
136
+ )
137
+ end
138
+ end
139
+
140
+ context "with error" do
141
+ let(:error) { ExampleStandardError.new("oh no!") }
142
+
143
+ it "should report errors and not re-raise them" do
144
+ allow(instance).to receive(:run).and_raise(error)
145
+
146
+ expect do
147
+ instance._run
148
+ end.to_not raise_error
149
+
150
+ expect(subject).to include(
151
+ "action" => "MyQueJob#run",
152
+ "id" => instance_of(String),
153
+ "namespace" => Appsignal::Transaction::BACKGROUND_JOB
154
+ )
155
+ expect(subject["error"]).to include(
156
+ "backtrace" => kind_of(String),
157
+ "name" => error.class.name,
158
+ "message" => error.message
159
+ )
160
+ expect(subject["sample_data"]).to include(
161
+ "params" => %w[1 birds],
162
+ "metadata" => {
163
+ "attempts" => 0,
164
+ "id" => 123,
165
+ "priority" => 100,
166
+ "queue" => "dfl",
167
+ "run_at" => fixed_time.to_s
168
+ }
169
+ )
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,129 @@
1
+ if DependencyHelper.rails_present?
2
+ describe Appsignal::Integrations::Railtie do
3
+ context "after initializing the app" do
4
+ it "should call initialize_appsignal" do
5
+ expect(Appsignal::Integrations::Railtie).to receive(:initialize_appsignal)
6
+
7
+ MyApp::Application.config.root = project_fixture_path
8
+ MyApp::Application.initialize!
9
+ end
10
+ end
11
+
12
+ describe "#initialize_appsignal" do
13
+ let(:app) { MyApp::Application }
14
+ before do
15
+ allow(app.middleware).to receive(:insert_before)
16
+ allow(app.middleware).to receive(:insert_after)
17
+ end
18
+
19
+ describe ".logger" do
20
+ before { Appsignal::Integrations::Railtie.initialize_appsignal(app) }
21
+ subject { Appsignal.logger }
22
+
23
+ it { is_expected.to be_a Logger }
24
+ end
25
+
26
+ describe ".config" do
27
+ let(:config) { Appsignal.config }
28
+
29
+ describe "basic configuration" do
30
+ before { Appsignal::Integrations::Railtie.initialize_appsignal(app) }
31
+
32
+ it { expect(config).to be_a(Appsignal::Config) }
33
+
34
+ it "sets the root_path" do
35
+ expect(config.root_path).to eq Pathname.new(project_fixture_path)
36
+ end
37
+
38
+ it "sets the detected environment" do
39
+ expect(config.env).to eq "test"
40
+ end
41
+
42
+ it "loads the app name" do
43
+ expect(config[:name]).to eq "TestApp"
44
+ end
45
+
46
+ it "sets the log_path based on the root_path" do
47
+ expect(config[:log_path]).to eq Pathname.new(File.join(project_fixture_path, "log"))
48
+ end
49
+ end
50
+
51
+ context "with APPSIGNAL_APP_ENV ENV var set" do
52
+ before do
53
+ ENV["APPSIGNAL_APP_ENV"] = "env_test"
54
+ Appsignal::Integrations::Railtie.initialize_appsignal(app)
55
+ end
56
+
57
+ it "uses the environment variable value as the environment" do
58
+ expect(config.env).to eq "env_test"
59
+ end
60
+ end
61
+ end
62
+
63
+ describe ".initial_config" do
64
+ before { Appsignal::Integrations::Railtie.initialize_appsignal(app) }
65
+ let(:config) { Appsignal.config.initial_config }
66
+
67
+ it "returns the initial config" do
68
+ expect(config[:name]).to eq "MyApp"
69
+ end
70
+ end
71
+
72
+ describe "Rails listener middleware" do
73
+ it "adds the Rails listener middleware" do
74
+ expect(app.middleware).to receive(:insert_after).with(
75
+ ActionDispatch::DebugExceptions,
76
+ Appsignal::Rack::RailsInstrumentation
77
+ )
78
+ end
79
+
80
+ after { Appsignal::Integrations::Railtie.initialize_appsignal(app) }
81
+ end
82
+
83
+ describe "frontend_error_catching middleware" do
84
+ let(:config) do
85
+ Appsignal::Config.new(
86
+ project_fixture_path,
87
+ "test",
88
+ :name => "MyApp",
89
+ :enable_frontend_error_catching => enable_frontend_error_catching
90
+ )
91
+ end
92
+ before { allow(Appsignal::Config).to receive(:new).and_return(config) }
93
+ after { Appsignal::Integrations::Railtie.initialize_appsignal(app) }
94
+
95
+ context "when enabled" do
96
+ let(:enable_frontend_error_catching) { true }
97
+
98
+ it "adds the Rails and JSExceptionCatcher middleware" do
99
+ expect(app.middleware).to receive(:insert_after).with(
100
+ ActionDispatch::DebugExceptions,
101
+ Appsignal::Rack::RailsInstrumentation
102
+ )
103
+
104
+ expect(app.middleware).to receive(:insert_before).with(
105
+ Appsignal::Rack::RailsInstrumentation,
106
+ Appsignal::Rack::JSExceptionCatcher
107
+ )
108
+ end
109
+ end
110
+
111
+ context "when not enabled" do
112
+ let(:enable_frontend_error_catching) { false }
113
+
114
+ it "adds the Rails middleware, but not the JSExceptionCatcher middleware" do
115
+ expect(app.middleware).to receive(:insert_after).with(
116
+ ActionDispatch::DebugExceptions,
117
+ Appsignal::Rack::RailsInstrumentation
118
+ )
119
+
120
+ expect(app.middleware).to_not receive(:insert_before).with(
121
+ Appsignal::Rack::RailsInstrumentation,
122
+ Appsignal::Rack::JSExceptionCatcher
123
+ )
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,83 @@
1
+ if DependencyHelper.resque_present? && DependencyHelper.active_job_present?
2
+ require "active_job"
3
+
4
+ describe Appsignal::Integrations::ResqueActiveJobPlugin do
5
+ let(:file) { File.expand_path("lib/appsignal/integrations/resque_active_job.rb") }
6
+ let(:args) { "argument" }
7
+ let(:job) { TestActiveJob.new(args) }
8
+ before do
9
+ load file
10
+ start_agent
11
+
12
+ class TestActiveJob < ActiveJob::Base
13
+ include Appsignal::Integrations::ResqueActiveJobPlugin
14
+
15
+ def perform(_)
16
+ end
17
+ end
18
+ end
19
+
20
+ it "wraps it in a transaction with the correct params" do
21
+ expect(Appsignal).to receive(:monitor_single_transaction).with(
22
+ "perform_job.resque",
23
+ :class => "TestActiveJob",
24
+ :method => "perform",
25
+ :params => ["argument"],
26
+ :metadata => {
27
+ :id => kind_of(String),
28
+ :queue => "default"
29
+ }
30
+ )
31
+ end
32
+
33
+ context "with complex arguments" do
34
+ let(:args) do
35
+ {
36
+ :foo => "Foo",
37
+ :bar => "Bar"
38
+ }
39
+ end
40
+
41
+ it "truncates large argument values" do
42
+ expect(Appsignal).to receive(:monitor_single_transaction).with(
43
+ "perform_job.resque",
44
+ :class => "TestActiveJob",
45
+ :method => "perform",
46
+ :params => [
47
+ :foo => "Foo",
48
+ :bar => "Bar"
49
+ ],
50
+ :metadata => {
51
+ :id => kind_of(String),
52
+ :queue => "default"
53
+ }
54
+ )
55
+ end
56
+
57
+ context "with parameter filtering" do
58
+ before do
59
+ Appsignal.config = project_fixture_config("production")
60
+ Appsignal.config[:filter_parameters] = ["foo"]
61
+ end
62
+
63
+ it "filters selected arguments" do
64
+ expect(Appsignal).to receive(:monitor_single_transaction).with(
65
+ "perform_job.resque",
66
+ :class => "TestActiveJob",
67
+ :method => "perform",
68
+ :params => [
69
+ :foo => "[FILTERED]",
70
+ :bar => "Bar"
71
+ ],
72
+ :metadata => {
73
+ :id => kind_of(String),
74
+ :queue => "default"
75
+ }
76
+ )
77
+ end
78
+ end
79
+ end
80
+
81
+ after { job.perform_now }
82
+ end
83
+ end
@@ -0,0 +1,92 @@
1
+ if DependencyHelper.resque_present?
2
+ describe "Resque integration" do
3
+ let(:file) { File.expand_path("lib/appsignal/integrations/resque.rb") }
4
+
5
+ context "with resque" do
6
+ before do
7
+ load file
8
+ start_agent
9
+
10
+ class TestJob
11
+ extend Appsignal::Integrations::ResquePlugin
12
+
13
+ def self.perform
14
+ end
15
+ end
16
+
17
+ class BrokenTestJob
18
+ extend Appsignal::Integrations::ResquePlugin
19
+
20
+ def self.perform
21
+ raise ExampleException
22
+ end
23
+ end
24
+ end
25
+
26
+ describe :around_perform_resque_plugin do
27
+ let(:transaction) { Appsignal::Transaction.new("1", "background", {}, {}) }
28
+ let(:job) { ::Resque::Job.new("default", "class" => "TestJob") }
29
+ before do
30
+ allow(transaction).to receive(:complete).and_return(true)
31
+ allow(Appsignal::Transaction).to receive(:current).and_return(transaction)
32
+ expect(Appsignal).to receive(:stop)
33
+ end
34
+
35
+ context "without exception" do
36
+ it "creates a new transaction" do
37
+ expect(Appsignal::Transaction).to receive(:create).and_return(transaction)
38
+ end
39
+
40
+ it "wraps it in a transaction with the correct params" do
41
+ expect(Appsignal).to receive(:monitor_transaction).with(
42
+ "perform_job.resque",
43
+ :class => "TestJob",
44
+ :method => "perform"
45
+ )
46
+ end
47
+
48
+ it "closes the transaction" do
49
+ expect(transaction).to receive(:complete)
50
+ end
51
+
52
+ after { job.perform }
53
+ end
54
+
55
+ context "with exception" do
56
+ let(:job) { ::Resque::Job.new("default", "class" => "BrokenTestJob") }
57
+ let(:transaction) do
58
+ Appsignal::Transaction.new(
59
+ SecureRandom.uuid,
60
+ Appsignal::Transaction::BACKGROUND_JOB,
61
+ Appsignal::Transaction::GenericRequest.new({})
62
+ )
63
+ end
64
+ before do
65
+ allow(Appsignal::Transaction).to receive(:current).and_return(transaction)
66
+ expect(Appsignal::Transaction).to receive(:create)
67
+ .with(
68
+ kind_of(String),
69
+ Appsignal::Transaction::BACKGROUND_JOB,
70
+ kind_of(Appsignal::Transaction::GenericRequest)
71
+ ).and_return(transaction)
72
+ end
73
+
74
+ it "sets the exception on the transaction" do
75
+ expect(transaction).to receive(:set_error).with(ExampleException)
76
+ end
77
+
78
+ after do
79
+ expect { job.perform }.to raise_error(ExampleException)
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ context "without resque" do
86
+ before(:context) { Object.send(:remove_const, :Resque) }
87
+
88
+ it { expect { ::Resque }.to raise_error(NameError) }
89
+ it { expect { load file }.to_not raise_error }
90
+ end
91
+ end
92
+ end