appsignal 3.9.1-java → 3.9.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +3135 -0
  3. data/.rubocop.yml +28 -20
  4. data/.rubocop_todo.yml +7 -33
  5. data/CHANGELOG.md +58 -0
  6. data/Rakefile +79 -64
  7. data/appsignal.gemspec +1 -1
  8. data/build_matrix.yml +109 -179
  9. data/ext/base.rb +1 -1
  10. data/gemfiles/hanami-2.1.gemfile +7 -0
  11. data/lib/appsignal/cli/diagnose.rb +1 -1
  12. data/lib/appsignal/config.rb +1 -1
  13. data/lib/appsignal/demo.rb +0 -1
  14. data/lib/appsignal/environment.rb +5 -1
  15. data/lib/appsignal/extension/jruby.rb +1 -1
  16. data/lib/appsignal/helpers/instrumentation.rb +3 -3
  17. data/lib/appsignal/hooks/active_job.rb +2 -1
  18. data/lib/appsignal/integrations/action_cable.rb +1 -1
  19. data/lib/appsignal/integrations/grape.rb +19 -47
  20. data/lib/appsignal/integrations/hanami.rb +27 -41
  21. data/lib/appsignal/integrations/padrino.rb +46 -43
  22. data/lib/appsignal/integrations/railtie.rb +1 -4
  23. data/lib/appsignal/integrations/resque.rb +1 -1
  24. data/lib/appsignal/integrations/sidekiq.rb +2 -4
  25. data/lib/appsignal/integrations/sinatra.rb +7 -2
  26. data/lib/appsignal/probes/gvl.rb +24 -2
  27. data/lib/appsignal/probes/sidekiq.rb +1 -1
  28. data/lib/appsignal/probes.rb +1 -1
  29. data/lib/appsignal/rack/abstract_middleware.rb +62 -28
  30. data/lib/appsignal/rack/event_handler.rb +37 -26
  31. data/lib/appsignal/rack/grape_middleware.rb +40 -0
  32. data/lib/appsignal/rack/hanami_middleware.rb +20 -0
  33. data/lib/appsignal/rack/rails_instrumentation.rb +14 -56
  34. data/lib/appsignal/utils/integration_memory_logger.rb +78 -0
  35. data/lib/appsignal/utils.rb +1 -0
  36. data/lib/appsignal/version.rb +1 -1
  37. data/lib/appsignal.rb +34 -33
  38. data/spec/.rubocop.yml +1 -1
  39. data/spec/lib/appsignal/cli/diagnose_spec.rb +1 -1
  40. data/spec/lib/appsignal/cli/install_spec.rb +3 -3
  41. data/spec/lib/appsignal/config_spec.rb +7 -5
  42. data/spec/lib/appsignal/demo_spec.rb +38 -41
  43. data/spec/lib/appsignal/hooks/action_cable_spec.rb +86 -167
  44. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +8 -20
  45. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +38 -84
  46. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +16 -37
  47. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +4 -4
  48. data/spec/lib/appsignal/hooks/activejob_spec.rb +111 -200
  49. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +54 -91
  50. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +14 -32
  51. data/spec/lib/appsignal/hooks/excon_spec.rb +8 -12
  52. data/spec/lib/appsignal/hooks/net_http_spec.rb +7 -42
  53. data/spec/lib/appsignal/hooks/rake_spec.rb +9 -19
  54. data/spec/lib/appsignal/hooks/redis_client_spec.rb +18 -30
  55. data/spec/lib/appsignal/hooks/redis_spec.rb +10 -16
  56. data/spec/lib/appsignal/hooks/resque_spec.rb +42 -62
  57. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +33 -74
  58. data/spec/lib/appsignal/integrations/hanami_spec.rb +126 -64
  59. data/spec/lib/appsignal/integrations/http_spec.rb +12 -20
  60. data/spec/lib/appsignal/integrations/net_http_spec.rb +33 -0
  61. data/spec/lib/appsignal/integrations/object_spec.rb +29 -36
  62. data/spec/lib/appsignal/integrations/padrino_spec.rb +47 -70
  63. data/spec/lib/appsignal/integrations/que_spec.rb +43 -70
  64. data/spec/lib/appsignal/integrations/railtie_spec.rb +26 -67
  65. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +86 -160
  66. data/spec/lib/appsignal/integrations/sinatra_spec.rb +8 -3
  67. data/spec/lib/appsignal/integrations/webmachine_spec.rb +28 -39
  68. data/spec/lib/appsignal/probes/gvl_spec.rb +80 -3
  69. data/spec/lib/appsignal/probes_spec.rb +7 -4
  70. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +215 -106
  71. data/spec/lib/appsignal/rack/event_handler_spec.rb +151 -69
  72. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +2 -12
  73. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +234 -0
  74. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +36 -0
  75. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +67 -131
  76. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +36 -44
  77. data/spec/lib/appsignal/rack/streaming_listener_spec.rb +68 -86
  78. data/spec/lib/appsignal/transaction_spec.rb +79 -93
  79. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +163 -0
  80. data/spec/lib/appsignal_spec.rb +363 -342
  81. data/spec/support/hanami/hanami_app.rb +1 -3
  82. data/spec/support/helpers/dependency_helper.rb +6 -1
  83. data/spec/support/helpers/std_streams_helper.rb +1 -1
  84. data/spec/support/helpers/transaction_helpers.rb +8 -0
  85. data/spec/support/matchers/transaction.rb +185 -0
  86. data/spec/support/mocks/dummy_app.rb +20 -0
  87. data/spec/support/shared_examples/instrument.rb +17 -12
  88. data/spec/support/testing.rb +18 -9
  89. metadata +17 -10
  90. data/.semaphore/semaphore.yml +0 -2347
  91. data/script/lint_git +0 -22
  92. data/spec/lib/appsignal/integrations/grape_spec.rb +0 -239
  93. data/spec/support/matchers/be_completed.rb +0 -5
  94. /data/gemfiles/{hanami.gemfile → hanami-2.0.gemfile} +0 -0
@@ -46,19 +46,12 @@ describe Appsignal::Hooks::ActionCableHook do
46
46
  http_request_env_with_data("action_dispatch.request_id" => request_id, :params => params)
47
47
  end
48
48
  let(:instance) { channel.new(connection, identifier, params) }
49
- subject { transaction.to_h }
50
49
  before do
51
50
  start_agent
52
51
  expect(Appsignal.active?).to be_truthy
53
52
  transaction
54
53
 
55
- expect(Appsignal::Transaction).to receive(:create).with(
56
- transaction_id,
57
- Appsignal::Transaction::ACTION_CABLE,
58
- kind_of(ActionDispatch::Request)
59
- )
60
- .and_return(transaction)
61
- allow(Appsignal::Transaction).to receive(:current).and_return(transaction)
54
+ set_current_transaction(transaction)
62
55
 
63
56
  # Stub transmit call for subscribe/unsubscribe tests
64
57
  allow(connection).to receive(:websocket)
@@ -70,35 +63,25 @@ describe Appsignal::Hooks::ActionCableHook do
70
63
  it "creates a transaction for an action" do
71
64
  instance.perform_action("message" => "foo", "action" => "speak")
72
65
 
73
- expect(subject).to include(
74
- "action" => "MyChannel#speak",
75
- "error" => nil,
76
- "id" => transaction_id,
77
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
78
- "metadata" => {
79
- "method" => "websocket",
80
- "path" => "/blog"
81
- }
66
+ transaction = last_transaction
67
+ expect(transaction).to have_id(transaction_id)
68
+ expect(transaction).to have_namespace(Appsignal::Transaction::ACTION_CABLE)
69
+ expect(transaction).to have_action("MyChannel#speak")
70
+ expect(transaction).to_not have_error
71
+ expect(transaction).to include_metadata(
72
+ "method" => "websocket",
73
+ "path" => "/blog"
82
74
  )
83
- expect(subject["events"].first).to include(
84
- "allocation_count" => kind_of(Integer),
75
+ expect(transaction).to include_event(
85
76
  "body" => "",
86
77
  "body_format" => Appsignal::EventFormatter::DEFAULT,
87
- "child_allocation_count" => kind_of(Integer),
88
- "child_duration" => kind_of(Float),
89
- "child_gc_duration" => kind_of(Float),
90
78
  "count" => 1,
91
- "gc_duration" => kind_of(Float),
92
- "start" => kind_of(Float),
93
- "duration" => kind_of(Float),
94
79
  "name" => "perform_action.action_cable",
95
80
  "title" => ""
96
81
  )
97
- expect(subject["sample_data"]).to include(
98
- "params" => {
99
- "action" => "speak",
100
- "message" => "foo"
101
- }
82
+ expect(transaction).to include_params(
83
+ "action" => "speak",
84
+ "message" => "foo"
102
85
  )
103
86
  end
104
87
 
@@ -120,7 +103,7 @@ describe Appsignal::Hooks::ActionCableHook do
120
103
  it "uses its own internal request_id set by the subscribed callback" do
121
104
  # Subscribe action, sets the request_id
122
105
  instance.subscribe_to_channel
123
- expect(transaction.to_h["id"]).to eq(transaction_id)
106
+ expect(transaction).to have_id(transaction_id)
124
107
 
125
108
  # Expect another transaction for the action.
126
109
  # This transaction will use the same request_id as the
@@ -131,12 +114,9 @@ describe Appsignal::Hooks::ActionCableHook do
131
114
  kind_of(ActionDispatch::Request)
132
115
  ).and_return(action_transaction)
133
116
  allow(Appsignal::Transaction).to receive(:current).and_return(action_transaction)
134
- # Stub complete call, stops it from being cleared in the extension
135
- # And allows us to call `#to_h` on it after it's been completed.
136
- expect(action_transaction.ext).to receive(:complete)
137
117
 
138
118
  instance.perform_action("message" => "foo", "action" => "speak")
139
- expect(action_transaction.to_h["id"]).to eq(transaction_id)
119
+ expect(action_transaction).to have_id(transaction_id)
140
120
  end
141
121
  end
142
122
 
@@ -158,25 +138,18 @@ describe Appsignal::Hooks::ActionCableHook do
158
138
  instance.perform_action("message" => "foo", "action" => "speak")
159
139
  end.to raise_error(ExampleException)
160
140
 
161
- expect(subject).to include(
162
- "action" => "MyChannel#speak",
163
- "id" => transaction_id,
164
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
165
- "metadata" => {
166
- "method" => "websocket",
167
- "path" => "/blog"
168
- }
169
- )
170
- expect(subject["error"]).to include(
171
- "backtrace" => kind_of(String),
172
- "name" => "ExampleException",
173
- "message" => "oh no!"
141
+ transaction = last_transaction
142
+ expect(transaction).to have_id(transaction_id)
143
+ expect(transaction).to have_action("MyChannel#speak")
144
+ expect(transaction).to have_namespace(Appsignal::Transaction::ACTION_CABLE)
145
+ expect(transaction).to have_error("ExampleException", "oh no!")
146
+ expect(transaction).to include_metadata(
147
+ "method" => "websocket",
148
+ "path" => "/blog"
174
149
  )
175
- expect(subject["sample_data"]).to include(
176
- "params" => {
177
- "action" => "speak",
178
- "message" => "foo"
179
- }
150
+ expect(transaction).to include_params(
151
+ "action" => "speak",
152
+ "message" => "foo"
180
153
  )
181
154
  end
182
155
  end
@@ -188,33 +161,23 @@ describe Appsignal::Hooks::ActionCableHook do
188
161
  it "creates a transaction for a subscription" do
189
162
  instance.subscribe_to_channel
190
163
 
191
- expect(subject).to include(
192
- "action" => "MyChannel#subscribed",
193
- "error" => nil,
194
- "id" => transaction_id,
195
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
196
- "metadata" => {
197
- "method" => "websocket",
198
- "path" => "/blog"
199
- }
164
+ transaction = last_transaction
165
+ expect(transaction).to have_id(transaction_id)
166
+ expect(transaction).to have_action("MyChannel#subscribed")
167
+ expect(transaction).to have_namespace(Appsignal::Transaction::ACTION_CABLE)
168
+ expect(transaction).to_not have_error
169
+ expect(transaction).to include_metadata(
170
+ "method" => "websocket",
171
+ "path" => "/blog"
200
172
  )
201
- expect(subject["events"].first).to include(
202
- "allocation_count" => kind_of(Integer),
173
+ expect(transaction).to include_params("internal" => "true")
174
+ expect(transaction).to include_event(
203
175
  "body" => "",
204
176
  "body_format" => Appsignal::EventFormatter::DEFAULT,
205
- "child_allocation_count" => kind_of(Integer),
206
- "child_duration" => kind_of(Float),
207
- "child_gc_duration" => kind_of(Float),
208
177
  "count" => 1,
209
- "gc_duration" => kind_of(Float),
210
- "start" => kind_of(Float),
211
- "duration" => kind_of(Float),
212
178
  "name" => "subscribed.action_cable",
213
179
  "title" => ""
214
180
  )
215
- expect(subject["sample_data"]).to include(
216
- "params" => { "internal" => "true" }
217
- )
218
181
  end
219
182
 
220
183
  context "without request_id (standalone server)" do
@@ -226,7 +189,7 @@ describe Appsignal::Hooks::ActionCableHook do
226
189
  end
227
190
 
228
191
  it "uses its own internal request_id" do
229
- expect(subject["id"]).to eq(transaction_id)
192
+ expect(last_transaction).to have_id(transaction_id)
230
193
  end
231
194
  end
232
195
 
@@ -248,23 +211,16 @@ describe Appsignal::Hooks::ActionCableHook do
248
211
  instance.subscribe_to_channel
249
212
  end.to raise_error(ExampleException)
250
213
 
251
- expect(subject).to include(
252
- "action" => "MyChannel#subscribed",
253
- "id" => transaction_id,
254
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
255
- "metadata" => {
256
- "method" => "websocket",
257
- "path" => "/blog"
258
- }
259
- )
260
- expect(subject["error"]).to include(
261
- "backtrace" => kind_of(String),
262
- "name" => "ExampleException",
263
- "message" => "oh no!"
264
- )
265
- expect(subject["sample_data"]).to include(
266
- "params" => { "internal" => "true" }
214
+ transaction = last_transaction
215
+ expect(transaction).to have_id(transaction_id)
216
+ expect(transaction).to have_action("MyChannel#subscribed")
217
+ expect(transaction).to have_namespace(Appsignal::Transaction::ACTION_CABLE)
218
+ expect(transaction).to have_error("ExampleException", "oh no!")
219
+ expect(transaction).to include_metadata(
220
+ "method" => "websocket",
221
+ "path" => "/blog"
267
222
  )
223
+ expect(transaction).to include_params("internal" => "true")
268
224
  end
269
225
  end
270
226
 
@@ -280,33 +236,23 @@ describe Appsignal::Hooks::ActionCableHook do
280
236
  it "does not fail on missing `#env` method on `ConnectionStub`" do
281
237
  instance.subscribe_to_channel
282
238
 
283
- expect(subject).to include(
284
- "action" => "MyChannel#subscribed",
285
- "error" => nil,
286
- "id" => transaction_id,
287
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
288
- "metadata" => {
289
- "method" => "websocket",
290
- "path" => "" # No path as the ConnectionStub doesn't have the real request env
291
- }
239
+ transaction = last_transaction
240
+ expect(transaction).to have_id(transaction_id)
241
+ expect(transaction).to have_action("MyChannel#subscribed")
242
+ expect(transaction).to have_namespace(Appsignal::Transaction::ACTION_CABLE)
243
+ expect(transaction).to_not have_error
244
+ expect(transaction).to include_metadata(
245
+ "method" => "websocket",
246
+ "path" => "" # No path as the ConnectionStub doesn't have the real request env
292
247
  )
293
- expect(subject["events"].first).to include(
294
- "allocation_count" => kind_of(Integer),
248
+ expect(transaction).to include_params("internal" => "true")
249
+ expect(transaction).to include_event(
295
250
  "body" => "",
296
251
  "body_format" => Appsignal::EventFormatter::DEFAULT,
297
- "child_allocation_count" => kind_of(Integer),
298
- "child_duration" => kind_of(Float),
299
- "child_gc_duration" => kind_of(Float),
300
252
  "count" => 1,
301
- "gc_duration" => kind_of(Float),
302
- "start" => kind_of(Float),
303
- "duration" => kind_of(Float),
304
253
  "name" => "subscribed.action_cable",
305
254
  "title" => ""
306
255
  )
307
- expect(subject["sample_data"]).to include(
308
- "params" => { "internal" => "true" }
309
- )
310
256
  end
311
257
  end
312
258
  end
@@ -318,33 +264,23 @@ describe Appsignal::Hooks::ActionCableHook do
318
264
  it "creates a transaction for a subscription" do
319
265
  instance.unsubscribe_from_channel
320
266
 
321
- expect(subject).to include(
322
- "action" => "MyChannel#unsubscribed",
323
- "error" => nil,
324
- "id" => transaction_id,
325
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
326
- "metadata" => {
327
- "method" => "websocket",
328
- "path" => "/blog"
329
- }
267
+ transaction = last_transaction
268
+ expect(transaction).to have_id(transaction_id)
269
+ expect(transaction).to have_action("MyChannel#unsubscribed")
270
+ expect(transaction).to have_namespace(Appsignal::Transaction::ACTION_CABLE)
271
+ expect(transaction).to_not have_error
272
+ expect(transaction).to include_metadata(
273
+ "method" => "websocket",
274
+ "path" => "/blog"
330
275
  )
331
- expect(subject["events"].first).to include(
332
- "allocation_count" => kind_of(Integer),
276
+ expect(transaction).to include_params("internal" => "true")
277
+ expect(transaction).to include_event(
333
278
  "body" => "",
334
279
  "body_format" => Appsignal::EventFormatter::DEFAULT,
335
- "child_allocation_count" => kind_of(Integer),
336
- "child_duration" => kind_of(Float),
337
- "child_gc_duration" => kind_of(Float),
338
280
  "count" => 1,
339
- "gc_duration" => kind_of(Float),
340
- "start" => kind_of(Float),
341
- "duration" => kind_of(Float),
342
281
  "name" => "unsubscribed.action_cable",
343
282
  "title" => ""
344
283
  )
345
- expect(subject["sample_data"]).to include(
346
- "params" => { "internal" => "true" }
347
- )
348
284
  end
349
285
 
350
286
  context "without request_id (standalone server)" do
@@ -356,7 +292,7 @@ describe Appsignal::Hooks::ActionCableHook do
356
292
  end
357
293
 
358
294
  it "uses its own internal request_id" do
359
- expect(subject["id"]).to eq(transaction_id)
295
+ expect(transaction).to have_id(transaction_id)
360
296
  end
361
297
  end
362
298
 
@@ -378,23 +314,16 @@ describe Appsignal::Hooks::ActionCableHook do
378
314
  instance.unsubscribe_from_channel
379
315
  end.to raise_error(ExampleException)
380
316
 
381
- expect(subject).to include(
382
- "action" => "MyChannel#unsubscribed",
383
- "id" => transaction_id,
384
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
385
- "metadata" => {
386
- "method" => "websocket",
387
- "path" => "/blog"
388
- }
389
- )
390
- expect(subject["error"]).to include(
391
- "backtrace" => kind_of(String),
392
- "name" => "ExampleException",
393
- "message" => "oh no!"
394
- )
395
- expect(subject["sample_data"]).to include(
396
- "params" => { "internal" => "true" }
317
+ transaction = last_transaction
318
+ expect(transaction).to have_id(transaction_id)
319
+ expect(transaction).to have_action("MyChannel#unsubscribed")
320
+ expect(transaction).to have_namespace(Appsignal::Transaction::ACTION_CABLE)
321
+ expect(transaction).to have_error("ExampleException", "oh no!")
322
+ expect(transaction).to include_metadata(
323
+ "method" => "websocket",
324
+ "path" => "/blog"
397
325
  )
326
+ expect(transaction).to include_params("internal" => "true")
398
327
  end
399
328
  end
400
329
 
@@ -410,33 +339,23 @@ describe Appsignal::Hooks::ActionCableHook do
410
339
  it "does not fail on missing `#env` method on `ConnectionStub`" do
411
340
  instance.unsubscribe_from_channel
412
341
 
413
- expect(subject).to include(
414
- "action" => "MyChannel#unsubscribed",
415
- "error" => nil,
416
- "id" => transaction_id,
417
- "namespace" => Appsignal::Transaction::ACTION_CABLE,
418
- "metadata" => {
419
- "method" => "websocket",
420
- "path" => "" # No path as the ConnectionStub doesn't have the real request env
421
- }
342
+ transaction = last_transaction
343
+ expect(transaction).to have_id(transaction_id)
344
+ expect(transaction).to have_action("MyChannel#unsubscribed")
345
+ expect(transaction).to have_namespace(Appsignal::Transaction::ACTION_CABLE)
346
+ expect(transaction).to_not have_error
347
+ expect(transaction).to include_metadata(
348
+ "method" => "websocket",
349
+ "path" => "" # No path as the ConnectionStub doesn't have the real request env
422
350
  )
423
- expect(subject["events"].first).to include(
424
- "allocation_count" => kind_of(Integer),
351
+ expect(transaction).to include_params("internal" => "true")
352
+ expect(transaction).to include_event(
425
353
  "body" => "",
426
354
  "body_format" => Appsignal::EventFormatter::DEFAULT,
427
- "child_allocation_count" => kind_of(Integer),
428
- "child_duration" => kind_of(Float),
429
- "child_gc_duration" => kind_of(Float),
430
355
  "count" => 1,
431
- "gc_duration" => kind_of(Float),
432
- "start" => kind_of(Float),
433
- "duration" => kind_of(Float),
434
356
  "name" => "unsubscribed.action_cable",
435
357
  "title" => ""
436
358
  )
437
- expect(subject["sample_data"]).to include(
438
- "params" => { "internal" => "true" }
439
- )
440
359
  end
441
360
  end
442
361
  end
@@ -5,31 +5,19 @@ shared_examples "activesupport finish_with_state override" do
5
5
  listeners_state = instrumenter.start("sql.active_record", {})
6
6
  instrumenter.finish_with_state(listeners_state, "sql.active_record", :sql => "SQL")
7
7
 
8
- expect(transaction.to_h["events"]).to match([
9
- {
10
- "allocation_count" => kind_of(Integer),
11
- "body" => "SQL",
12
- "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT,
13
- "child_allocation_count" => kind_of(Integer),
14
- "child_duration" => kind_of(Float),
15
- "child_gc_duration" => kind_of(Float),
16
- "count" => 1,
17
- "duration" => kind_of(Float),
18
- "gc_duration" => kind_of(Float),
19
- "name" => "sql.active_record",
20
- "start" => kind_of(Float),
21
- "title" => ""
22
- }
23
- ])
8
+ expect(transaction).to include_event(
9
+ "body" => "SQL",
10
+ "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT,
11
+ "count" => 1,
12
+ "name" => "sql.active_record",
13
+ "title" => ""
14
+ )
24
15
  end
25
16
 
26
17
  it "does not instrument events whose name starts with a bang" do
27
- expect(Appsignal::Transaction.current).not_to receive(:start_event)
28
- expect(Appsignal::Transaction.current).not_to receive(:finish_event)
29
-
30
18
  listeners_state = instrumenter.start("!sql.active_record", {})
31
19
  instrumenter.finish_with_state(listeners_state, "!sql.active_record", :sql => "SQL")
32
20
 
33
- expect(transaction.to_h["events"]).to be_empty
21
+ expect(transaction).to_not include_events
34
22
  end
35
23
  end
@@ -5,22 +5,13 @@ shared_examples "activesupport instrument override" do
5
5
  end
6
6
 
7
7
  expect(return_value).to eq "value"
8
- expect(transaction.to_h["events"]).to match([
9
- {
10
- "allocation_count" => kind_of(Integer),
11
- "body" => "SQL",
12
- "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT,
13
- "child_allocation_count" => kind_of(Integer),
14
- "child_duration" => kind_of(Float),
15
- "child_gc_duration" => kind_of(Float),
16
- "count" => 1,
17
- "duration" => kind_of(Float),
18
- "gc_duration" => kind_of(Float),
19
- "name" => "sql.active_record",
20
- "start" => kind_of(Float),
21
- "title" => ""
22
- }
23
- ])
8
+ expect(transaction).to include_event(
9
+ "body" => "SQL",
10
+ "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT,
11
+ "count" => 1,
12
+ "name" => "sql.active_record",
13
+ "title" => ""
14
+ )
24
15
  end
25
16
 
26
17
  it "instruments an ActiveSupport::Notifications.instrument event with no registered formatter" do
@@ -29,53 +20,34 @@ shared_examples "activesupport instrument override" do
29
20
  end
30
21
 
31
22
  expect(return_value).to eq "value"
32
- expect(transaction.to_h["events"]).to match([
33
- {
34
- "allocation_count" => kind_of(Integer),
35
- "body" => "",
36
- "body_format" => Appsignal::EventFormatter::DEFAULT,
37
- "child_allocation_count" => kind_of(Integer),
38
- "child_duration" => kind_of(Float),
39
- "child_gc_duration" => kind_of(Float),
40
- "count" => 1,
41
- "duration" => kind_of(Float),
42
- "gc_duration" => kind_of(Float),
43
- "name" => "no-registered.formatter",
44
- "start" => kind_of(Float),
45
- "title" => ""
46
- }
47
- ])
23
+ expect(transaction).to include_event(
24
+ "body" => "",
25
+ "body_format" => Appsignal::EventFormatter::DEFAULT,
26
+ "count" => 1,
27
+ "name" => "no-registered.formatter",
28
+ "title" => ""
29
+ )
48
30
  end
49
31
 
50
32
  it "converts non-string names to strings" do
51
33
  as.instrument(:not_a_string) {} # rubocop:disable Lint/EmptyBlock
52
- expect(transaction.to_h["events"]).to match([
53
- {
54
- "allocation_count" => kind_of(Integer),
55
- "body" => "",
56
- "body_format" => Appsignal::EventFormatter::DEFAULT,
57
- "child_allocation_count" => kind_of(Integer),
58
- "child_duration" => kind_of(Float),
59
- "child_gc_duration" => kind_of(Float),
60
- "count" => 1,
61
- "duration" => kind_of(Float),
62
- "gc_duration" => kind_of(Float),
63
- "name" => "not_a_string",
64
- "start" => kind_of(Float),
65
- "title" => ""
66
- }
67
- ])
34
+ expect(transaction).to include_event(
35
+ "body" => "",
36
+ "body_format" => Appsignal::EventFormatter::DEFAULT,
37
+ "count" => 1,
38
+ "name" => "not_a_string",
39
+ "title" => ""
40
+ )
68
41
  end
69
42
 
70
43
  it "does not instrument events whose name starts with a bang" do
71
- expect(Appsignal::Transaction.current).not_to receive(:start_event)
72
- expect(Appsignal::Transaction.current).not_to receive(:finish_event)
73
-
74
44
  return_value = as.instrument("!sql.active_record", :sql => "SQL") do
75
45
  "value"
76
46
  end
77
47
 
78
48
  expect(return_value).to eq "value"
49
+
50
+ expect(transaction).to_not include_events
79
51
  end
80
52
 
81
53
  context "when an error is raised in an instrumented block" do
@@ -86,22 +58,13 @@ shared_examples "activesupport instrument override" do
86
58
  end
87
59
  end.to raise_error(ExampleException, "foo")
88
60
 
89
- expect(transaction.to_h["events"]).to match([
90
- {
91
- "allocation_count" => kind_of(Integer),
92
- "body" => "SQL",
93
- "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT,
94
- "child_allocation_count" => kind_of(Integer),
95
- "child_duration" => kind_of(Float),
96
- "child_gc_duration" => kind_of(Float),
97
- "count" => 1,
98
- "duration" => kind_of(Float),
99
- "gc_duration" => kind_of(Float),
100
- "name" => "sql.active_record",
101
- "start" => kind_of(Float),
102
- "title" => ""
103
- }
104
- ])
61
+ expect(transaction).to include_event(
62
+ "body" => "SQL",
63
+ "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT,
64
+ "count" => 1,
65
+ "name" => "sql.active_record",
66
+ "title" => ""
67
+ )
105
68
  end
106
69
  end
107
70
 
@@ -113,22 +76,13 @@ shared_examples "activesupport instrument override" do
113
76
  end
114
77
  end.to throw_symbol(:foo)
115
78
 
116
- expect(transaction.to_h["events"]).to match([
117
- {
118
- "allocation_count" => kind_of(Integer),
119
- "body" => "SQL",
120
- "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT,
121
- "child_allocation_count" => kind_of(Integer),
122
- "child_duration" => kind_of(Float),
123
- "child_gc_duration" => kind_of(Float),
124
- "count" => 1,
125
- "duration" => kind_of(Float),
126
- "gc_duration" => kind_of(Float),
127
- "name" => "sql.active_record",
128
- "start" => kind_of(Float),
129
- "title" => ""
130
- }
131
- ])
79
+ expect(transaction).to include_event(
80
+ "body" => "SQL",
81
+ "body_format" => Appsignal::EventFormatter::SQL_BODY_FORMAT,
82
+ "count" => 1,
83
+ "name" => "sql.active_record",
84
+ "title" => ""
85
+ )
132
86
  end
133
87
  end
134
88
 
@@ -139,7 +93,7 @@ shared_examples "activesupport instrument override" do
139
93
  Appsignal::Transaction.complete_current!
140
94
  end
141
95
 
142
- expect(transaction.to_h["events"]).to match([])
96
+ expect(transaction).to_not include_events
143
97
  end
144
98
  end
145
99
  end