newrelic_rpm 3.12.1.298 → 3.13.0.299

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +37 -0
  3. data/GUIDELINES_FOR_CONTRIBUTING.md +1 -1
  4. data/LICENSE +4 -4
  5. data/README.md +3 -3
  6. data/lib/new_relic/agent/agent.rb +27 -0
  7. data/lib/new_relic/agent/commands/thread_profiler_session.rb +2 -0
  8. data/lib/new_relic/agent/configuration/default_source.rb +51 -1
  9. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  10. data/lib/new_relic/agent/database.rb +12 -2
  11. data/lib/new_relic/agent/database/obfuscator.rb +4 -3
  12. data/lib/new_relic/agent/datastores.rb +1 -1
  13. data/lib/new_relic/agent/datastores/redis.rb +131 -0
  14. data/lib/new_relic/agent/error_collector.rb +2 -2
  15. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -0
  16. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -0
  17. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +2 -0
  18. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +2 -0
  19. data/lib/new_relic/agent/instrumentation/rake.rb +170 -0
  20. data/lib/new_relic/agent/instrumentation/redis.rb +71 -0
  21. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -0
  22. data/lib/new_relic/agent/new_relic_service.rb +4 -0
  23. data/lib/new_relic/agent/sql_sampler.rb +14 -13
  24. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -0
  25. data/lib/new_relic/agent/transaction.rb +2 -0
  26. data/lib/new_relic/agent/transaction/attributes.rb +1 -1
  27. data/lib/new_relic/agent/transaction/trace.rb +2 -1
  28. data/lib/new_relic/agent/transaction/trace_node.rb +3 -2
  29. data/lib/new_relic/agent/transaction_sampler.rb +4 -15
  30. data/lib/new_relic/agent/transaction_state.rb +1 -0
  31. data/lib/new_relic/agent/vm/rubinius_vm.rb +27 -19
  32. data/lib/new_relic/language_support.rb +7 -0
  33. data/lib/new_relic/version.rb +2 -2
  34. data/lib/tasks/newrelic.rb +9 -0
  35. data/newrelic_rpm.gemspec +1 -1
  36. data/test/multiverse/README.md +1 -1
  37. data/test/multiverse/lib/multiverse/runner.rb +2 -2
  38. data/test/multiverse/suites/active_record/active_record_test.rb +6 -6
  39. data/test/multiverse/suites/agent_only/agent_attributes_test.rb +11 -0
  40. data/test/multiverse/suites/agent_only/script/warnings.rb +15 -0
  41. data/test/multiverse/suites/agent_only/start_up_test.rb +12 -4
  42. data/test/multiverse/suites/rake/Envfile +37 -0
  43. data/test/multiverse/suites/rake/Rakefile +54 -0
  44. data/test/multiverse/suites/rake/config/newrelic.yml +18 -0
  45. data/test/multiverse/suites/rake/multitask_test.rb +40 -0
  46. data/test/multiverse/suites/rake/rake_test.rb +209 -0
  47. data/test/multiverse/suites/rake/rake_test_helper.rb +66 -0
  48. data/test/multiverse/suites/rake/unsupported_rake_test.rb +19 -0
  49. data/test/multiverse/suites/redis/Envfile +14 -0
  50. data/test/multiverse/suites/redis/config/newrelic.yml +19 -0
  51. data/test/multiverse/suites/redis/redis_instrumentation_test.rb +212 -0
  52. data/test/multiverse/suites/redis/redis_unsupported_version_test.rb +20 -0
  53. data/test/multiverse/suites/resque/resque_marshalling_test.rb +9 -1
  54. data/test/new_relic/agent/agent_test.rb +78 -1
  55. data/test/new_relic/agent/configuration/high_security_source_test.rb +9 -0
  56. data/test/new_relic/agent/database/sql_obfuscation_test.rb +1 -3
  57. data/test/new_relic/agent/datastores/redis_test.rb +128 -0
  58. data/test/new_relic/agent/instrumentation/active_record_subscriber_test.rb +1 -1
  59. data/test/new_relic/agent/sql_sampler_test.rb +64 -52
  60. data/test/new_relic/agent/transaction/trace_node_test.rb +1 -1
  61. data/test/new_relic/agent/transaction/trace_test.rb +1 -1
  62. data/test/new_relic/agent/transaction_sampler_test.rb +9 -11
  63. data/test/new_relic/agent/vm/rubinius_vm_test.rb +1 -1
  64. data/test/new_relic/fake_collector.rb +18 -1
  65. data/test/new_relic/multiverse_helpers.rb +6 -0
  66. data/test/performance/suites/redis.rb +45 -0
  67. data/ui/views/newrelic/_sql_row.rhtml +1 -1
  68. data/ui/views/newrelic/explain_sql.rhtml +1 -1
  69. metadata +21 -5
@@ -37,6 +37,7 @@ module NewRelic
37
37
  @untraced = []
38
38
  @traced_method_stack = TracedMethodStack.new
39
39
  @current_transaction = nil
40
+ @record_tt = nil
40
41
  end
41
42
 
42
43
  # This starts the timer for the transaction.
@@ -41,16 +41,26 @@ module NewRelic
41
41
  snap.major_gc_count = metric(:'gc.immix.count') + 0
42
42
  snap.minor_gc_count = metric(:'gc.young.count') + 0
43
43
 
44
- snap.heap_live = metric(:'memory.large.objects.current') +
45
- metric(:'memory.young.objects.current') +
46
- metric(:'memory.immix.objects.current')
47
-
48
- snap.total_allocated_object =
49
- metric(:'memory.large.objects.total') +
50
- metric(:'memory.young.objects.total') +
51
- metric(:'memory.immix.objects.total')
44
+ if has_metric_totals?
45
+ # Rubinius < 2.5.8 metric names
46
+ snap.heap_live = metric(:'memory.large.objects.current') +
47
+ metric(:'memory.young.objects.current') +
48
+ metric(:'memory.immix.objects.current')
49
+
50
+ snap.total_allocated_object =
51
+ metric(:'memory.large.objects.total') +
52
+ metric(:'memory.young.objects.total') +
53
+ metric(:'memory.immix.objects.total')
54
+
55
+ snap.method_cache_invalidations = metric(:'vm.inline_cache.resets') + 0
56
+ else
57
+ # Rubinius >= 2.5.8 metric names and no total metrics
58
+ snap.heap_live = metric(:'memory.large.objects') +
59
+ metric(:'memory.young.objects') +
60
+ metric(:'memory.immix.objects')
52
61
 
53
- snap.method_cache_invalidations = metric(:'vm.inline_cache.resets') + 0
62
+ snap.method_cache_invalidations = metric(:'machine.inline_cache.resets') + 0
63
+ end
54
64
  end
55
65
 
56
66
  def gather_stats_from_gc_stat(snap)
@@ -81,15 +91,13 @@ module NewRelic
81
91
  Rubinius::Metrics.data[key]
82
92
  end
83
93
 
84
- SUPPORTED_KEYS_GC_RBX_METRICS = [
85
- :gc_runs,
86
- :heap_live,
87
- :major_gc_count,
88
- :minor_gc_count,
89
- :method_cache_invalidations,
90
- :thread_count,
91
- :total_allocated_object
92
- ].freeze
94
+ def has_metric?(key)
95
+ Rubinius::Metrics.data.keys.include? key
96
+ end
97
+
98
+ def has_metric_totals?
99
+ has_metric? :'memory.large.objects.total'
100
+ end
93
101
 
94
102
  def supports?(key)
95
103
  if has_metrics?
@@ -101,7 +109,7 @@ module NewRelic
101
109
  when :heap_live
102
110
  true
103
111
  when :total_allocated_object
104
- true
112
+ has_metric_totals?
105
113
  when :method_cache_invalidations
106
114
  true
107
115
  when :gc_runs
@@ -141,4 +141,11 @@ module NewRelic::LanguageSupport
141
141
  rescue NotImplementedError
142
142
  false
143
143
  end
144
+
145
+ def bundled_gem?(gem_name)
146
+ defined?(Bundler) && Bundler.rubygems.all_specs.map(&:name).include?(gem_name)
147
+ rescue => e
148
+ ::NewRelic::Agent.logger.info("Could not determine if third party #{gem_name} gem is installed", e)
149
+ false
150
+ end
144
151
  end
@@ -11,8 +11,8 @@ module NewRelic
11
11
  end
12
12
 
13
13
  MAJOR = 3
14
- MINOR = 12
15
- TINY = 1
14
+ MINOR = 13
15
+ TINY = 0
16
16
 
17
17
  begin
18
18
  require File.join(File.dirname(__FILE__), 'build')
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+ #
5
+ # If you are looking to instrument rake tasks in a Rails environment, but the
6
+ # task doesn't depend on :environment, this task may be included to ensure that
7
+ # the agent will load.
8
+
9
+ NewRelic::Agent.manual_start(:sync_startup => false)
data/newrelic_rpm.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.version = NewRelic::VERSION::STRING
11
11
  s.required_ruby_version = '>= 1.8.7'
12
12
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
13
- s.authors = [ "Jason Clark", "Tim Krajcar", "Jonan Scheffler", "Matthew Wear", "Ben Weintraub" ]
13
+ s.authors = [ "Tim Krajcar", "Matthew Wear", "Katherine Wu" ]
14
14
  s.date = Time.now.strftime('%Y-%m-%d')
15
15
  s.licenses = ['New Relic', 'MIT', 'Ruby']
16
16
  s.description = <<-EOS
@@ -4,7 +4,7 @@
4
4
 
5
5
  Multiverse was created to solve a specific problem experienced by the Agent
6
6
  team. Not only does the New Relic Agent run in a wide variety of environments,
7
- but its expected behavior *changes* based on the environment. Instrumenation is
7
+ but its expected behavior *changes* based on the environment. Instrumentation is
8
8
  toggled on and off based on the presence of certain libraries, and some of these
9
9
  libraries are incompatible with each other. Effective testing requires us to
10
10
  specify different environments for different tests; Multiverse aims to make this
@@ -85,8 +85,8 @@ module Multiverse
85
85
  "agent" => ["agent_only", "bare", "config_file_loading",
86
86
  "deferred_instrumentation", "high_security"],
87
87
  "api" => ["grape"],
88
- "background" => ["delayed_job", "resque", "sidekiq"],
89
- "database" => ["datamapper", "mongo", "sequel"],
88
+ "background" => ["delayed_job", "rake", "resque", "sidekiq"],
89
+ "database" => ["datamapper", "mongo", "redis", "sequel"],
90
90
  "httpclients" => ["curb", "excon", "httpclient", "typhoeus", "net_http"],
91
91
  "rails" => ["active_record", "rails"],
92
92
  "serialization" => ["json", "marshalling", "yajl"],
@@ -405,12 +405,12 @@ class ActiveRecordInstrumentationTest < Minitest::Test
405
405
  node = find_node_with_name(sample, metric)
406
406
  assert_equal(metric, node.metric_name)
407
407
 
408
- sql = node.params[:sql]
409
- assert_match(/^SELECT /, sql)
408
+ statement = node.params[:sql]
409
+ assert_match(/^SELECT /, statement.sql)
410
410
 
411
- assert_equal(adapter.to_s, sql.adapter)
412
- refute_nil(sql.config)
413
- refute_nil(sql.explainer)
411
+ assert_equal(adapter.to_s, statement.adapter)
412
+ refute_nil(statement.config)
413
+ refute_nil(statement.explainer)
414
414
  end
415
415
 
416
416
  def test_gathers_explain_plans
@@ -423,7 +423,7 @@ class ActiveRecordInstrumentationTest < Minitest::Test
423
423
  metric = "Datastore/statement/#{current_product}/Order/find"
424
424
  sql_node = find_node_with_name(sample, metric)
425
425
 
426
- assert_match(/^SELECT /, sql_node.params[:sql])
426
+ assert_match(/^SELECT /, sql_node.params[:sql].sql)
427
427
 
428
428
  sample.prepare_to_send!
429
429
  explanations = sql_node.params[:explain_plan]
@@ -77,6 +77,17 @@ class AgentAttributesTest < Minitest::Test
77
77
  refute_browser_monitoring_has_custom_attributes('foo')
78
78
  end
79
79
 
80
+ def test_falses_included
81
+ run_transaction do
82
+ NewRelic::Agent.add_custom_attributes(:foo => false)
83
+ end
84
+
85
+ assert_transaction_tracer_has_custom_attributes('foo', false)
86
+ assert_transaction_event_has_custom_attributes('foo', false)
87
+ assert_error_collector_has_custom_attributes('foo', false)
88
+ assert_browser_monitoring_has_custom_attributes('foo', false)
89
+ end
90
+
80
91
  def test_custom_attributes_excluded
81
92
  config = {
82
93
  :'transaction_tracer.attributes.enabled' => false,
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # This file is distributed under New Relic's license terms.
4
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
5
+ require 'bundler/setup'
6
+ require 'newrelic_rpm'
7
+
8
+ NewRelic::Agent::Transaction.wrap(NewRelic::Agent::TransactionState.tl_get, 'ponies', :controller) do
9
+ end
10
+
11
+ NewRelic::Agent.notice_error 'oops'
12
+
13
+ NewRelic::Agent.instance.send(:transmit_data)
14
+
15
+ puts NewRelic::VERSION::STRING
@@ -8,6 +8,10 @@ require 'open3'
8
8
  class StartUpTest < Minitest::Test
9
9
  GIT_NOISE = "fatal: Not a git repository (or any of the parent directories): .git\n"
10
10
 
11
+ include MultiverseHelpers
12
+
13
+ setup_and_teardown_agent
14
+
11
15
  def test_should_not_print_to_stdout_when_logging_available
12
16
  ruby = 'require "newrelic_rpm"; NewRelic::Agent.manual_start; NewRelic::Agent.shutdown'
13
17
  cmd = "bundle exec ruby -e '#{ruby}'"
@@ -56,11 +60,15 @@ class StartUpTest < Minitest::Test
56
60
  # going forward from Ruby 2.1.
57
61
  if RUBY_VERSION >= "2.1"
58
62
  def test_no_warnings
59
- output = `bundle exec ruby -w -r bundler/setup -r newrelic_rpm -e 'puts NewRelic::VERSION::STRING' 2>&1`
60
- output.gsub!(GIT_NOISE, "")
61
- output.chomp!
63
+ with_environment('NEW_RELIC_TRANSACTION_TRACER_TRANSACTION_THRESHOLD' => '-10',
64
+ 'NEW_RELIC_PORT' => $collector.port.to_s) do
65
+
66
+ output = `bundle exec ruby -w script/warnings.rb 2>&1`
67
+ output.gsub!(GIT_NOISE, "")
68
+ output.chomp!
62
69
 
63
- assert_equal NewRelic::VERSION::STRING, output
70
+ assert_equal NewRelic::VERSION::STRING, output
71
+ end
64
72
  end
65
73
  end
66
74
 
@@ -0,0 +1,37 @@
1
+ gemfile <<-RB
2
+ gem 'rack'
3
+ gem 'rake', '~> 10.4'
4
+ RB
5
+
6
+ # No single Rails version works everywhere, so split it up
7
+ if RUBY_VERSION >= "1.9.3"
8
+ gemfile <<-RB
9
+ gem 'rack'
10
+ gem 'rake', '~> 10.4'
11
+ gem 'rails', '~> 4.2.1'
12
+ gem 'minitest', '5.2.3'
13
+ RB
14
+ else
15
+ gemfile <<-RB
16
+ gem 'rack'
17
+ gem 'rake', '~> 10.4'
18
+ gem 'rails', '~> 3.2.21'
19
+ gem 'i18n', '~>0.6.11'
20
+ RB
21
+ end
22
+
23
+ gemfile <<-RB
24
+ gem 'rack'
25
+ gem 'rake', '10.0.0' # Oldest supported version
26
+ RB
27
+
28
+ gemfile <<-RB
29
+ gem 'rack'
30
+ gem 'rake', '0.9.6' # Newest unsupported version
31
+ RB
32
+
33
+ gemfile <<-RB
34
+ gem 'rack'
35
+ gem 'rake', '~> 10.4'
36
+ gem 'newrelic-rake' # Can't coexist with third-party instrumentation
37
+ RB
@@ -0,0 +1,54 @@
1
+ Bundler.require
2
+ require "tasks/newrelic"
3
+
4
+ task :default => [:before, :during, :after] do
5
+ puts "default"
6
+ end
7
+
8
+ task :before do
9
+ puts "before"
10
+ end
11
+
12
+ task :during do
13
+ puts "during"
14
+ end
15
+
16
+ task :after do
17
+ puts "after"
18
+ end
19
+
20
+ task :untraced do
21
+ puts "untraced"
22
+ end
23
+
24
+ task :argument, [:who, :where] => [] do
25
+ puts "argument"
26
+ end
27
+
28
+ task :boom do
29
+ raise "a legitimate issue with the proposal."
30
+ end
31
+
32
+ task :tree => [:branch1, :branch2]
33
+ task :branch1 => [:branch1a, :branch1b]
34
+ task :branch2 => [:branch2a, :branch2b]
35
+ task :branch1a
36
+ task :branch1b
37
+ task :branch2a
38
+ task :branch2b
39
+
40
+ namespace :named do
41
+ task :all => [:'named:before', :'named:during', :'named:after']
42
+
43
+ task :before do
44
+ puts "named:before"
45
+ end
46
+
47
+ task :during do
48
+ puts "named:during"
49
+ end
50
+
51
+ task :after do
52
+ puts "named:after"
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ ---
2
+ development:
3
+ attributes:
4
+ include:
5
+ - "*"
6
+ rake:
7
+ tasks:
8
+ - "default"
9
+ ssl: false
10
+ monitor_mode: true
11
+ license_key: bootstrap_newrelic_admin_license_key_000
12
+ developer_mode: false
13
+ app_name: test
14
+ host: 127.0.0.1
15
+ port: <%= $collector ||= nil; $collector && $collector.port %>
16
+ transaction_tracer:
17
+ transaction_threshold: -10
18
+ enabled: true
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(__FILE__, '..', 'rake_test_helper'))
6
+
7
+ if ::NewRelic::Agent::Instrumentation::RakeInstrumentation.should_install?
8
+ class MultiTaskTest < Minitest::Test
9
+ include MultiverseHelpers
10
+ include RakeTestHelper
11
+
12
+ setup_and_teardown_agent
13
+
14
+ def test_generate_scoped_metrics_for_children_if_always_multitask_set
15
+ with_tasks_traced("named:all") do
16
+ run_rake("named:all --multitask")
17
+
18
+ assert_metric_names_posted "OtherTransaction/Rake/invoke/named:all",
19
+ "OtherTransaction/Rake/all",
20
+ "OtherTransaction/all",
21
+ "Rake/execute/multitask"
22
+
23
+ refute_metric_names_posted "Rake/execute/named:before",
24
+ "Rake/execute/named:during",
25
+ "Rake/execute/named:after"
26
+ end
27
+ end
28
+
29
+ def test_generate_transaction_trace_with_placeholder_node
30
+ with_tasks_traced("named:all") do
31
+ run_rake("named:all --multitask")
32
+
33
+ expected = [{},
34
+ [{},
35
+ [{"statement"=>"Couldn't trace concurrent prereq tasks: named:before, named:during, named:after"}]]]
36
+ assert_equal expected, single_transaction_trace_posted.tree.node_params
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,209 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require File.expand_path(File.join(__FILE__, '..', 'rake_test_helper'))
6
+
7
+ if ::NewRelic::Agent::Instrumentation::RakeInstrumentation.should_install? &&
8
+ class RakeTest < Minitest::Test
9
+ include MultiverseHelpers
10
+ include RakeTestHelper
11
+
12
+ setup_and_teardown_agent
13
+
14
+ def test_disabling_rake_instrumentation
15
+ with_environment("NEW_RELIC_DISABLE_RAKE" => "true") do
16
+ run_rake
17
+ end
18
+
19
+ refute_any_rake_metrics
20
+ end
21
+
22
+ def test_doesnt_trace_by_default
23
+ run_rake("untraced")
24
+ refute_any_rake_metrics
25
+ end
26
+
27
+ def test_doesnt_trace_with_an_empty_list
28
+ with_tasks_traced("") do
29
+ run_rake
30
+ refute_any_rake_metrics
31
+ end
32
+ end
33
+
34
+ def test_timeout_on_connect
35
+ $collector.stub_wait('connect', 5)
36
+
37
+ with_environment("NEW_RELIC_RAKE_CONNECT_TIMEOUT" => "0",
38
+ "NEW_RELIC_LOG" => "stdout") do
39
+ run_rake
40
+ end
41
+
42
+ refute_any_rake_metrics
43
+ assert_includes @output, "ERROR : NewRelic::Agent::Agent::InstanceMethods::Connect::WaitOnConnectTimeout: Agent was unable to connect"
44
+ end
45
+
46
+ def test_records_transaction_metrics
47
+ run_rake
48
+
49
+ assert_metric_names_posted "OtherTransaction/Rake/invoke/default",
50
+ "OtherTransaction/Rake/all",
51
+ "OtherTransaction/all",
52
+ "Rake/execute/before",
53
+ "Rake/execute/during",
54
+ "Rake/execute/after"
55
+ end
56
+
57
+ def test_records_transaction_trace
58
+ run_rake
59
+
60
+ trace = single_transaction_trace_posted
61
+ assert_equal "OtherTransaction/Rake/invoke/default", trace.metric_name
62
+
63
+ expected = ["ROOT",
64
+ ["OtherTransaction/Rake/invoke/default",
65
+ ["Rake/execute/before"],
66
+ ["Rake/execute/during"],
67
+ ["Rake/execute/after"]]]
68
+
69
+ assert_equal expected, trace.tree.nodes
70
+ end
71
+
72
+ def test_records_transaction_events
73
+ run_rake
74
+
75
+ event = single_event_posted[0]
76
+ assert_equal "OtherTransaction/Rake/invoke/default", event["name"]
77
+ end
78
+
79
+ def test_records_namespaced_tasks
80
+ with_tasks_traced("named:all") do
81
+ run_rake("named:all")
82
+
83
+ assert_metric_names_posted "OtherTransaction/Rake/invoke/named:all",
84
+ "OtherTransaction/Rake/all",
85
+ "OtherTransaction/all",
86
+ "Rake/execute/named:before",
87
+ "Rake/execute/named:during",
88
+ "Rake/execute/named:after"
89
+ end
90
+ end
91
+
92
+ def test_matches_tasks_by_regex
93
+ with_tasks_traced(".*before") do
94
+ run_rake("before named:before during")
95
+
96
+ assert_metric_names_posted "OtherTransaction/Rake/invoke/before",
97
+ "OtherTransaction/Rake/invoke/named:before"
98
+
99
+ refute_metric_names_posted "OtherTransaction/Rake/invoke/during"
100
+ end
101
+ end
102
+
103
+ def test_records_tree_of_prereqs
104
+ with_tasks_traced("tree") do
105
+ run_rake("tree")
106
+
107
+ assert_metric_names_posted "OtherTransaction/Rake/invoke/tree",
108
+ "OtherTransaction/Rake/all",
109
+ "OtherTransaction/all",
110
+ "Rake/execute/branch1",
111
+ "Rake/execute/branch1a",
112
+ "Rake/execute/branch1b",
113
+ "Rake/execute/branch2",
114
+ "Rake/execute/branch2a",
115
+ "Rake/execute/branch2b"
116
+ end
117
+ end
118
+
119
+ def test_traced_task_as_prereq_doesnt_get_transaction
120
+ with_tasks_traced("default", "before") do
121
+ run_rake
122
+
123
+ assert_metric_names_posted "OtherTransaction/Rake/invoke/default",
124
+ "OtherTransaction/Rake/all",
125
+ "OtherTransaction/all",
126
+ "Rake/execute/before",
127
+ "Rake/execute/during",
128
+ "Rake/execute/after"
129
+
130
+ refute_metric_names_posted "OtherTransaction/Rake/invoke/before"
131
+ end
132
+ end
133
+
134
+ def test_error_during_task
135
+ with_tasks_traced("boom") do
136
+ run_rake("boom", true)
137
+
138
+ expected = "OtherTransaction/Rake/invoke/boom"
139
+ assert_equal expected, single_error_posted.path
140
+ end
141
+ end
142
+
143
+ def test_captures_task_arguments
144
+ with_tasks_traced("argument") do
145
+ run_rake("argument[someone,somewhere,vigorously]")
146
+
147
+ attributes = single_transaction_trace_posted.agent_attributes
148
+ assert_equal "someone", attributes["job.rake.args.who"]
149
+ assert_equal "somewhere", attributes["job.rake.args.where"]
150
+ assert_equal "vigorously", attributes["job.rake.args.2"]
151
+ end
152
+ end
153
+
154
+ def test_captures_task_arguments_with_too_few
155
+ with_tasks_traced("argument") do
156
+ run_rake("argument[someone]")
157
+
158
+ attributes = single_transaction_trace_posted.agent_attributes
159
+ assert_equal "someone", attributes["job.rake.args.who"]
160
+
161
+ refute_includes attributes, "job.rake.args.where"
162
+ refute_includes attributes, "job.rake.args.2"
163
+ end
164
+ end
165
+
166
+ def test_doesnt_capture_task_arguments_if_disabled_by_agent_attributes
167
+ with_tasks_traced("argument") do
168
+ without_attributes do
169
+ run_rake("argument[someone,somewhere,vigorously]")
170
+
171
+ attributes = single_transaction_trace_posted.agent_attributes
172
+ refute_includes attributes, "job.rake.args.who"
173
+ refute_includes attributes, "job.rake.args.where"
174
+ refute_includes attributes, "job.rake.args.2"
175
+ end
176
+ end
177
+ end
178
+
179
+ def test_doesnt_capture_completely_empty_args
180
+ with_tasks_traced("default") do
181
+ run_rake("default")
182
+
183
+ attributes = single_transaction_trace_posted.agent_attributes
184
+ refute attributes.keys.any? { |key| key.start_with?("job.rake.args") }
185
+ end
186
+ end
187
+
188
+ def test_captures_command_line
189
+ with_tasks_traced("default", "argument") do
190
+ run_rake("argument[someone] default")
191
+
192
+ attributes = single_transaction_trace_posted.agent_attributes
193
+ assert_includes attributes["job.rake.command"], "argument[someone]"
194
+ assert_includes attributes["job.rake.command"], "default"
195
+ end
196
+ end
197
+
198
+ def test_doesnt_capture_command_line_if_disabled_by_agent_attributes
199
+ with_tasks_traced("default", "argument") do
200
+ without_attributes do
201
+ run_rake("argument[someone] default")
202
+
203
+ attributes = single_transaction_trace_posted.agent_attributes
204
+ refute_includes attributes, "job.rake.command"
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end