appsignal 3.9.2-java → 3.9.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) 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 +38 -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 +1 -1
  17. data/lib/appsignal/integrations/grape.rb +19 -47
  18. data/lib/appsignal/integrations/hanami.rb +8 -7
  19. data/lib/appsignal/integrations/padrino.rb +46 -43
  20. data/lib/appsignal/integrations/railtie.rb +0 -3
  21. data/lib/appsignal/integrations/sinatra.rb +0 -1
  22. data/lib/appsignal/probes/gvl.rb +24 -2
  23. data/lib/appsignal/probes/sidekiq.rb +1 -1
  24. data/lib/appsignal/probes.rb +1 -1
  25. data/lib/appsignal/rack/abstract_middleware.rb +62 -28
  26. data/lib/appsignal/rack/event_handler.rb +12 -3
  27. data/lib/appsignal/rack/grape_middleware.rb +40 -0
  28. data/lib/appsignal/rack/hanami_middleware.rb +1 -11
  29. data/lib/appsignal/rack/rails_instrumentation.rb +14 -55
  30. data/lib/appsignal/utils/integration_memory_logger.rb +78 -0
  31. data/lib/appsignal/utils.rb +1 -0
  32. data/lib/appsignal/version.rb +1 -1
  33. data/lib/appsignal.rb +34 -33
  34. data/spec/.rubocop.yml +1 -1
  35. data/spec/lib/appsignal/cli/diagnose_spec.rb +1 -1
  36. data/spec/lib/appsignal/cli/install_spec.rb +3 -3
  37. data/spec/lib/appsignal/config_spec.rb +7 -5
  38. data/spec/lib/appsignal/demo_spec.rb +38 -41
  39. data/spec/lib/appsignal/hooks/action_cable_spec.rb +86 -167
  40. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +8 -20
  41. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +38 -84
  42. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +16 -37
  43. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +4 -4
  44. data/spec/lib/appsignal/hooks/activejob_spec.rb +111 -200
  45. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +54 -91
  46. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +14 -32
  47. data/spec/lib/appsignal/hooks/excon_spec.rb +8 -12
  48. data/spec/lib/appsignal/hooks/net_http_spec.rb +7 -42
  49. data/spec/lib/appsignal/hooks/rake_spec.rb +9 -19
  50. data/spec/lib/appsignal/hooks/redis_client_spec.rb +18 -30
  51. data/spec/lib/appsignal/hooks/redis_spec.rb +10 -16
  52. data/spec/lib/appsignal/hooks/resque_spec.rb +42 -62
  53. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +33 -74
  54. data/spec/lib/appsignal/integrations/hanami_spec.rb +79 -21
  55. data/spec/lib/appsignal/integrations/http_spec.rb +12 -20
  56. data/spec/lib/appsignal/integrations/net_http_spec.rb +33 -0
  57. data/spec/lib/appsignal/integrations/object_spec.rb +29 -36
  58. data/spec/lib/appsignal/integrations/padrino_spec.rb +47 -70
  59. data/spec/lib/appsignal/integrations/que_spec.rb +43 -70
  60. data/spec/lib/appsignal/integrations/railtie_spec.rb +26 -67
  61. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +86 -160
  62. data/spec/lib/appsignal/integrations/sinatra_spec.rb +0 -1
  63. data/spec/lib/appsignal/integrations/webmachine_spec.rb +28 -39
  64. data/spec/lib/appsignal/probes/gvl_spec.rb +80 -3
  65. data/spec/lib/appsignal/probes_spec.rb +7 -4
  66. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +215 -106
  67. data/spec/lib/appsignal/rack/event_handler_spec.rb +81 -78
  68. data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +2 -12
  69. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +234 -0
  70. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +2 -16
  71. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +67 -131
  72. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +36 -44
  73. data/spec/lib/appsignal/rack/streaming_listener_spec.rb +68 -86
  74. data/spec/lib/appsignal/transaction_spec.rb +76 -90
  75. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +163 -0
  76. data/spec/lib/appsignal_spec.rb +363 -342
  77. data/spec/support/helpers/dependency_helper.rb +6 -1
  78. data/spec/support/helpers/std_streams_helper.rb +1 -1
  79. data/spec/support/helpers/transaction_helpers.rb +8 -0
  80. data/spec/support/matchers/transaction.rb +185 -0
  81. data/spec/support/mocks/dummy_app.rb +20 -0
  82. data/spec/support/shared_examples/instrument.rb +17 -12
  83. data/spec/support/testing.rb +18 -9
  84. metadata +15 -10
  85. data/.semaphore/semaphore.yml +0 -2347
  86. data/script/lint_git +0 -22
  87. data/spec/lib/appsignal/integrations/grape_spec.rb +0 -239
  88. data/spec/support/matchers/be_completed.rb +0 -5
  89. /data/gemfiles/{hanami.gemfile → hanami-2.0.gemfile} +0 -0
@@ -119,25 +119,19 @@ if DependencyHelper.active_job_present?
119
119
  queue_job(ActiveJobTestJob)
120
120
 
121
121
  transaction = last_transaction
122
- transaction_hash = transaction.to_h
123
- expect(transaction_hash).to include(
124
- "action" => "ActiveJobTestJob#perform",
125
- "error" => nil,
126
- "namespace" => namespace,
127
- "metadata" => {},
128
- "sample_data" => hash_including(
129
- "params" => [],
130
- "tags" => {
131
- "active_job_id" => kind_of(String),
132
- "queue" => queue,
133
- "executions" => 1
134
- }
135
- )
122
+ expect(transaction).to have_namespace(namespace)
123
+ expect(transaction).to have_action("ActiveJobTestJob#perform")
124
+ expect(transaction).to_not have_error
125
+ expect(transaction).to_not include_metadata
126
+ expect(transaction).to include_params([])
127
+ expect(transaction).to include_tags(
128
+ "active_job_id" => kind_of(String),
129
+ "queue" => queue,
130
+ "executions" => 1
136
131
  )
137
- events = transaction_hash["events"]
132
+ events = transaction.to_h["events"]
138
133
  .sort_by { |e| e["start"] }
139
134
  .map { |event| event["name"] }
140
-
141
135
  expect(events).to eq(expected_perform_events)
142
136
  end
143
137
 
@@ -148,13 +142,7 @@ if DependencyHelper.active_job_present?
148
142
  .with("active_job_queue_job_count", 1, tags.merge(:status => :processed))
149
143
  queue_job(ActiveJobCustomQueueTestJob)
150
144
 
151
- transaction = last_transaction
152
- transaction_hash = transaction.to_h
153
- expect(transaction_hash).to include(
154
- "sample_data" => hash_including(
155
- "tags" => hash_including("queue" => "custom_queue")
156
- )
157
- )
145
+ expect(last_transaction).to include_tags("queue" => "custom_queue")
158
146
  end
159
147
  end
160
148
 
@@ -182,13 +170,7 @@ if DependencyHelper.active_job_present?
182
170
 
183
171
  queue_job(ActiveJobPriorityTestJob)
184
172
 
185
- transaction = last_transaction
186
- transaction_hash = transaction.to_h
187
- expect(transaction_hash).to include(
188
- "sample_data" => hash_including(
189
- "tags" => hash_including("queue" => queue, "priority" => 10)
190
- )
191
- )
173
+ expect(last_transaction).to include_tags("queue" => queue, "priority" => 10)
192
174
  end
193
175
  end
194
176
  end
@@ -207,29 +189,20 @@ if DependencyHelper.active_job_present?
207
189
  end.to raise_error(RuntimeError, "uh oh")
208
190
 
209
191
  transaction = last_transaction
210
- transaction_hash = transaction.to_h
211
- expect(transaction_hash).to include(
212
- "action" => "ActiveJobErrorTestJob#perform",
213
- "error" => {
214
- "name" => "RuntimeError",
215
- "message" => "uh oh",
216
- "backtrace" => kind_of(String)
217
- },
218
- "namespace" => namespace,
219
- "metadata" => {},
220
- "sample_data" => hash_including(
221
- "params" => [],
222
- "tags" => {
223
- "active_job_id" => kind_of(String),
224
- "queue" => queue,
225
- "executions" => 1
226
- }
227
- )
192
+ expect(transaction).to have_namespace(namespace)
193
+ expect(transaction).to have_action("ActiveJobErrorTestJob#perform")
194
+ expect(transaction).to have_error("RuntimeError", "uh oh")
195
+ expect(transaction).to_not include_metadata
196
+ expect(transaction).to include_params([])
197
+ expect(transaction).to include_tags(
198
+ "active_job_id" => kind_of(String),
199
+ "queue" => queue,
200
+ "executions" => 1
228
201
  )
229
- events = transaction_hash["events"]
202
+
203
+ events = transaction.to_h["events"]
230
204
  .sort_by { |e| e["start"] }
231
205
  .map { |event| event["name"] }
232
-
233
206
  expect(events).to eq(expected_perform_events)
234
207
  end
235
208
 
@@ -247,9 +220,7 @@ if DependencyHelper.active_job_present?
247
220
  queue_job(ActiveJobErrorTestJob)
248
221
  end.to raise_error(RuntimeError, "uh oh")
249
222
 
250
- transaction = last_transaction
251
- transaction_hash = transaction.to_h
252
- expect(transaction_hash).to include("error" => nil)
223
+ expect(last_transaction).to_not have_error
253
224
  end
254
225
  end
255
226
 
@@ -270,15 +241,8 @@ if DependencyHelper.active_job_present?
270
241
  end
271
242
 
272
243
  transaction = last_transaction
273
- transaction_hash = transaction.to_h
274
- expect(transaction_hash).to include(
275
- "error" => nil,
276
- "sample_data" => hash_including(
277
- "tags" => hash_including(
278
- "executions" => 1
279
- )
280
- )
281
- )
244
+ expect(transaction).to_not have_error
245
+ expect(transaction).to include_tags("executions" => 1)
282
246
  end
283
247
 
284
248
  it "reports error when discarding the job" do
@@ -294,19 +258,8 @@ if DependencyHelper.active_job_present?
294
258
  end
295
259
 
296
260
  transaction = last_transaction
297
- transaction_hash = transaction.to_h
298
- expect(transaction_hash).to include(
299
- "error" => {
300
- "name" => "RuntimeError",
301
- "message" => "uh oh",
302
- "backtrace" => kind_of(String)
303
- },
304
- "sample_data" => hash_including(
305
- "tags" => hash_including(
306
- "executions" => 2
307
- )
308
- )
309
- )
261
+ expect(transaction).to have_error("RuntimeError", "uh oh")
262
+ expect(transaction).to include_tags("executions" => 2)
310
263
  end
311
264
  end
312
265
  end
@@ -343,13 +296,7 @@ if DependencyHelper.active_job_present?
343
296
  queue_job(ActiveJobErrorPriorityTestJob)
344
297
  end.to raise_error(RuntimeError, "uh oh")
345
298
 
346
- transaction = last_transaction
347
- transaction_hash = transaction.to_h
348
- expect(transaction_hash).to include(
349
- "sample_data" => hash_including(
350
- "tags" => hash_including("queue" => queue, "priority" => 10)
351
- )
352
- )
299
+ expect(last_transaction).to include_tags("queue" => queue, "priority" => 10)
353
300
  end
354
301
  end
355
302
  end
@@ -363,51 +310,39 @@ if DependencyHelper.active_job_present?
363
310
  end.to raise_error(RuntimeError, "uh oh")
364
311
  end
365
312
 
366
- transaction = last_transaction
367
- transaction_hash = transaction.to_h
368
- expect(transaction_hash).to include(
369
- "sample_data" => hash_including(
370
- "tags" => hash_including("executions" => 2)
371
- )
372
- )
313
+ expect(last_transaction).to include_tags("executions" => 2)
373
314
  end
374
315
  end
375
316
 
376
317
  context "when wrapped in another transaction" do
377
318
  it "does not create a new transaction or close the currently open one" do
378
319
  current_transaction = background_job_transaction
379
- allow(current_transaction).to receive(:complete).and_call_original
380
320
  set_current_transaction current_transaction
381
321
 
382
322
  queue_job(ActiveJobTestJob)
383
323
 
384
324
  expect(created_transactions.count).to eql(1)
385
- expect(current_transaction).to_not have_received(:complete)
386
- current_transaction.complete
387
325
 
388
326
  transaction = current_transaction
389
- transaction_hash = transaction.to_h
327
+ expect(transaction).to_not be_completed
328
+ transaction._sample
390
329
  # It does set data on the transaction
391
- expect(transaction_hash).to include(
392
- "id" => current_transaction.transaction_id,
393
- "action" => "ActiveJobTestJob#perform",
394
- "error" => nil,
395
- "namespace" => namespace,
396
- "metadata" => {},
397
- "sample_data" => hash_including(
398
- "params" => [],
399
- "tags" => {
400
- "active_job_id" => kind_of(String),
401
- "queue" => queue,
402
- "executions" => 1
403
- }
404
- )
330
+ expect(transaction).to have_namespace(namespace)
331
+ expect(transaction).to have_id(current_transaction.transaction_id)
332
+ expect(transaction).to have_action("ActiveJobTestJob#perform")
333
+ expect(transaction).to_not have_error
334
+ expect(transaction).to_not include_metadata
335
+ expect(transaction).to include_params([])
336
+ expect(transaction).to include_tags(
337
+ "active_job_id" => kind_of(String),
338
+ "queue" => queue,
339
+ "executions" => 1
405
340
  )
406
- events = transaction_hash["events"]
341
+
342
+ events = transaction.to_h["events"]
407
343
  .reject { |e| e["name"] == "enqueue.active_job" }
408
344
  .sort_by { |e| e["start"] }
409
345
  .map { |event| event["name"] }
410
-
411
346
  expect(events).to eq(expected_perform_events)
412
347
  end
413
348
  end
@@ -467,9 +402,7 @@ if DependencyHelper.active_job_present?
467
402
  it "sets provider_job_id as tag" do
468
403
  queue_job(ProviderWrappedActiveJobTestJob)
469
404
 
470
- transaction = last_transaction
471
- transaction_hash = transaction.to_h
472
- expect(transaction_hash["sample_data"]["tags"]).to include(
405
+ expect(last_transaction).to include_tags(
473
406
  "provider_job_id" => "my_provider_job_id"
474
407
  )
475
408
  end
@@ -506,13 +439,10 @@ if DependencyHelper.active_job_present?
506
439
  end
507
440
 
508
441
  it "sets queue time on transaction" do
509
- allow_any_instance_of(Appsignal::Transaction).to receive(:set_queue_start).and_call_original
510
442
  queue_job(ProviderWrappedActiveJobTestJob)
511
443
 
512
- transaction = last_transaction
513
444
  queue_time = Time.parse("2020-10-10T10:10:10Z")
514
- expect(transaction).to have_received(:set_queue_start)
515
- .with((queue_time.to_f * 1_000).to_i)
445
+ expect(last_transaction).to have_queue_start((queue_time.to_f * 1_000).to_i)
516
446
  end
517
447
  end
518
448
 
@@ -534,18 +464,14 @@ if DependencyHelper.active_job_present?
534
464
  perform_mailer(ActionMailerTestJob, :welcome)
535
465
 
536
466
  transaction = last_transaction
537
- transaction_hash = transaction.to_h
538
- expect(transaction_hash).to include(
539
- "action" => "ActionMailerTestJob#welcome",
540
- "sample_data" => hash_including(
541
- "params" => ["ActionMailerTestJob", "welcome",
542
- "deliver_now"] + active_job_args_wrapper,
543
- "tags" => {
544
- "active_job_id" => kind_of(String),
545
- "queue" => "mailers",
546
- "executions" => 1
547
- }
548
- )
467
+ expect(transaction).to have_action("ActionMailerTestJob#welcome")
468
+ expect(transaction).to include_params(
469
+ ["ActionMailerTestJob", "welcome", "deliver_now"] + active_job_args_wrapper
470
+ )
471
+ expect(transaction).to include_tags(
472
+ "active_job_id" => kind_of(String),
473
+ "queue" => "mailers",
474
+ "executions" => 1
549
475
  )
550
476
  end
551
477
  end
@@ -555,18 +481,15 @@ if DependencyHelper.active_job_present?
555
481
  perform_mailer(ActionMailerTestJob, :welcome, method_given_args)
556
482
 
557
483
  transaction = last_transaction
558
- transaction_hash = transaction.to_h
559
- expect(transaction_hash).to include(
560
- "action" => "ActionMailerTestJob#welcome",
561
- "sample_data" => hash_including(
562
- "params" => ["ActionMailerTestJob", "welcome",
563
- "deliver_now"] + active_job_args_wrapper(:args => method_expected_args),
564
- "tags" => {
565
- "active_job_id" => kind_of(String),
566
- "queue" => "mailers",
567
- "executions" => 1
568
- }
569
- )
484
+ expect(transaction).to have_action("ActionMailerTestJob#welcome")
485
+ expect(transaction).to include_params(
486
+ ["ActionMailerTestJob", "welcome",
487
+ "deliver_now"] + active_job_args_wrapper(:args => method_expected_args)
488
+ )
489
+ expect(transaction).to include_tags(
490
+ "active_job_id" => kind_of(String),
491
+ "queue" => "mailers",
492
+ "executions" => 1
570
493
  )
571
494
  end
572
495
  end
@@ -577,21 +500,18 @@ if DependencyHelper.active_job_present?
577
500
  perform_mailer(ActionMailerTestJob, :welcome, parameterized_given_args)
578
501
 
579
502
  transaction = last_transaction
580
- transaction_hash = transaction.to_h
581
- expect(transaction_hash).to include(
582
- "action" => "ActionMailerTestJob#welcome",
583
- "sample_data" => hash_including(
584
- "params" => [
585
- "ActionMailerTestJob",
586
- "welcome",
587
- "deliver_now"
588
- ] + active_job_args_wrapper(:params => parameterized_expected_args),
589
- "tags" => {
590
- "active_job_id" => kind_of(String),
591
- "queue" => "mailers",
592
- "executions" => 1
593
- }
594
- )
503
+ expect(transaction).to have_action("ActionMailerTestJob#welcome")
504
+ expect(transaction).to include_params(
505
+ [
506
+ "ActionMailerTestJob",
507
+ "welcome",
508
+ "deliver_now"
509
+ ] + active_job_args_wrapper(:params => parameterized_expected_args)
510
+ )
511
+ expect(transaction).to include_tags(
512
+ "active_job_id" => kind_of(String),
513
+ "queue" => "mailers",
514
+ "executions" => 1
595
515
  )
596
516
  end
597
517
  end
@@ -618,22 +538,19 @@ if DependencyHelper.active_job_present?
618
538
  perform_mailer(ActionMailerTestMailDeliveryJob, :welcome)
619
539
 
620
540
  transaction = last_transaction
621
- transaction_hash = transaction.to_h
622
- expect(transaction_hash).to include(
623
- "action" => "ActionMailerTestMailDeliveryJob#welcome",
624
- "sample_data" => hash_including(
625
- "params" => [
626
- "ActionMailerTestMailDeliveryJob",
627
- "welcome",
628
- "deliver_now",
629
- { active_job_internal_key => ["args"], "args" => [] }
630
- ],
631
- "tags" => {
632
- "active_job_id" => kind_of(String),
633
- "queue" => "mailers",
634
- "executions" => 1
635
- }
636
- )
541
+ expect(transaction).to have_action("ActionMailerTestMailDeliveryJob#welcome")
542
+ expect(transaction).to include_params(
543
+ [
544
+ "ActionMailerTestMailDeliveryJob",
545
+ "welcome",
546
+ "deliver_now",
547
+ { active_job_internal_key => ["args"], "args" => [] }
548
+ ]
549
+ )
550
+ expect(transaction).to include_tags(
551
+ "active_job_id" => kind_of(String),
552
+ "queue" => "mailers",
553
+ "executions" => 1
637
554
  )
638
555
  end
639
556
 
@@ -642,25 +559,22 @@ if DependencyHelper.active_job_present?
642
559
  perform_mailer(ActionMailerTestMailDeliveryJob, :welcome, method_given_args)
643
560
 
644
561
  transaction = last_transaction
645
- transaction_hash = transaction.to_h
646
- expect(transaction_hash).to include(
647
- "action" => "ActionMailerTestMailDeliveryJob#welcome",
648
- "sample_data" => hash_including(
649
- "params" => [
650
- "ActionMailerTestMailDeliveryJob",
651
- "welcome",
652
- "deliver_now",
653
- {
654
- active_job_internal_key => ["args"],
655
- "args" => method_expected_args
656
- }
657
- ],
658
- "tags" => {
659
- "active_job_id" => kind_of(String),
660
- "queue" => "mailers",
661
- "executions" => 1
562
+ expect(transaction).to have_action("ActionMailerTestMailDeliveryJob#welcome")
563
+ expect(transaction).to include_params(
564
+ [
565
+ "ActionMailerTestMailDeliveryJob",
566
+ "welcome",
567
+ "deliver_now",
568
+ {
569
+ active_job_internal_key => ["args"],
570
+ "args" => method_expected_args
662
571
  }
663
- )
572
+ ]
573
+ )
574
+ expect(transaction).to include_tags(
575
+ "active_job_id" => kind_of(String),
576
+ "queue" => "mailers",
577
+ "executions" => 1
664
578
  )
665
579
  end
666
580
  end
@@ -670,11 +584,9 @@ if DependencyHelper.active_job_present?
670
584
  perform_mailer(ActionMailerTestMailDeliveryJob, :welcome, parameterized_given_args)
671
585
 
672
586
  transaction = last_transaction
673
- transaction_hash = transaction.to_h
674
- expect(transaction_hash).to include(
675
- "action" => "ActionMailerTestMailDeliveryJob#welcome",
676
- "sample_data" => hash_including(
677
- "params" => [
587
+ expect(transaction).to have_action("ActionMailerTestMailDeliveryJob#welcome")
588
+ expect(transaction).to include_params(
589
+ [
678
590
  "ActionMailerTestMailDeliveryJob",
679
591
  "welcome",
680
592
  "deliver_now",
@@ -683,13 +595,12 @@ if DependencyHelper.active_job_present?
683
595
  "args" => [],
684
596
  "params" => parameterized_expected_args
685
597
  }
686
- ],
687
- "tags" => {
688
- "active_job_id" => kind_of(String),
689
- "queue" => "mailers",
690
- "executions" => 1
691
- }
598
+ ]
692
599
  )
600
+ expect(transaction).to include_tags(
601
+ "active_job_id" => kind_of(String),
602
+ "queue" => "mailers",
603
+ "executions" => 1
693
604
  )
694
605
  end
695
606
  end