appsignal 3.11.0-java → 3.12.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +109 -0
  3. data/Rakefile +1 -1
  4. data/lib/appsignal/cli/diagnose.rb +1 -1
  5. data/lib/appsignal/config.rb +150 -32
  6. data/lib/appsignal/demo.rb +1 -6
  7. data/lib/appsignal/integrations/grape.rb +7 -0
  8. data/lib/appsignal/integrations/hanami.rb +8 -43
  9. data/lib/appsignal/integrations/padrino.rb +8 -73
  10. data/lib/appsignal/integrations/railtie.rb +35 -13
  11. data/lib/appsignal/integrations/sinatra.rb +8 -19
  12. data/lib/appsignal/loaders/grape.rb +13 -0
  13. data/lib/appsignal/loaders/hanami.rb +40 -0
  14. data/lib/appsignal/loaders/padrino.rb +68 -0
  15. data/lib/appsignal/loaders/sinatra.rb +24 -0
  16. data/lib/appsignal/loaders.rb +92 -0
  17. data/lib/appsignal/rack/abstract_middleware.rb +2 -1
  18. data/lib/appsignal/rack/event_handler.rb +5 -5
  19. data/lib/appsignal/rack.rb +6 -0
  20. data/lib/appsignal/version.rb +1 -1
  21. data/lib/appsignal.rb +163 -9
  22. data/spec/lib/appsignal/cli/demo_spec.rb +0 -1
  23. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +1 -1
  24. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1
  25. data/spec/lib/appsignal/config_spec.rb +153 -1
  26. data/spec/lib/appsignal/demo_spec.rb +1 -2
  27. data/spec/lib/appsignal/environment_spec.rb +4 -2
  28. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +3 -6
  29. data/spec/lib/appsignal/hooks/activejob_spec.rb +3 -3
  30. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +4 -7
  31. data/spec/lib/appsignal/hooks/excon_spec.rb +3 -6
  32. data/spec/lib/appsignal/hooks/gvl_spec.rb +2 -2
  33. data/spec/lib/appsignal/hooks/http_spec.rb +1 -3
  34. data/spec/lib/appsignal/hooks/net_http_spec.rb +1 -1
  35. data/spec/lib/appsignal/hooks/redis_client_spec.rb +5 -8
  36. data/spec/lib/appsignal/hooks/redis_spec.rb +3 -6
  37. data/spec/lib/appsignal/hooks/resque_spec.rb +1 -1
  38. data/spec/lib/appsignal/hooks/sequel_spec.rb +3 -5
  39. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +1 -1
  40. data/spec/lib/appsignal/hooks/webmachine_spec.rb +1 -1
  41. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +2 -2
  42. data/spec/lib/appsignal/integrations/grape_spec.rb +36 -0
  43. data/spec/lib/appsignal/integrations/hanami_spec.rb +9 -178
  44. data/spec/lib/appsignal/integrations/http_spec.rb +1 -5
  45. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +4 -2
  46. data/spec/lib/appsignal/integrations/net_http_spec.rb +1 -1
  47. data/spec/lib/appsignal/integrations/object_spec.rb +1 -3
  48. data/spec/lib/appsignal/integrations/padrino_spec.rb +8 -330
  49. data/spec/lib/appsignal/integrations/railtie_spec.rb +275 -191
  50. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +1 -1
  51. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +11 -9
  52. data/spec/lib/appsignal/integrations/sinatra_spec.rb +9 -104
  53. data/spec/lib/appsignal/loaders/grape_spec.rb +12 -0
  54. data/spec/lib/appsignal/loaders/hanami_spec.rb +95 -0
  55. data/spec/lib/appsignal/loaders/padrino_spec.rb +277 -0
  56. data/spec/lib/appsignal/loaders/sinatra_spec.rb +47 -0
  57. data/spec/lib/appsignal/loaders_spec.rb +137 -0
  58. data/spec/lib/appsignal/probes/sidekiq_spec.rb +1 -1
  59. data/spec/lib/appsignal/probes_spec.rb +6 -5
  60. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +3 -2
  61. data/spec/lib/appsignal/rack/event_handler_spec.rb +33 -0
  62. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +1 -1
  63. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +2 -35
  64. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +1 -1
  65. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +3 -3
  66. data/spec/lib/appsignal/span_spec.rb +1 -3
  67. data/spec/lib/appsignal/transaction_spec.rb +4 -2
  68. data/spec/lib/appsignal_spec.rb +278 -26
  69. data/spec/lib/puma/appsignal_spec.rb +0 -3
  70. data/spec/spec_helper.rb +5 -4
  71. data/spec/support/helpers/config_helpers.rb +2 -1
  72. data/spec/support/helpers/loader_helper.rb +21 -0
  73. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +7 -0
  74. data/spec/support/testing.rb +46 -0
  75. metadata +15 -2
@@ -6,59 +6,121 @@ if DependencyHelper.rails_present?
6
6
 
7
7
  after { clear_rails_error_reporter! }
8
8
 
9
- context "after initializing the app" do
10
- it "should call initialize_appsignal" do
11
- expect(Appsignal::Integrations::Railtie).to receive(:initialize_appsignal)
9
+ module RailtieHelper
10
+ def self.ensure_initialize!
11
+ return if @initialized
12
12
 
13
- MyApp::Application.config.root = project_fixture_path
13
+ MyApp::Application.config.root = ConfigHelpers.project_fixture_path
14
14
  MyApp::Application.initialize!
15
+ @initialized = true
15
16
  end
16
17
  end
17
18
 
18
- describe "#initialize_appsignal" do
19
- let(:app) { MyApp::Application.new }
19
+ def expect_middleware_to_match(middleware, klass, args)
20
+ expect(middleware.klass).to eq(klass)
21
+ expect(middleware.args).to match(args)
22
+ end
20
23
 
21
- describe ".internal_logger" do
22
- before { Appsignal::Integrations::Railtie.initialize_appsignal(app) }
23
- subject { Appsignal.internal_logger }
24
+ describe "on Rails app initialize!" do
25
+ it "starts AppSignal by calling its hooks" do
26
+ expect(Appsignal::Integrations::Railtie).to receive(:on_load).and_call_original
27
+ expect(Appsignal::Integrations::Railtie).to receive(:after_initialize).and_call_original
24
28
 
25
- it { is_expected.to be_a Logger }
29
+ RailtieHelper.ensure_initialize!
26
30
  end
31
+ end
27
32
 
28
- describe ".config" do
29
- let(:config) { Appsignal.config }
33
+ describe "initializer" do
34
+ let(:app) { MyApp::Application.new }
35
+ before do
36
+ RailtieHelper.ensure_initialize!
37
+ Appsignal.config = nil
38
+ end
30
39
 
31
- describe "basic configuration" do
32
- before { Appsignal::Integrations::Railtie.initialize_appsignal(app) }
40
+ def initialize_railtie(event)
41
+ MyApp::Application.config.root = project_fixture_path
42
+ case event
43
+ when :on_load
44
+ described_class.on_load(app)
45
+ when :after_initialize
46
+ described_class.after_initialize(app)
47
+ else
48
+ raise "Unsupported test event '#{event}'"
49
+ end
50
+ end
33
51
 
34
- it { expect(config).to be_a(Appsignal::Config) }
52
+ shared_examples "integrates with Rails" do
53
+ it "starts AppSignal" do
54
+ initialize_railtie(event)
35
55
 
36
- it "sets the root_path" do
37
- expect(config.root_path).to eq Pathname.new(project_fixture_path)
38
- end
56
+ expect(Appsignal.active?).to be_truthy
57
+ end
39
58
 
40
- it "sets the detected environment" do
41
- expect(config.env).to eq "test"
42
- end
59
+ it "doesn't overwrite the config if a config is already present " do
60
+ Appsignal.config = Appsignal::Config.new(
61
+ Dir.pwd,
62
+ "my_env",
63
+ :some_config => "some value"
64
+ )
65
+ initialize_railtie(event)
43
66
 
44
- it "loads the app name" do
45
- expect(config[:name]).to eq "TestApp"
46
- end
67
+ expect(Appsignal.config.env).to eq("my_env")
68
+ expect(Appsignal.config.root_path).to eq(Dir.pwd)
69
+ expect(Appsignal.config[:some_config]).to eq("some value")
70
+ end
47
71
 
48
- it "sets the log_path based on the root_path" do
49
- expect(config[:log_path]).to eq Pathname.new(File.join(project_fixture_path, "log"))
50
- end
72
+ it "sets the detected environment" do
73
+ initialize_railtie(event)
74
+
75
+ expect(Appsignal.config.env).to eq("test")
51
76
  end
52
77
 
53
- context "with APPSIGNAL_APP_ENV ENV var set" do
54
- before do
55
- ENV["APPSIGNAL_APP_ENV"] = "env_test"
56
- Appsignal::Integrations::Railtie.initialize_appsignal(app)
57
- end
78
+ it "uses the APPSIGNAL_APP_ENV environment variable value as the environment" do
79
+ ENV["APPSIGNAL_APP_ENV"] = "env_test"
80
+ initialize_railtie(event)
58
81
 
59
- it "uses the environment variable value as the environment" do
60
- expect(config.env).to eq "env_test"
61
- end
82
+ expect(Appsignal.config.env).to eq "env_test"
83
+ end
84
+
85
+ it "sets the Rails app path as root_path" do
86
+ initialize_railtie(event)
87
+
88
+ expect(Appsignal.config.root_path).to eq(Pathname.new(project_fixture_path))
89
+ end
90
+
91
+ it "loads the Rails app name in the initial config" do
92
+ initialize_railtie(event)
93
+
94
+ expect(Appsignal.config.initial_config[:name]).to eq "MyApp"
95
+ end
96
+
97
+ it "loads the app name from the project's appsignal.yml file" do
98
+ initialize_railtie(event)
99
+
100
+ expect(Appsignal.config[:name]).to eq "TestApp"
101
+ end
102
+
103
+ it "sets the log_path based on the root_path" do
104
+ initialize_railtie(event)
105
+
106
+ expect(Appsignal.config[:log_path])
107
+ .to eq(Pathname.new(File.join(project_fixture_path, "log")))
108
+ end
109
+
110
+ it "adds the middleware" do
111
+ initialize_railtie(event)
112
+
113
+ middlewares = MyApp::Application.middleware
114
+ expect_middleware_to_match(
115
+ middlewares.find { |m| m.klass == ::Rack::Events },
116
+ ::Rack::Events,
117
+ [[instance_of(Appsignal::Rack::EventHandler)]]
118
+ )
119
+ expect_middleware_to_match(
120
+ middlewares.find { |m| m.klass == Appsignal::Rack::RailsInstrumentation },
121
+ Appsignal::Rack::RailsInstrumentation,
122
+ []
123
+ )
62
124
  end
63
125
 
64
126
  if Rails.respond_to?(:error)
@@ -82,7 +144,7 @@ if DependencyHelper.rails_present?
82
144
 
83
145
  context "when enable_rails_error_reporter is enabled" do
84
146
  it "subscribes to the error reporter" do
85
- Appsignal::Integrations::Railtie.initialize_appsignal(app)
147
+ initialize_railtie(event)
86
148
 
87
149
  expect(error_reporter.subscribers)
88
150
  .to eq([Appsignal::Integrations::RailsErrorReporterSubscriber])
@@ -92,7 +154,7 @@ if DependencyHelper.rails_present?
92
154
  context "when enable_rails_error_reporter is disabled" do
93
155
  it "does not subscribe to the error reporter" do
94
156
  ENV["APPSIGNAL_ENABLE_RAILS_ERROR_REPORTER"] = "false"
95
- Appsignal::Integrations::Railtie.initialize_appsignal(app)
157
+ initialize_railtie(event)
96
158
 
97
159
  expect(error_reporter.subscribers)
98
160
  .to_not eq([Appsignal::Integrations::RailsErrorReporterSubscriber])
@@ -102,215 +164,237 @@ if DependencyHelper.rails_present?
102
164
  else
103
165
  context "when Rails does not listen to `error`" do
104
166
  it "does not error trying to subscribe to the error reporter" do
105
- Appsignal::Integrations::Railtie.initialize_appsignal(app)
167
+ initialize_railtie(event)
106
168
  end
107
169
  end
108
170
  end
109
171
  end
110
172
 
111
- describe ".initial_config" do
112
- before { Appsignal::Integrations::Railtie.initialize_appsignal(app) }
113
- let(:config) { Appsignal.config.initial_config }
173
+ describe ".on_load" do
174
+ let(:event) { :on_load }
114
175
 
115
- it "returns the initial config" do
116
- expect(config[:name]).to eq "MyApp"
176
+ context "when start_at == :on_load" do
177
+ include_examples "integrates with Rails"
117
178
  end
118
- end
119
179
 
120
- describe "Rails listener middleware" do
121
- it "adds the Rails listener middleware" do
122
- expect(app.middleware).to receive(:insert_after).with(
123
- ActionDispatch::DebugExceptions,
124
- Appsignal::Rack::RailsInstrumentation
125
- )
126
- Appsignal::Integrations::Railtie.initialize_appsignal(app)
180
+ context "when start_at == :after_initialize" do
181
+ it "does not start AppSignal" do
182
+ app.config.appsignal.start_at = :after_initialize
183
+ initialize_railtie(event)
184
+
185
+ expect(Appsignal.active?).to be_falsy
186
+ expect(Appsignal.config).to be_nil
187
+ end
127
188
  end
128
189
  end
129
190
 
130
- if Rails.respond_to?(:error)
131
- describe "Rails error reporter" do
132
- before { start_agent }
133
- around { |example| keep_transactions { example.run } }
191
+ describe ".after_initialize" do
192
+ let(:event) { :after_initialize }
134
193
 
135
- context "when error is not handled (reraises the error)" do
136
- it "does nothing" do
137
- with_rails_error_reporter do
138
- expect do
139
- Rails.error.record { raise ExampleStandardError, "error message" }
140
- end.to raise_error(ExampleStandardError, "error message")
141
- end
194
+ context "when start_at == :after_initialize" do
195
+ before do
196
+ app.config.appsignal.start_at = :after_initialize
197
+ end
198
+
199
+ include_examples "integrates with Rails"
200
+ end
201
+
202
+ context "when start_at == :on_load" do
203
+ it "does not start AppSignal" do
204
+ app.config.appsignal.start_at = :on_load
205
+ initialize_railtie(event)
142
206
 
143
- expect(created_transactions).to be_empty
207
+ expect(Appsignal.active?).to be_falsy
208
+ expect(Appsignal.config).to be_nil
209
+ end
210
+ end
211
+ end
212
+ end
213
+
214
+ if Rails.respond_to?(:error)
215
+ describe "Rails error reporter" do
216
+ before { start_agent }
217
+ around { |example| keep_transactions { example.run } }
218
+
219
+ context "when error is not handled (reraises the error)" do
220
+ it "does nothing" do
221
+ with_rails_error_reporter do
222
+ expect do
223
+ Rails.error.record { raise ExampleStandardError, "error message" }
224
+ end.to raise_error(ExampleStandardError, "error message")
144
225
  end
226
+
227
+ expect(created_transactions).to be_empty
145
228
  end
229
+ end
146
230
 
147
- context "when error is handled (not reraised)" do
148
- context "when a transaction is active" do
149
- it "duplicates the transaction namespace, action and tags" do
150
- current_transaction = http_request_transaction
151
- current_transaction.set_namespace "custom"
152
- current_transaction.set_action "CustomAction"
153
- current_transaction.set_tags(
154
- :duplicated_tag => "duplicated value"
155
- )
156
-
157
- with_rails_error_reporter do
158
- with_current_transaction current_transaction do
159
- Rails.error.handle { raise ExampleStandardError, "error message" }
160
-
161
- transaction = last_transaction
162
- expect(transaction).to have_namespace("custom")
163
- expect(transaction).to have_action("CustomAction")
164
- expect(transaction).to have_error("ExampleStandardError", "error message")
165
- expect(transaction).to include_tags(
166
- "duplicated_tag" => "duplicated value",
167
- "severity" => "warning"
168
- )
169
- end
170
- end
171
- end
231
+ context "when error is handled (not reraised)" do
232
+ context "when a transaction is active" do
233
+ it "duplicates the transaction namespace, action and tags" do
234
+ current_transaction = http_request_transaction
235
+ current_transaction.set_namespace "custom"
236
+ current_transaction.set_action "CustomAction"
237
+ current_transaction.set_tags(
238
+ :duplicated_tag => "duplicated value"
239
+ )
172
240
 
173
- it "overwrites duplicated tags with tags from context" do
174
- current_transaction = http_request_transaction
175
- current_transaction.set_tags(:tag1 => "duplicated value")
176
-
177
- with_rails_error_reporter do
178
- with_current_transaction current_transaction do
179
- given_context = { :tag1 => "value1", :tag2 => "value2" }
180
- Rails.error.handle(:context => given_context) { raise ExampleStandardError }
181
-
182
- expect(last_transaction).to include_tags(
183
- "tag1" => "value1",
184
- "tag2" => "value2",
185
- "severity" => "warning"
186
- )
187
- end
241
+ with_rails_error_reporter do
242
+ with_current_transaction current_transaction do
243
+ Rails.error.handle { raise ExampleStandardError, "error message" }
244
+
245
+ transaction = last_transaction
246
+ expect(transaction).to have_namespace("custom")
247
+ expect(transaction).to have_action("CustomAction")
248
+ expect(transaction).to have_error("ExampleStandardError", "error message")
249
+ expect(transaction).to include_tags(
250
+ "duplicated_tag" => "duplicated value",
251
+ "severity" => "warning"
252
+ )
188
253
  end
189
254
  end
255
+ end
190
256
 
191
- it "sends tags stored in :appsignal -> :custom_data as custom data" do
192
- current_transaction = http_request_transaction
193
-
194
- with_rails_error_reporter do
195
- with_current_transaction current_transaction do
196
- given_context = {
197
- :appsignal => {
198
- :custom_data => {
199
- :array => [1, 2],
200
- :hash => { :one => 1, :two => 2 }
201
- }
202
- }
203
- }
204
- Rails.error.handle(:context => given_context) { raise ExampleStandardError }
205
-
206
- transaction = last_transaction
207
- expect(transaction).to include_custom_data(
208
- "array" => [1, 2],
209
- "hash" => { "one" => 1, "two" => 2 }
210
- )
211
- end
257
+ it "overwrites duplicated tags with tags from context" do
258
+ current_transaction = http_request_transaction
259
+ current_transaction.set_tags(:tag1 => "duplicated value")
260
+
261
+ with_rails_error_reporter do
262
+ with_current_transaction current_transaction do
263
+ given_context = { :tag1 => "value1", :tag2 => "value2" }
264
+ Rails.error.handle(:context => given_context) { raise ExampleStandardError }
265
+
266
+ expect(last_transaction).to include_tags(
267
+ "tag1" => "value1",
268
+ "tag2" => "value2",
269
+ "severity" => "warning"
270
+ )
212
271
  end
213
272
  end
273
+ end
214
274
 
215
- it "overwrites duplicated namespace and action with custom from context" do
216
- current_transaction = http_request_transaction
217
- current_transaction.set_namespace "custom"
218
- current_transaction.set_action "CustomAction"
275
+ it "sends tags stored in :appsignal -> :custom_data as custom data" do
276
+ current_transaction = http_request_transaction
219
277
 
220
- with_rails_error_reporter do
221
- with_current_transaction current_transaction do
222
- given_context = {
223
- :appsignal => { :namespace => "context", :action => "ContextAction" }
278
+ with_rails_error_reporter do
279
+ with_current_transaction current_transaction do
280
+ given_context = {
281
+ :appsignal => {
282
+ :custom_data => {
283
+ :array => [1, 2],
284
+ :hash => { :one => 1, :two => 2 }
285
+ }
224
286
  }
225
- Rails.error.handle(:context => given_context) { raise ExampleStandardError }
287
+ }
288
+ Rails.error.handle(:context => given_context) { raise ExampleStandardError }
226
289
 
227
- transaction = last_transaction
228
- expect(transaction).to have_namespace("context")
229
- expect(transaction).to have_action("ContextAction")
230
- end
290
+ transaction = last_transaction
291
+ expect(transaction).to include_custom_data(
292
+ "array" => [1, 2],
293
+ "hash" => { "one" => 1, "two" => 2 }
294
+ )
231
295
  end
232
296
  end
233
297
  end
234
298
 
235
- context "when no transaction is active" do
236
- class ExampleRailsRequestMock
237
- def path
238
- "path"
239
- end
299
+ it "overwrites duplicated namespace and action with custom from context" do
300
+ current_transaction = http_request_transaction
301
+ current_transaction.set_namespace "custom"
302
+ current_transaction.set_action "CustomAction"
240
303
 
241
- def method
242
- "GET"
243
- end
304
+ with_rails_error_reporter do
305
+ with_current_transaction current_transaction do
306
+ given_context = {
307
+ :appsignal => { :namespace => "context", :action => "ContextAction" }
308
+ }
309
+ Rails.error.handle(:context => given_context) { raise ExampleStandardError }
244
310
 
245
- def filtered_parameters
246
- { :user_id => 123, :password => "[FILTERED]" }
311
+ transaction = last_transaction
312
+ expect(transaction).to have_namespace("context")
313
+ expect(transaction).to have_action("ContextAction")
247
314
  end
248
315
  end
316
+ end
317
+ end
249
318
 
250
- class ExampleRailsControllerMock
251
- def action_name
252
- "index"
253
- end
319
+ context "when no transaction is active" do
320
+ class ExampleRailsRequestMock
321
+ def path
322
+ "path"
323
+ end
254
324
 
255
- def request
256
- @request ||= ExampleRailsRequestMock.new
257
- end
325
+ def method
326
+ "GET"
258
327
  end
259
328
 
260
- class ExampleRailsJobMock
329
+ def filtered_parameters
330
+ { :user_id => 123, :password => "[FILTERED]" }
261
331
  end
332
+ end
262
333
 
263
- class ExampleRailsMailerMock < ActionMailer::MailDeliveryJob
264
- def arguments
265
- ["ExampleRailsMailerMock", "send_mail"]
266
- end
334
+ class ExampleRailsControllerMock
335
+ def action_name
336
+ "index"
267
337
  end
268
338
 
269
- before do
270
- clear_current_transaction!
339
+ def request
340
+ @request ||= ExampleRailsRequestMock.new
271
341
  end
342
+ end
272
343
 
273
- it "fetches the action, path and method from the controller in the context" do
274
- # The controller key is set by Rails when raised in a controller
275
- given_context = { :controller => ExampleRailsControllerMock.new }
276
- with_rails_error_reporter do
277
- Rails.error.handle(:context => given_context) { raise ExampleStandardError }
278
- end
344
+ class ExampleRailsJobMock
345
+ end
279
346
 
280
- transaction = last_transaction
281
- expect(transaction).to have_action("ExampleRailsControllerMock#index")
282
- expect(transaction).to include_metadata("path" => "path", "method" => "GET")
283
- expect(transaction).to include_params("user_id" => 123, "password" => "[FILTERED]")
347
+ class ExampleRailsMailerMock < ActionMailer::MailDeliveryJob
348
+ def arguments
349
+ ["ExampleRailsMailerMock", "send_mail"]
284
350
  end
351
+ end
285
352
 
286
- it "sets no action if no execution context is present" do
287
- # The controller key is set by Rails when raised in a controller
288
- with_rails_error_reporter do
289
- Rails.error.handle { raise ExampleStandardError }
290
- end
353
+ before do
354
+ clear_current_transaction!
355
+ end
291
356
 
292
- expect(last_transaction).to_not have_action
357
+ it "fetches the action, path and method from the controller in the context" do
358
+ # The controller key is set by Rails when raised in a controller
359
+ given_context = { :controller => ExampleRailsControllerMock.new }
360
+ with_rails_error_reporter do
361
+ Rails.error.handle(:context => given_context) { raise ExampleStandardError }
293
362
  end
363
+
364
+ transaction = last_transaction
365
+ expect(transaction).to have_action("ExampleRailsControllerMock#index")
366
+ expect(transaction).to include_metadata("path" => "path", "method" => "GET")
367
+ expect(transaction).to include_params("user_id" => 123,
368
+ "password" => "[FILTERED]")
294
369
  end
295
370
 
296
- it "sets the error context as tags" do
297
- given_context = {
298
- :controller => ExampleRailsControllerMock.new, # Not set as tag
299
- :job => ExampleRailsJobMock.new, # Not set as tag
300
- :appsignal => { :something => "not used" }, # Not set as tag
301
- :tag1 => "value1",
302
- :tag2 => "value2"
303
- }
371
+ it "sets no action if no execution context is present" do
372
+ # The controller key is set by Rails when raised in a controller
304
373
  with_rails_error_reporter do
305
- Rails.error.handle(:context => given_context) { raise ExampleStandardError }
374
+ Rails.error.handle { raise ExampleStandardError }
306
375
  end
307
376
 
308
- expect(last_transaction).to include_tags(
309
- "tag1" => "value1",
310
- "tag2" => "value2",
311
- "severity" => "warning"
312
- )
377
+ expect(last_transaction).to_not have_action
378
+ end
379
+ end
380
+
381
+ it "sets the error context as tags" do
382
+ given_context = {
383
+ :controller => ExampleRailsControllerMock.new, # Not set as tag
384
+ :job => ExampleRailsJobMock.new, # Not set as tag
385
+ :appsignal => { :something => "not used" }, # Not set as tag
386
+ :tag1 => "value1",
387
+ :tag2 => "value2"
388
+ }
389
+ with_rails_error_reporter do
390
+ Rails.error.handle(:context => given_context) { raise ExampleStandardError }
313
391
  end
392
+
393
+ expect(last_transaction).to include_tags(
394
+ "tag1" => "value1",
395
+ "tag2" => "value2",
396
+ "severity" => "warning"
397
+ )
314
398
  end
315
399
  end
316
400
  end
@@ -61,7 +61,7 @@ describe Appsignal::Integrations::ShoryukenMiddleware do
61
61
 
62
62
  context "with parameter filtering" do
63
63
  before do
64
- Appsignal.config = project_fixture_config("production")
64
+ start_agent("production")
65
65
  Appsignal.config[:filter_parameters] = ["foo"]
66
66
  end
67
67
 
@@ -243,7 +243,7 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
243
243
 
244
244
  context "with parameter filtering" do
245
245
  before do
246
- Appsignal.config = project_fixture_config("production")
246
+ start_agent("production")
247
247
  Appsignal.config[:filter_parameters] = ["foo"]
248
248
  end
249
249
 
@@ -384,7 +384,7 @@ describe Appsignal::Integrations::SidekiqMiddleware, :with_yaml_parse_error => f
384
384
  include RailsHelper
385
385
 
386
386
  it "reports the worker name as the action, copies the namespace and tags" do
387
- Appsignal.config = project_fixture_config("production")
387
+ start_agent("production")
388
388
  with_rails_error_reporter do
389
389
  perform_sidekiq_job do
390
390
  Appsignal.tag_job("test_tag" => "value")
@@ -527,6 +527,15 @@ if DependencyHelper.active_job_present?
527
527
  end
528
528
  end
529
529
  around do |example|
530
+ with_rails_error_reporter do
531
+ keep_transactions do
532
+ Sidekiq::Testing.fake! do
533
+ example.run
534
+ end
535
+ end
536
+ end
537
+ end
538
+ before do
530
539
  start_agent
531
540
  Appsignal.internal_logger = test_logger(log)
532
541
  ActiveJob::Base.queue_adapter = :sidekiq
@@ -551,13 +560,6 @@ if DependencyHelper.active_job_present?
551
560
  Sidekiq::Testing.server_middleware do |chain|
552
561
  chain.add Appsignal::Integrations::SidekiqMiddleware
553
562
  end
554
- with_rails_error_reporter do
555
- keep_transactions do
556
- Sidekiq::Testing.fake! do
557
- example.run
558
- end
559
- end
560
- end
561
563
  end
562
564
  after do
563
565
  Object.send(:remove_const, :ActiveJobSidekiqTestJob)