newrelic_rpm 3.8.0.218 → 3.8.1.221

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +32 -0
  3. data/README.md +4 -7
  4. data/Rakefile +3 -0
  5. data/lib/new_relic/agent.rb +3 -7
  6. data/lib/new_relic/agent/agent.rb +4 -14
  7. data/lib/new_relic/agent/agent_logger.rb +19 -11
  8. data/lib/new_relic/agent/autostart.rb +1 -1
  9. data/lib/new_relic/agent/configuration/default_source.rb +25 -12
  10. data/lib/new_relic/agent/configuration/manager.rb +14 -7
  11. data/lib/new_relic/agent/configuration/yaml_source.rb +39 -8
  12. data/lib/new_relic/agent/cross_app_monitor.rb +9 -7
  13. data/lib/new_relic/agent/cross_app_tracing.rb +6 -6
  14. data/lib/new_relic/agent/datastores/mongo.rb +6 -7
  15. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +32 -13
  16. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +4 -3
  17. data/lib/new_relic/agent/error_collector.rb +2 -2
  18. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +10 -69
  19. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +5 -7
  20. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +2 -2
  21. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +77 -93
  22. data/lib/new_relic/agent/instrumentation/evented_subscriber.rb +1 -1
  23. data/lib/new_relic/agent/instrumentation/mongo.rb +26 -42
  24. data/lib/new_relic/agent/instrumentation/rubyprof.rb +1 -1
  25. data/lib/new_relic/agent/instrumentation/sinatra.rb +4 -1
  26. data/lib/new_relic/agent/javascript_instrumentor.rb +15 -6
  27. data/lib/new_relic/agent/method_tracer.rb +41 -92
  28. data/lib/new_relic/agent/request_sampler.rb +0 -1
  29. data/lib/new_relic/agent/rules_engine.rb +36 -12
  30. data/lib/new_relic/agent/shim_agent.rb +0 -1
  31. data/lib/new_relic/agent/sql_sampler.rb +8 -15
  32. data/lib/new_relic/agent/stats_engine.rb +2 -6
  33. data/lib/new_relic/agent/stats_engine/metric_stats.rb +8 -2
  34. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  35. data/lib/new_relic/agent/supported_versions.rb +1 -1
  36. data/lib/new_relic/agent/traced_method_stack.rb +87 -0
  37. data/lib/new_relic/agent/transaction.rb +277 -107
  38. data/lib/new_relic/agent/transaction_sample_builder.rb +2 -2
  39. data/lib/new_relic/agent/transaction_sampler.rb +18 -27
  40. data/lib/new_relic/agent/transaction_state.rb +15 -40
  41. data/lib/new_relic/control/instance_methods.rb +8 -4
  42. data/lib/new_relic/recipes.rb +3 -3
  43. data/lib/new_relic/transaction_sample.rb +3 -7
  44. data/lib/new_relic/version.rb +1 -1
  45. data/lib/sequel/extensions/newrelic_instrumentation.rb +3 -3
  46. data/newrelic_rpm.gemspec +15 -9
  47. data/test/agent_helper.rb +71 -36
  48. data/test/environments/norails/Gemfile +2 -0
  49. data/test/environments/rails21/Gemfile +2 -0
  50. data/test/environments/rails22/Gemfile +2 -0
  51. data/test/environments/rails23/Gemfile +2 -0
  52. data/test/environments/rails30/Gemfile +2 -0
  53. data/test/environments/rails31/Gemfile +2 -0
  54. data/test/environments/rails32/Gemfile +2 -0
  55. data/test/environments/rails40/Gemfile +2 -0
  56. data/test/environments/rails41/Gemfile +1 -0
  57. data/test/helpers/mongo_metric_builder.rb +1 -1
  58. data/test/multiverse/suites/agent_only/audit_log_test.rb +2 -2
  59. data/test/multiverse/suites/agent_only/cross_application_tracing_test.rb +9 -1
  60. data/test/multiverse/suites/agent_only/encoding_handling_test.rb +1 -1
  61. data/test/multiverse/suites/agent_only/logging_test.rb +2 -2
  62. data/test/multiverse/suites/agent_only/marshaling_test.rb +8 -9
  63. data/test/multiverse/suites/agent_only/rum_instrumentation_test.rb +14 -1
  64. data/test/multiverse/suites/agent_only/set_transaction_name_test.rb +30 -13
  65. data/test/multiverse/suites/agent_only/thread_profiling_test.rb +9 -8
  66. data/test/multiverse/suites/agent_only/transaction_ignoring_test.rb +43 -0
  67. data/test/multiverse/suites/config_file_loading/config_file_loading_test.rb +77 -5
  68. data/test/multiverse/suites/excon/excon_test.rb +1 -1
  69. data/test/multiverse/suites/mongo/Envfile +4 -7
  70. data/test/multiverse/suites/mongo/helpers/mongo_operation_tests.rb +55 -16
  71. data/test/multiverse/suites/mongo/helpers/mongo_server.rb +6 -4
  72. data/test/multiverse/suites/rails/bad_instrumentation_test.rb +2 -2
  73. data/test/multiverse/suites/rails/error_tracing_test.rb +3 -1
  74. data/test/multiverse/suites/rails/request_statistics_test.rb +14 -14
  75. data/test/multiverse/suites/rails/transaction_ignoring_test.rb +45 -0
  76. data/test/multiverse/suites/sequel/sequel_instrumentation_test.rb +1 -1
  77. data/test/new_relic/agent/agent/connect_test.rb +4 -4
  78. data/test/new_relic/agent/agent_logger_test.rb +32 -0
  79. data/test/new_relic/agent/configuration/manager_test.rb +12 -4
  80. data/test/new_relic/agent/configuration/yaml_source_test.rb +2 -2
  81. data/test/new_relic/agent/cross_app_monitor_test.rb +6 -2
  82. data/test/new_relic/agent/cross_app_tracing_test.rb +5 -5
  83. data/test/new_relic/agent/datastores/mongo/statement_formatter_test.rb +7 -6
  84. data/test/new_relic/agent/error_collector_test.rb +1 -2
  85. data/test/new_relic/agent/instrumentation/action_controller_subscriber_test.rb +24 -11
  86. data/test/new_relic/agent/instrumentation/action_view_subscriber_test.rb +2 -2
  87. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +12 -17
  88. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +43 -32
  89. data/test/new_relic/agent/instrumentation/net_instrumentation_test.rb +3 -4
  90. data/test/new_relic/agent/instrumentation/task_instrumentation_test.rb +36 -20
  91. data/test/new_relic/agent/javascript_instrumentor_test.rb +1 -2
  92. data/test/new_relic/agent/method_tracer/class_methods/add_method_tracer_test.rb +15 -26
  93. data/test/new_relic/agent/method_tracer/instance_methods/trace_execution_scoped_test.rb +66 -103
  94. data/test/new_relic/agent/method_tracer_test.rb +2 -2
  95. data/test/new_relic/agent/mock_scope_listener.rb +3 -6
  96. data/test/new_relic/agent/pipe_channel_manager_test.rb +4 -4
  97. data/test/new_relic/agent/rules_engine_test.rb +13 -0
  98. data/test/new_relic/agent/sql_sampler_test.rb +8 -10
  99. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +18 -0
  100. data/test/new_relic/agent/stats_engine_test.rb +0 -173
  101. data/test/new_relic/agent/threading/agent_thread_test.rb +27 -26
  102. data/test/new_relic/agent/traced_method_stack_test.rb +139 -0
  103. data/test/new_relic/agent/transaction_sample_builder_test.rb +2 -12
  104. data/test/new_relic/agent/transaction_sampler_test.rb +98 -107
  105. data/test/new_relic/agent/transaction_state_test.rb +52 -61
  106. data/test/new_relic/agent/transaction_test.rb +209 -140
  107. data/test/new_relic/agent_test.rb +3 -2
  108. data/test/new_relic/control_test.rb +10 -9
  109. data/test/new_relic/fake_collector.rb +34 -2
  110. data/test/new_relic/http_client_test_cases.rb +0 -5
  111. data/test/new_relic/license_test.rb +4 -2
  112. data/test/new_relic/local_environment_test.rb +14 -28
  113. data/test/new_relic/multiverse_helpers.rb +2 -2
  114. data/test/new_relic/rack/developer_mode_test.rb +4 -5
  115. data/test/new_relic/transaction_ignoring_test_cases.rb +104 -0
  116. data/test/new_relic/transaction_sample_test.rb +14 -7
  117. data/test/performance/lib/performance/instrumentation/gc_stats.rb +6 -3
  118. data/test/performance/suites/transaction_tracing.rb +4 -1
  119. data/test/test_helper.rb +31 -60
  120. data/ui/views/newrelic/show_sample.rhtml +1 -1
  121. metadata +46 -101
  122. metadata.gz.sig +0 -0
  123. data/lib/new_relic/agent/stats_engine/transactions.rb +0 -114
  124. data/lib/new_relic/agent/transaction/pop.rb +0 -52
  125. data/test/new_relic/agent/transaction/pop_test.rb +0 -79
@@ -31,12 +31,11 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
31
31
  stats_engine = NewRelic::Agent::StatsEngine.new
32
32
  agent.stubs(:stats_engine).returns(stats_engine)
33
33
  @sampler = NewRelic::Agent::TransactionSampler.new
34
- stats_engine.transaction_sampler = @sampler
35
34
  @old_sampler = NewRelic::Agent.instance.transaction_sampler
36
35
  NewRelic::Agent.instance.instance_variable_set(:@transaction_sampler, @sampler)
37
36
  @test_config = { :'transaction_tracer.enabled' => true }
38
37
  NewRelic::Agent.config.apply_config(@test_config)
39
- @txn = stub('txn', :name => '/path', :custom_parameters => {}, :guid => 'a guid')
38
+ @txn = stub('txn', :best_name => '/path', :custom_parameters => {}, :guid => 'a guid')
40
39
  end
41
40
 
42
41
  def teardown
@@ -63,39 +62,39 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
63
62
 
64
63
  # Tests
65
64
 
66
- def test_notice_first_scope_push_default
65
+ def test_on_start_transaction_default
67
66
  @sampler.expects(:start_builder).with(100.0)
68
- @sampler.notice_first_scope_push(Time.at(100))
67
+ @sampler.on_start_transaction(Time.at(100))
69
68
  end
70
69
 
71
- def test_notice_first_scope_push_disabled
70
+ def test_on_start_transaction_disabled
72
71
  with_config(:'transaction_tracer.enabled' => false,
73
72
  :developer_mode => false) do
74
73
  @sampler.expects(:start_builder).never
75
- @sampler.notice_first_scope_push(Time.at(100))
74
+ @sampler.on_start_transaction(Time.at(100))
76
75
  end
77
76
  end
78
77
 
79
- def test_notice_push_scope_no_builder
78
+ def test_notice_push_frame_no_builder
80
79
  @sampler.expects(:builder)
81
- assert_equal(nil, @sampler.notice_push_scope())
80
+ assert_equal(nil, @sampler.notice_push_frame())
82
81
  end
83
82
 
84
- def test_notice_push_scope_with_builder
83
+ def test_notice_push_frame_with_builder
85
84
  with_config(:developer_mode => false) do
86
85
  builder = mock('builder')
87
86
  builder.expects(:trace_entry).with(100.0)
88
87
  @sampler.expects(:builder).returns(builder).twice
89
- @sampler.notice_push_scope(Time.at(100))
88
+ @sampler.notice_push_frame(Time.at(100))
90
89
  end
91
90
  end
92
91
 
93
- def test_notice_pop_scope_no_builder
92
+ def test_notice_pop_frame_no_builder
94
93
  @sampler.expects(:builder).returns(nil)
95
- assert_equal(nil, @sampler.notice_pop_scope('a scope', Time.at(100)))
94
+ assert_equal(nil, @sampler.notice_pop_frame('a frame', Time.at(100)))
96
95
  end
97
96
 
98
- def test_notice_pop_scope_with_finished_sample
97
+ def test_notice_pop_frame_with_finished_sample
99
98
  builder = mock('builder')
100
99
  sample = mock('sample')
101
100
  builder.expects(:sample).returns(sample)
@@ -103,27 +102,27 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
103
102
  @sampler.expects(:builder).returns(builder).twice
104
103
 
105
104
  assert_raises(RuntimeError) do
106
- @sampler.notice_pop_scope('a scope', Time.at(100))
105
+ @sampler.notice_pop_frame('a frame', Time.at(100))
107
106
  end
108
107
  end
109
108
 
110
- def test_notice_pop_scope_builder_delegation
109
+ def test_notice_pop_frame_builder_delegation
111
110
  builder = mock('builder')
112
- builder.expects(:trace_exit).with('a scope', 100.0)
111
+ builder.expects(:trace_exit).with('a frame', 100.0)
113
112
  sample = mock('sample')
114
113
  builder.expects(:sample).returns(sample)
115
114
  sample.expects(:finished).returns(false)
116
115
  @sampler.expects(:builder).returns(builder).times(3)
117
116
 
118
- @sampler.notice_pop_scope('a scope', Time.at(100))
117
+ @sampler.notice_pop_frame('a frame', Time.at(100))
119
118
  end
120
119
 
121
- def test_notice_scope_empty_no_builder
120
+ def test_on_finishing_transaction_no_builder
122
121
  @sampler.expects(:builder).returns(nil)
123
- assert_equal(nil, @sampler.notice_scope_empty(@txn))
122
+ assert_equal(nil, @sampler.on_finishing_transaction(@txn))
124
123
  end
125
124
 
126
- def test_notice_scope_empty_ignored_transaction
125
+ def test_on_finishing_transaction_ignored_transaction
127
126
  builder = mock('builder')
128
127
  # the builder should be cached, so only called once
129
128
  @sampler.expects(:builder).returns(builder).once
@@ -135,10 +134,10 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
135
134
  builder.expects(:ignored?).returns(true)
136
135
  builder.expects(:set_transaction_name).returns(true)
137
136
 
138
- assert_equal(nil, @sampler.notice_scope_empty(@txn, Time.at(100)))
137
+ assert_equal(nil, @sampler.on_finishing_transaction(@txn, Time.at(100)))
139
138
  end
140
139
 
141
- def test_notice_scope_empty_with_builder
140
+ def test_on_finishing_transaction_with_builder
142
141
  builder = mock('builder')
143
142
  @sampler.stubs(:builder).returns(builder)
144
143
 
@@ -154,13 +153,13 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
154
153
  builder.expects(:sample).returns(sample)
155
154
  @sampler.expects(:store_sample).with(sample)
156
155
 
157
- @sampler.notice_transaction(nil, {})
158
- @sampler.notice_scope_empty(@txn, Time.at(100))
156
+ @sampler.on_start_transaction(Time.now, nil, {})
157
+ @sampler.on_finishing_transaction(@txn, Time.at(100))
159
158
 
160
159
  assert_equal(sample, @sampler.instance_variable_get('@last_sample'))
161
160
  end
162
161
 
163
- def test_notice_scope_empty_passes_guid_along
162
+ def test_on_finishing_transaction_passes_guid_along
164
163
  builder = stub_everything('builder')
165
164
  @sampler.stubs(:builder).returns(builder)
166
165
 
@@ -170,8 +169,8 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
170
169
  sample.expects(:guid=).with(@txn.guid)
171
170
  builder.stubs(:sample).returns(sample)
172
171
 
173
- @sampler.notice_transaction(nil, {})
174
- @sampler.notice_scope_empty(@txn, Time.at(100))
172
+ @sampler.on_start_transaction(Time.now, nil, {})
173
+ @sampler.on_finishing_transaction(@txn, Time.at(100))
175
174
  end
176
175
 
177
176
  def test_ignore_transaction_no_builder
@@ -496,20 +495,19 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
496
495
 
497
496
  def test_sample_tree
498
497
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
499
- @sampler.notice_first_scope_push Time.now.to_f
500
- @sampler.notice_transaction(nil, {})
501
- @sampler.notice_push_scope
498
+ @sampler.on_start_transaction(Time.now, nil, {})
499
+ @sampler.notice_push_frame
502
500
 
503
- @sampler.notice_push_scope
504
- @sampler.notice_pop_scope "b"
501
+ @sampler.notice_push_frame
502
+ @sampler.notice_pop_frame "b"
505
503
 
506
- @sampler.notice_push_scope
507
- @sampler.notice_push_scope
508
- @sampler.notice_pop_scope "d"
509
- @sampler.notice_pop_scope "c"
504
+ @sampler.notice_push_frame
505
+ @sampler.notice_push_frame
506
+ @sampler.notice_pop_frame "d"
507
+ @sampler.notice_pop_frame "c"
510
508
 
511
- @sampler.notice_pop_scope "a"
512
- @sampler.notice_scope_empty(@txn)
509
+ @sampler.notice_pop_frame "a"
510
+ @sampler.on_finishing_transaction(@txn)
513
511
  sample = @sampler.harvest!.first
514
512
  assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
515
513
  end
@@ -522,20 +520,19 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
522
520
  MockGCStats.mock_values = [0,0,0,1,0,0,1,0,0,0,0,0,0,0,0]
523
521
 
524
522
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
525
- @sampler.notice_first_scope_push Time.now.to_f
526
- @sampler.notice_transaction(nil, {})
527
- @sampler.notice_push_scope
523
+ @sampler.on_start_transaction(Time.now, nil, {})
524
+ @sampler.notice_push_frame
528
525
 
529
- @sampler.notice_push_scope
530
- @sampler.notice_pop_scope "b"
526
+ @sampler.notice_push_frame
527
+ @sampler.notice_pop_frame "b"
531
528
 
532
- @sampler.notice_push_scope
533
- @sampler.notice_push_scope
534
- @sampler.notice_pop_scope "d"
535
- @sampler.notice_pop_scope "c"
529
+ @sampler.notice_push_frame
530
+ @sampler.notice_push_frame
531
+ @sampler.notice_pop_frame "d"
532
+ @sampler.notice_pop_frame "c"
536
533
 
537
- @sampler.notice_pop_scope "a"
538
- @sampler.notice_scope_empty(@txn)
534
+ @sampler.notice_pop_frame "a"
535
+ @sampler.on_finishing_transaction(@txn)
539
536
 
540
537
  sample = @sampler.harvest!.first
541
538
  assert_equal "ROOT{a{b,c{d}}}", sample.to_s_compact
@@ -577,15 +574,15 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
577
574
  end
578
575
 
579
576
  def test_prepare_to_send
577
+ t0 = freeze_time
580
578
  sample = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
581
- run_sample_trace { sleep 0.002 }
579
+ run_sample_trace { advance_time(2.0) }
582
580
  @sampler.harvest![0]
583
581
  end
584
582
 
585
583
  ready_to_send = sample.prepare_to_send!
586
- assert sample.duration == ready_to_send.duration
587
-
588
- assert ready_to_send.start_time.is_a?(Time)
584
+ assert_equal 2.0, ready_to_send.duration
585
+ assert_equal t0.to_f, ready_to_send.start_time
589
586
  end
590
587
 
591
588
  def test_multithread
@@ -606,22 +603,20 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
606
603
 
607
604
  def test_sample_with_parallel_paths
608
605
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
609
- @sampler.notice_first_scope_push Time.now.to_f
610
- @sampler.notice_transaction(nil, {})
611
- @sampler.notice_push_scope
606
+ @sampler.on_start_transaction(Time.now, nil, {})
607
+ @sampler.notice_push_frame
612
608
 
613
609
  assert_equal 1, @sampler.builder.scope_depth
614
610
 
615
- @sampler.notice_pop_scope "a"
616
- @sampler.notice_scope_empty(@txn)
611
+ @sampler.notice_pop_frame "a"
612
+ @sampler.on_finishing_transaction(@txn)
617
613
 
618
614
  assert_nil @sampler.builder
619
615
 
620
- @sampler.notice_first_scope_push Time.now.to_f
621
- @sampler.notice_transaction(nil, {})
622
- @sampler.notice_push_scope
623
- @sampler.notice_pop_scope "a"
624
- @sampler.notice_scope_empty(@txn)
616
+ @sampler.on_start_transaction(Time.now, nil, {})
617
+ @sampler.notice_push_frame
618
+ @sampler.notice_pop_frame "a"
619
+ @sampler.on_finishing_transaction(@txn)
625
620
 
626
621
  assert_nil @sampler.builder
627
622
 
@@ -629,16 +624,15 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
629
624
  end
630
625
  end
631
626
 
632
- def test_double_scope_stack_empty
627
+ def test_double_traced_method_stack_empty
633
628
  with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
634
- @sampler.notice_first_scope_push Time.now.to_f
635
- @sampler.notice_transaction(nil, {})
636
- @sampler.notice_push_scope
637
- @sampler.notice_pop_scope "a"
638
- @sampler.notice_scope_empty(@txn)
639
- @sampler.notice_scope_empty(@txn)
640
- @sampler.notice_scope_empty(@txn)
641
- @sampler.notice_scope_empty(@txn)
629
+ @sampler.on_start_transaction(Time.now, nil, {})
630
+ @sampler.notice_push_frame
631
+ @sampler.notice_pop_frame "a"
632
+ @sampler.on_finishing_transaction(@txn)
633
+ @sampler.on_finishing_transaction(@txn)
634
+ @sampler.on_finishing_transaction(@txn)
635
+ @sampler.on_finishing_transaction(@txn)
642
636
 
643
637
  refute_nil @sampler.harvest![0]
644
638
  end
@@ -646,7 +640,7 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
646
640
 
647
641
 
648
642
  def test_record_sql_off
649
- @sampler.notice_first_scope_push Time.now.to_f
643
+ @sampler.on_start_transaction Time.now.to_f
650
644
 
651
645
  NewRelic::Agent::TransactionState.get.record_sql = false
652
646
 
@@ -657,9 +651,9 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
657
651
  assert_nil segment[:sql]
658
652
  end
659
653
 
660
- def test_stack_trace__sql
654
+ def test_stack_trace_sql
661
655
  with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
662
- @sampler.notice_first_scope_push Time.now.to_f
656
+ @sampler.on_start_transaction Time.now.to_f
663
657
  @sampler.notice_sql("test", {}, 1)
664
658
  segment = @sampler.send(:builder).current_segment
665
659
 
@@ -668,11 +662,11 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
668
662
  end
669
663
  end
670
664
 
671
- def test_stack_trace__scope
665
+ def test_stack_trace_scope
672
666
  with_config(:'transaction_tracer.stack_trace_threshold' => 0) do
673
667
  t = Time.now
674
- @sampler.notice_first_scope_push t.to_f
675
- @sampler.notice_push_scope((t+1).to_f)
668
+ @sampler.on_start_transaction t.to_f
669
+ @sampler.notice_push_frame((t+1).to_f)
676
670
 
677
671
  segment = @sampler.send(:builder).current_segment
678
672
  assert segment[:backtrace]
@@ -681,7 +675,7 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
681
675
 
682
676
  def test_nil_stacktrace
683
677
  with_config(:'transaction_tracer.stack_trace_threshold' => 2) do
684
- @sampler.notice_first_scope_push Time.now.to_f
678
+ @sampler.on_start_transaction Time.now.to_f
685
679
  @sampler.notice_sql("test", {}, 1)
686
680
  segment = @sampler.send(:builder).current_segment
687
681
 
@@ -691,7 +685,7 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
691
685
  end
692
686
 
693
687
  def test_big_sql
694
- @sampler.notice_first_scope_push Time.now.to_f
688
+ @sampler.on_start_transaction Time.now.to_f
695
689
 
696
690
  sql = "SADJKHASDHASD KAJSDH ASKDH ASKDHASDK JASHD KASJDH ASKDJHSAKDJHAS DKJHSADKJSAH DKJASHD SAKJDH SAKDJHS"
697
691
 
@@ -709,8 +703,8 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
709
703
  end
710
704
 
711
705
  def test_segment_obfuscated
712
- @sampler.notice_first_scope_push Time.now.to_f
713
- @sampler.notice_push_scope
706
+ @sampler.on_start_transaction Time.now.to_f
707
+ @sampler.notice_push_frame
714
708
 
715
709
  orig_sql = "SELECT * from Jim where id=66"
716
710
 
@@ -720,16 +714,15 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
720
714
 
721
715
  assert_equal orig_sql, segment[:sql]
722
716
  assert_equal "SELECT * from Jim where id=?", segment.obfuscated_sql
723
- @sampler.notice_pop_scope "foo"
717
+ @sampler.notice_pop_frame "foo"
724
718
  end
725
719
 
726
720
  def test_param_capture
727
721
  [true, false].each do |capture|
728
722
  with_config(:capture_params => capture) do
729
723
  tt = with_config(:'transaction_tracer.transaction_threshold' => 0.0) do
730
- @sampler.notice_first_scope_push Time.now.to_f
731
- @sampler.notice_transaction(nil, :param => 'hi')
732
- @sampler.notice_scope_empty(@txn)
724
+ @sampler.on_start_transaction(Time.now, nil, :param => 'hi')
725
+ @sampler.on_finishing_transaction(@txn)
733
726
  @sampler.harvest![0]
734
727
  end
735
728
 
@@ -741,12 +734,12 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
741
734
  def test_should_not_collect_segments_beyond_limit
742
735
  with_config(:'transaction_tracer.limit_segments' => 3) do
743
736
  run_sample_trace do
744
- @sampler.notice_push_scope
737
+ @sampler.notice_push_frame
745
738
  @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'challah'", {}, 0)
746
- @sampler.notice_push_scope
739
+ @sampler.notice_push_frame
747
740
  @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'semolina'", {}, 0)
748
- @sampler.notice_pop_scope "a11"
749
- @sampler.notice_pop_scope "a1"
741
+ @sampler.notice_pop_frame "a11"
742
+ @sampler.notice_pop_frame "a1"
750
743
  end
751
744
  assert_equal 3, @sampler.last_sample.count_segments
752
745
 
@@ -759,14 +752,14 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
759
752
 
760
753
  def test_renaming_current_segment_midflight
761
754
  @sampler.start_builder
762
- segment = @sampler.notice_push_scope
755
+ segment = @sampler.notice_push_frame
763
756
  segment.metric_name = 'External/www.google.com/Net::HTTP/GET'
764
- @sampler.notice_pop_scope( 'External/www.google.com/Net::HTTP/GET' )
757
+ @sampler.notice_pop_frame( 'External/www.google.com/Net::HTTP/GET' )
765
758
  end
766
759
 
767
760
  def test_adding_segment_parameters
768
761
  @sampler.start_builder
769
- @sampler.notice_push_scope
762
+ @sampler.notice_push_frame
770
763
  @sampler.add_segment_parameters( :transaction_guid => '97612F92E6194080' )
771
764
  assert_equal '97612F92E6194080', @sampler.builder.current_segment[:transaction_guid]
772
765
  end
@@ -909,29 +902,27 @@ class NewRelic::Agent::TransactionSamplerTest < Minitest::Test
909
902
  end
910
903
 
911
904
  def run_long_sample_trace(n)
912
- @sampler.notice_transaction(nil, {})
913
- @sampler.notice_first_scope_push(Time.now.to_f)
905
+ @sampler.on_start_transaction(Time.now, nil, {})
914
906
  n.times do |i|
915
- @sampler.notice_push_scope
907
+ @sampler.notice_push_frame
916
908
  yield if block_given?
917
- @sampler.notice_pop_scope "node#{i}"
909
+ @sampler.notice_pop_frame "node#{i}"
918
910
  end
919
- @sampler.notice_scope_empty(@txn, Time.now.to_f)
911
+ @sampler.on_finishing_transaction(@txn, Time.now.to_f)
920
912
  end
921
913
 
922
914
  def run_sample_trace(start = Time.now.to_f, stop = nil)
923
- @sampler.notice_transaction(nil, {})
924
- @sampler.notice_first_scope_push start
925
- @sampler.notice_push_scope
915
+ @sampler.on_start_transaction(start, nil, {})
916
+ @sampler.notice_push_frame
926
917
  @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'wheat'", {}, 0)
927
- @sampler.notice_push_scope
918
+ @sampler.notice_push_frame
928
919
  @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'white'", {}, 0)
929
920
  yield if block_given?
930
- @sampler.notice_pop_scope "ab"
931
- @sampler.notice_push_scope
921
+ @sampler.notice_pop_frame "ab"
922
+ @sampler.notice_push_frame
932
923
  @sampler.notice_sql("SELECT * FROM sandwiches WHERE bread = 'french'", {}, 0)
933
- @sampler.notice_pop_scope "ac"
934
- @sampler.notice_pop_scope "a"
935
- @sampler.notice_scope_empty(@txn, (stop || Time.now.to_f))
924
+ @sampler.notice_pop_frame "ac"
925
+ @sampler.notice_pop_frame "a"
926
+ @sampler.on_finishing_transaction(@txn, (stop || Time.now.to_f))
936
927
  end
937
928
  end
@@ -11,38 +11,32 @@ module NewRelic::Agent
11
11
  attr_reader :state
12
12
 
13
13
  def setup
14
- @state = TransactionState.new
14
+ TransactionState.clear
15
+ @state = TransactionState.get
16
+ end
17
+
18
+ def teardown
19
+ TransactionState.clear
15
20
  end
16
21
 
17
22
  def test_without_transaction_stack_on_thread
18
- state.current_transaction_stack = nil
19
23
  assert_equal false, state.in_background_transaction?
20
24
  assert_equal false, state.in_request_transaction?
21
25
  end
22
26
 
23
27
  def test_in_background_transaction
24
- state.current_transaction_stack = [NewRelic::Agent::Transaction.new]
25
-
26
- assert state.in_background_transaction?
28
+ in_transaction(:type => :task) do |txn|
29
+ txn.request = nil # this makes it a "background transaction"
30
+ assert state.in_background_transaction?
31
+ end
27
32
  end
28
33
 
29
34
  def test_in_request_tranasction
30
- transaction = NewRelic::Agent::Transaction.new
31
- transaction.request = stub()
32
-
33
- state.current_transaction_stack = [transaction]
34
-
35
- assert state.in_request_transaction?
36
- end
37
-
38
- def test_in_request_transaction_checks_last
39
- earlier_transaction = NewRelic::Agent::Transaction.new
40
- transaction = NewRelic::Agent::Transaction.new
41
- transaction.request = stub()
35
+ in_transaction do |txn|
36
+ txn.request = stub()
42
37
 
43
- state.current_transaction_stack = [earlier_transaction, transaction]
44
-
45
- assert state.in_request_transaction?
38
+ assert state.in_request_transaction?
39
+ end
46
40
  end
47
41
 
48
42
  def test_timings_without_transaction
@@ -58,24 +52,24 @@ module NewRelic::Agent
58
52
 
59
53
  def test_timings_with_transaction
60
54
  earliest_time = freeze_time
61
- transaction = NewRelic::Agent::Transaction.new
62
- transaction.apdex_start = earliest_time
63
- transaction.start_time = earliest_time + 5
64
- transaction.name = "Transaction/name"
65
- state.transaction = transaction
66
55
 
67
- advance_time(10.0)
68
- timings = state.timings
56
+ in_transaction("Transaction/name") do |txn|
57
+ txn.apdex_start = earliest_time
58
+ txn.start_time = earliest_time + 5
69
59
 
70
- assert_equal 5.0, timings.queue_time_in_seconds
71
- assert_equal 5.0, timings.app_time_in_seconds
72
- assert_equal transaction.name, timings.transaction_name
60
+ advance_time(10.0)
61
+ timings = state.timings
62
+
63
+ assert_equal 5.0, timings.queue_time_in_seconds
64
+ assert_equal 5.0, timings.app_time_in_seconds
65
+ assert_equal txn.best_name, timings.transaction_name
66
+ end
73
67
  end
74
68
 
75
69
  def test_guid_from_transaction
76
- txn = NewRelic::Agent::Transaction.new
77
- state.transaction = txn
78
- assert_equal state.request_guid, txn.guid
70
+ in_transaction do |txn|
71
+ assert_equal state.request_guid, txn.guid
72
+ end
79
73
  end
80
74
 
81
75
  GUID = "goo-id"
@@ -85,11 +79,11 @@ module NewRelic::Agent
85
79
  freeze_time
86
80
 
87
81
  state.request_token = "token"
88
- state.transaction = NewRelic::Agent::Transaction.new
89
82
 
90
- advance_time(4.0)
91
-
92
- assert_equal state.transaction.guid, state.request_guid_to_include
83
+ in_transaction do |txn|
84
+ advance_time(4.0)
85
+ assert_equal state.current_transaction.guid, state.request_guid_to_include
86
+ end
93
87
  end
94
88
  end
95
89
 
@@ -98,11 +92,10 @@ module NewRelic::Agent
98
92
  freeze_time
99
93
 
100
94
  state.request_token = "token"
101
- state.transaction = NewRelic::Agent::Transaction.new
102
-
103
- advance_time(1.0)
104
-
105
- assert_equal "", state.request_guid_to_include
95
+ in_transaction do |txn|
96
+ advance_time(1.0)
97
+ assert_equal "", state.request_guid_to_include
98
+ end
106
99
  end
107
100
  end
108
101
 
@@ -111,11 +104,10 @@ module NewRelic::Agent
111
104
  freeze_time
112
105
 
113
106
  state.request_token = nil
114
- state.transaction = NewRelic::Agent::Transaction.new
115
-
116
- advance_time(4.0)
117
-
118
- assert_equal "", state.request_guid_to_include
107
+ in_transaction do |txn|
108
+ advance_time(4.0)
109
+ assert_equal "", state.request_guid_to_include
110
+ end
119
111
  end
120
112
  end
121
113
 
@@ -123,38 +115,37 @@ module NewRelic::Agent
123
115
  state.request_token = nil
124
116
  state.is_cross_app_caller = false
125
117
  state.referring_transaction_info = nil
126
- state.transaction = NewRelic::Agent::Transaction.new
127
-
128
- assert_nil state.request_guid_for_event
118
+ in_transaction do
119
+ assert_nil state.request_guid_for_event
120
+ end
129
121
  end
130
122
 
131
123
  def test_request_guid_for_event
132
124
  state.request_token = nil
133
125
  state.is_cross_app_caller = true
134
126
  state.referring_transaction_info = nil
135
- state.transaction = NewRelic::Agent::Transaction.new
136
-
137
- assert_equal state.transaction.guid, state.request_guid_for_event
127
+ in_transaction do
128
+ assert_equal state.current_transaction.guid, state.request_guid_for_event
129
+ end
138
130
  end
139
131
 
140
132
  def test_request_guid_for_event_if_referring_transaction
141
133
  state.request_token = nil
142
134
  state.is_cross_app_caller = false
143
135
  state.referring_transaction_info = ["another"]
144
- state.transaction = NewRelic::Agent::Transaction.new
145
-
146
- assert_equal state.transaction.guid, state.request_guid_for_event
136
+ in_transaction do
137
+ assert_equal state.current_transaction.guid, state.request_guid_for_event
138
+ end
147
139
  end
148
140
 
149
141
  def test_request_guid_for_event_if_there_for_rum
150
142
  with_config(:apdex_t => 2.0) do
151
143
  state.request_token = "token"
152
144
  state.is_cross_app_caller = false
153
- state.transaction = NewRelic::Agent::Transaction.new
154
-
155
- advance_time(10.0)
156
-
157
- assert_equal state.transaction.guid, state.request_guid_for_event
145
+ in_transaction do
146
+ advance_time(10.0)
147
+ assert_equal state.current_transaction.guid, state.request_guid_for_event
148
+ end
158
149
  end
159
150
  end
160
151