newrelic_rpm 3.12.0.288 → 3.12.1.298

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +42 -0
  3. data/Rakefile +5 -5
  4. data/lib/new_relic/agent.rb +23 -11
  5. data/lib/new_relic/agent/agent.rb +17 -67
  6. data/lib/new_relic/agent/agent_logger.rb +9 -33
  7. data/lib/new_relic/agent/attribute_processing.rb +2 -2
  8. data/lib/new_relic/agent/autostart.rb +1 -18
  9. data/lib/new_relic/agent/aws_info.rb +90 -0
  10. data/lib/new_relic/agent/configuration/default_source.rb +45 -16
  11. data/lib/new_relic/agent/configuration/dotted_hash.rb +0 -2
  12. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -1
  13. data/lib/new_relic/agent/configuration/manager.rb +1 -31
  14. data/lib/new_relic/agent/configuration/server_source.rb +0 -1
  15. data/lib/new_relic/agent/configuration/yaml_source.rb +26 -7
  16. data/lib/new_relic/agent/database.rb +5 -5
  17. data/lib/new_relic/agent/database/postgres_explain_obfuscator.rb +0 -1
  18. data/lib/new_relic/agent/datastores/metric_helper.rb +15 -3
  19. data/lib/new_relic/agent/error_collector.rb +28 -18
  20. data/lib/new_relic/agent/instrumentation/active_record.rb +8 -2
  21. data/lib/new_relic/agent/instrumentation/active_record_4.rb +1 -0
  22. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +49 -1
  23. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +2 -2
  24. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +9 -0
  25. data/lib/new_relic/agent/instrumentation/grape.rb +1 -1
  26. data/lib/new_relic/agent/instrumentation/resque.rb +8 -20
  27. data/lib/new_relic/agent/instrumentation/sequel.rb +0 -2
  28. data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -0
  29. data/lib/new_relic/agent/log_once.rb +39 -0
  30. data/lib/new_relic/agent/memory_logger.rb +8 -1
  31. data/lib/new_relic/agent/method_tracer.rb +5 -1
  32. data/lib/new_relic/agent/new_relic_service.rb +13 -14
  33. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -0
  34. data/lib/new_relic/agent/samplers/memory_sampler.rb +6 -3
  35. data/lib/new_relic/agent/sql_sampler.rb +4 -15
  36. data/lib/new_relic/agent/stats_engine/metric_stats.rb +1 -1
  37. data/lib/new_relic/agent/stats_engine/samplers.rb +0 -6
  38. data/lib/new_relic/agent/stats_engine/stats_hash.rb +92 -35
  39. data/lib/new_relic/agent/system_info.rb +53 -6
  40. data/lib/new_relic/agent/transaction.rb +4 -13
  41. data/lib/new_relic/agent/transaction/attributes.rb +2 -0
  42. data/lib/new_relic/agent/transaction/trace_node.rb +1 -1
  43. data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -9
  44. data/lib/new_relic/agent/transaction_sample_builder.rb +0 -6
  45. data/lib/new_relic/agent/transaction_sampler.rb +1 -13
  46. data/lib/new_relic/agent/utilization_data.rb +29 -42
  47. data/lib/new_relic/agent/worker_loop.rb +2 -3
  48. data/lib/new_relic/cli/commands/deployments.rb +5 -0
  49. data/lib/new_relic/coerce.rb +1 -1
  50. data/lib/new_relic/collection_helper.rb +0 -2
  51. data/lib/new_relic/control/instance_methods.rb +4 -1
  52. data/lib/new_relic/control/instrumentation.rb +1 -9
  53. data/lib/new_relic/control/server_methods.rb +3 -56
  54. data/lib/new_relic/helper.rb +1 -0
  55. data/lib/new_relic/language_support.rb +21 -0
  56. data/lib/new_relic/local_environment.rb +1 -0
  57. data/lib/new_relic/metric_data.rb +1 -1
  58. data/lib/new_relic/noticed_error.rb +1 -1
  59. data/lib/new_relic/rack/agent_middleware.rb +9 -0
  60. data/lib/new_relic/version.rb +1 -1
  61. data/lib/sequel/extensions/newrelic_instrumentation.rb +2 -2
  62. data/lib/tasks/multiverse.rake +2 -0
  63. data/lib/tasks/multiverse.rb +50 -0
  64. data/test/agent_helper.rb +24 -5
  65. data/test/fixtures/cross_agent_tests/aws.json +218 -0
  66. data/test/fixtures/cross_agent_tests/docker_container_id/cases.json +40 -11
  67. data/test/fixtures/cross_agent_tests/docker_container_id/invalid-characters.txt +9 -0
  68. data/test/fixtures/cross_agent_tests/docker_container_id/invalid-length.txt +9 -0
  69. data/test/multiverse/lib/multiverse/suite.rb +3 -0
  70. data/test/multiverse/suites/active_record/Envfile +18 -12
  71. data/test/multiverse/suites/active_record/active_record_test.rb +203 -9
  72. data/test/multiverse/suites/active_record/app/models/models.rb +16 -9
  73. data/test/multiverse/suites/active_record/config/database.rb +3 -2
  74. data/test/multiverse/suites/active_record/db/migrate/20150413011200_add_timestamps_to_orders.rb +16 -0
  75. data/test/multiverse/suites/active_record/db/migrate/20150414084400_create_groups.rb +21 -0
  76. data/test/multiverse/suites/agent_only/agent_attributes_test.rb +26 -3
  77. data/test/multiverse/suites/agent_only/config/newrelic.yml +1 -1
  78. data/test/multiverse/suites/agent_only/script/public_api_when_disabled.rb +68 -0
  79. data/test/multiverse/suites/agent_only/service_timeout_test.rb +1 -1
  80. data/test/multiverse/suites/agent_only/ssl_test.rb +2 -1
  81. data/test/multiverse/suites/agent_only/start_up_test.rb +20 -1
  82. data/test/multiverse/suites/agent_only/utilization_data_collection_test.rb +43 -104
  83. data/test/multiverse/suites/bare/standalone_instrumentation_test.rb +2 -2
  84. data/test/multiverse/suites/high_security/high_security_test.rb +2 -2
  85. data/test/multiverse/suites/rack/http_response_code_test.rb +4 -4
  86. data/test/multiverse/suites/rails/error_tracing_test.rb +1 -1
  87. data/test/multiverse/suites/sidekiq/sidekiq_instrumentation_test.rb +38 -0
  88. data/test/multiverse/suites/sidekiq/test_worker.rb +13 -1
  89. data/test/new_relic/agent/agent_test.rb +0 -70
  90. data/test/new_relic/agent/attribute_processing_test.rb +10 -5
  91. data/test/new_relic/agent/autostart_test.rb +0 -31
  92. data/test/new_relic/agent/aws_info_test.rb +61 -0
  93. data/test/new_relic/agent/configuration/manager_test.rb +1 -1
  94. data/test/new_relic/agent/configuration/yaml_source_test.rb +25 -1
  95. data/test/new_relic/agent/database_test.rb +16 -15
  96. data/test/new_relic/agent/datastores/metric_helper_test.rb +35 -0
  97. data/test/new_relic/agent/error_collector_test.rb +28 -5
  98. data/test/new_relic/agent/instrumentation/controller_instrumentation_test.rb +23 -20
  99. data/test/new_relic/agent/memory_logger_test.rb +18 -0
  100. data/test/new_relic/agent/new_relic_service_test.rb +2 -9
  101. data/test/new_relic/agent/rpm_agent_test.rb +0 -10
  102. data/test/new_relic/agent/sql_sampler_test.rb +4 -4
  103. data/test/new_relic/agent/stats_engine/stats_hash_test.rb +18 -22
  104. data/test/new_relic/agent/system_info_test.rb +81 -23
  105. data/test/new_relic/agent/transaction_event_aggregator_test.rb +0 -7
  106. data/test/new_relic/agent/transaction_test.rb +1 -1
  107. data/test/new_relic/agent/utilization_data_test.rb +135 -6
  108. data/test/new_relic/cli/commands/deployments_test.rb +12 -2
  109. data/test/new_relic/control/instrumentation_test.rb +0 -15
  110. data/test/new_relic/control_test.rb +0 -63
  111. data/test/new_relic/fake_collector.rb +4 -17
  112. data/test/new_relic/language_support_test.rb +30 -0
  113. data/test/new_relic/license_test.rb +2 -0
  114. data/test/new_relic/multiverse_helpers.rb +12 -0
  115. data/test/performance/suites/stats_hash.rb +6 -5
  116. data/test/test_helper.rb +1 -2
  117. metadata +13 -4
  118. data/lib/new_relic/agent/shim_agent.rb +0 -33
  119. data/test/new_relic/agent/shim_agent_test.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab8bebcd389bae69e6fbac95dd23d18923adc883
4
- data.tar.gz: f8270582f1517c086367167d739444c11a01db90
3
+ metadata.gz: 0798cd154bf943c9a4fc467ef1c36e427b72fa69
4
+ data.tar.gz: cd97b3eeb7c08207ef647fab453450d9c4e012b2
5
5
  SHA512:
6
- metadata.gz: 35f890abc5f586c85bcfe9d94830053574ae40523aec910094725627649caece236d2ecba04b6d1da7dee8270b302eb1fb331520d8e728b73c661cbb1855bde3
7
- data.tar.gz: 6998f741f755f020c6f8c676e0a8de17e92efaf4d6261fdbb2ab73fe66af51de63c28c084c1a43cfbfb18bb998fa1254a6d59d977933156f62e85d0580b8f873
6
+ metadata.gz: 1a28882d587c9633022b7f0192d9a309a084abcf9610a3b3a86e506bcb313068db9583839290c4ca367942c2aba89e8aff42fa045b1dae8384e33195e8d8a1e6
7
+ data.tar.gz: 5055fa5929114caa4fecc07e9e76268dfb7187de30df4551e808254326dfd7e16fbd9a259c03e6c494e30f711d2f63969efb4a895d89700b4021800aed046208
data/CHANGELOG CHANGED
@@ -1,5 +1,47 @@
1
1
  # New Relic Ruby Agent Release Notes #
2
2
 
3
+ ## v3.12.1 ##
4
+
5
+ * More granular Database metrics for ActiveRecord 3 and 4
6
+
7
+ Database metrics recorded for non-SELECT operations (UPDATE, INSERT, DELETE,
8
+ etc.) on ActiveRecord 3 and 4 now include the model name that the query was
9
+ being executed against, allowing you to view these queries broken down by
10
+ model on the Datastores page. Thanks to Bill Kayser for reporting this issue!
11
+
12
+ * Support for Multiverse testing third party gems
13
+
14
+ The Ruby agent has rich support for testing multiple gem versions, but
15
+ previously that wasn't accessible to third party gems. Now you can now
16
+ simply `require 'task/multiverse'` in your Rakefile to access the same
17
+ test:multiverse task that New Relic uses itself. For more details, see:
18
+
19
+ https://docs.newrelic.com/docs/agents/ruby-agent/frameworks/third-party-instrumentation#testing-your-extension
20
+
21
+ * Use Sidekiq 3.x's error handler
22
+
23
+ Sidekiq 3.x+ provides an error handler for internal and middleware related
24
+ failures. Failures at these points were previously unseen by the Ruby agent,
25
+ but now they are properly traced.
26
+
27
+ * Better error messages for common configuration problems with Capistrano
28
+
29
+ Templating errors in newrelic.yml would result in obscure error messages
30
+ during Capistrano deployments. These messages now more properly reflect the
31
+ root cause of the errors.
32
+
33
+ * newrelic_ignore methods allow strings
34
+
35
+ The newrelic_ignore methods previously only supported passing symbols, and
36
+ would quietly ignore any strings passed. Now strings can be passed as well
37
+ to get the intuitive ignoring behavior you'd expect.
38
+
39
+ * Replace DNS resolver for Resque jobs with Resolv
40
+
41
+ In some circumstances customers with a very high number of short-lived Resque
42
+ jobs were experiencing deadlocks during DNS resolution. Resolv is an all Ruby
43
+ DNS resolver that replaces the libc implementation to prevent these deadlocks.
44
+
3
45
  ## v3.12.0 ##
4
46
 
5
47
  * Flexible capturing of attributes
data/Rakefile CHANGED
@@ -22,13 +22,13 @@ namespace :test do
22
22
 
23
23
  agent_home = File.expand_path(File.dirname(__FILE__))
24
24
 
25
- desc "Run functional test suite for newrelic"
26
- task :multiverse, [:suite, :param1, :param2, :param3, :param4] => [] do |t, args|
27
- require File.expand_path(File.join(File.dirname(__FILE__), 'test', 'multiverse', 'lib', 'multiverse', 'environment'))
28
- opts = Multiverse::Runner.parse_args(args)
29
- Multiverse::Runner.run(args.suite, opts)
25
+ # Agent-specific setup to enforce getting our proper suites directory
26
+ task :multiverse_setup do
27
+ ENV["SUITES_DIRECTORY"] = File.expand_path(File.join(File.dirname(__FILE__), 'test', 'multiverse', 'suites'))
30
28
  end
31
29
 
30
+ task :multiverse => :multiverse_setup
31
+
32
32
  desc "Test the multiverse testing framework by executing tests in test/multiverse/test. Get meta with it."
33
33
  task 'multiverse:self', [:suite, :mode] => [] do |t, args|
34
34
  args.with_defaults(:suite => "", :mode => "")
@@ -3,7 +3,6 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require 'forwardable'
6
- require 'new_relic/control'
7
6
 
8
7
  # @api public
9
8
  module NewRelic
@@ -34,12 +33,10 @@ module NewRelic
34
33
  require 'new_relic/noticed_error'
35
34
  require 'new_relic/timer_lib'
36
35
 
37
- require 'new_relic/agent'
38
36
  require 'new_relic/agent/stats'
39
37
  require 'new_relic/agent/chained_call'
40
38
  require 'new_relic/agent/cross_app_monitor'
41
39
  require 'new_relic/agent/agent'
42
- require 'new_relic/agent/shim_agent'
43
40
  require 'new_relic/agent/method_tracer'
44
41
  require 'new_relic/agent/worker_loop'
45
42
  require 'new_relic/agent/event_loop'
@@ -100,6 +97,7 @@ module NewRelic
100
97
  UNKNOWN_METRIC = '(unknown)'.freeze
101
98
 
102
99
  @agent = nil
100
+ @logger = nil
103
101
 
104
102
  # The singleton Agent instance. Used internally.
105
103
  def agent #:nodoc:
@@ -157,6 +155,8 @@ module NewRelic
157
155
  #
158
156
  # @api public
159
157
  def record_metric(metric_name, value) #THREAD_LOCAL_ACCESS
158
+ return unless agent
159
+
160
160
  if value.is_a?(Hash)
161
161
  stats = NewRelic::Agent::Stats.new
162
162
 
@@ -180,6 +180,8 @@ module NewRelic
180
180
  #
181
181
  # @api public
182
182
  def increment_metric(metric_name, amount=1) #THREAD_LOCAL_ACCESS
183
+ return unless agent
184
+
183
185
  agent.stats_engine.tl_record_unscoped_metrics(metric_name) do |stats|
184
186
  stats.increment_count(amount)
185
187
  end
@@ -316,7 +318,7 @@ module NewRelic
316
318
  # @api public
317
319
  #
318
320
  def after_fork(options={})
319
- agent.after_fork(options)
321
+ agent.after_fork(options) if agent
320
322
  end
321
323
 
322
324
  # Shutdown the agent. Call this before exiting. Sends any queued data
@@ -335,7 +337,7 @@ module NewRelic
335
337
  #
336
338
  # @api public
337
339
  def drop_buffered_data
338
- agent.drop_buffered_data
340
+ agent.drop_buffered_data if agent
339
341
  end
340
342
 
341
343
  # Add instrumentation files to the agent. The argument should be
@@ -422,10 +424,14 @@ module NewRelic
422
424
  # @api public
423
425
  #
424
426
  def disable_all_tracing
425
- agent.push_trace_execution_flag(false)
426
- yield
427
- ensure
428
- agent.pop_trace_execution_flag
427
+ return yield unless agent
428
+
429
+ begin
430
+ agent.push_trace_execution_flag(false)
431
+ yield
432
+ ensure
433
+ agent.pop_trace_execution_flag
434
+ end
429
435
  end
430
436
 
431
437
  # This method disables the recording of transaction traces in the given
@@ -434,6 +440,8 @@ module NewRelic
434
440
  # @api public
435
441
  #
436
442
  def disable_transaction_tracing
443
+ return yield unless agent
444
+
437
445
  state = agent.set_record_tt(false)
438
446
  begin
439
447
  yield
@@ -454,6 +462,8 @@ module NewRelic
454
462
  # @api public
455
463
  #
456
464
  def disable_sql_recording
465
+ return yield unless agent
466
+
457
467
  state = agent.set_record_sql(false)
458
468
  begin
459
469
  yield
@@ -557,9 +567,9 @@ module NewRelic
557
567
  # @param [String] method the name of the finder method or other method to
558
568
  # identify the operation with.
559
569
  #
560
- def with_database_metric_name(model, method = nil, &block) #THREAD_LOCAL_ACCESS
570
+ def with_database_metric_name(model, method = nil, product = nil, &block) #THREAD_LOCAL_ACCESS
561
571
  if txn = Transaction.tl_current
562
- txn.with_database_metric_name(model, method, &block)
572
+ txn.with_database_metric_name(model, method, product, &block)
563
573
  else
564
574
  yield
565
575
  end
@@ -596,6 +606,7 @@ module NewRelic
596
606
  # @api public
597
607
  #
598
608
  def browser_timing_header
609
+ return "" unless agent
599
610
  agent.javascript_instrumentor.browser_timing_header
600
611
  end
601
612
 
@@ -665,6 +676,7 @@ module NewRelic
665
676
  # @deprecated
666
677
  #
667
678
  def get_stats(metric_name, use_scope=false)
679
+ return unless agent
668
680
  agent.stats_engine.get_stats(metric_name, use_scope)
669
681
  end
670
682
 
@@ -43,9 +43,10 @@ module NewRelic
43
43
  end
44
44
 
45
45
  def initialize
46
- # FIXME: temporary work around for RUBY-839
47
- # This should be handled with a configuration callback
48
- start_service_if_needed
46
+ @started = false
47
+ @event_loop = nil
48
+
49
+ @service = NewRelicService.new
49
50
 
50
51
  @events = NewRelic::Agent::EventListener.new
51
52
  @stats_engine = NewRelic::Agent::StatsEngine.new
@@ -55,7 +56,6 @@ module NewRelic
55
56
  @cross_app_monitor = NewRelic::Agent::CrossAppMonitor.new(@events)
56
57
  @synthetics_monitor = NewRelic::Agent::SyntheticsMonitor.new(@events)
57
58
  @error_collector = NewRelic::Agent::ErrorCollector.new
58
- @utilization_data = NewRelic::Agent::UtilizationData.new
59
59
  @transaction_rules = NewRelic::Agent::RulesEngine.new
60
60
  @harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events)
61
61
  @monotonic_gc_profiler = NewRelic::Agent::VM::MonotonicGCProfiler.new
@@ -71,7 +71,6 @@ module NewRelic
71
71
  @connect_attempts = 0
72
72
  @environment_report = nil
73
73
 
74
- @harvest_lock = Mutex.new
75
74
  @obfuscator = lambda {|sql| NewRelic::Agent::Database.default_sql_obfuscator(sql) }
76
75
 
77
76
  setup_attribute_filter
@@ -134,7 +133,6 @@ module NewRelic
134
133
  attr_reader :transaction_rules
135
134
  # Responsbile for restarting the harvest thread
136
135
  attr_reader :harvester
137
- attr_reader :harvest_lock
138
136
  # GC::Profiler.total_time is not monotonic so we wrap it.
139
137
  attr_reader :monotonic_gc_profiler
140
138
  attr_reader :custom_event_aggregator
@@ -398,12 +396,6 @@ module NewRelic
398
396
  end
399
397
  end
400
398
 
401
- def start_service_if_needed
402
- if Agent.config[:monitor_mode] && !@service
403
- @service = NewRelic::Agent::NewRelicService.new
404
- end
405
- end
406
-
407
399
  # Classy logging of the agent version and the current pid,
408
400
  # so we can disambiguate processes in the log file and make
409
401
  # sure they're running a reasonable version
@@ -571,7 +563,6 @@ module NewRelic
571
563
  # might be holding locks for background thread that aren't there anymore.
572
564
  def reset_objects_with_locks
573
565
  @stats_engine = NewRelic::Agent::StatsEngine.new
574
- reset_harvest_locks
575
566
  end
576
567
 
577
568
  def flush_pipe_data
@@ -587,24 +578,6 @@ module NewRelic
587
578
  # start_worker_thread method - this is an artifact of
588
579
  # refactoring and can be moved, renamed, etc at will
589
580
  module StartWorkerThread
590
- # Synchronize with the harvest loop. If the harvest thread has taken
591
- # a lock (DNS lookups, backticks, agent-owned locks, etc), and we
592
- # fork while locked, this can deadlock child processes. For more
593
- # details, see https://github.com/resque/resque/issues/1101
594
- def synchronize_with_harvest
595
- harvest_lock.synchronize do
596
- yield
597
- end
598
- end
599
-
600
- # Some forking cases (like Resque) end up with harvest lock from the
601
- # parent process orphaned in the child. Let it go before we proceed.
602
- def reset_harvest_locks
603
- return if harvest_lock.nil?
604
-
605
- harvest_lock.unlock if harvest_lock.locked?
606
- end
607
-
608
581
  def create_event_loop
609
582
  EventLoop.new
610
583
  end
@@ -612,7 +585,6 @@ module NewRelic
612
585
  # Never allow any data type to be reported more frequently than once
613
586
  # per second.
614
587
  MIN_ALLOWED_REPORT_PERIOD = 1.0
615
- UTILIZATION_REPORT_PERIOD = 30 * 60 # every half hour
616
588
 
617
589
  def report_period_for(method)
618
590
  config_key = "data_report_periods.#{method}".to_sym
@@ -645,14 +617,6 @@ module NewRelic
645
617
  @event_loop.fire_every(report_period_for(:analytic_event_data), :report_event_data)
646
618
  @event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD, :reset_log_once_keys)
647
619
 
648
- if Agent.config[:collect_utilization] && !in_resque_child_process?
649
- @event_loop.on(:report_utilization_data) do
650
- transmit_utilization_data
651
- end
652
- @event_loop.fire(:report_utilization_data)
653
- @event_loop.fire_every(UTILIZATION_REPORT_PERIOD, :report_utilization_data)
654
- end
655
-
656
620
  @event_loop.run
657
621
  end
658
622
 
@@ -839,7 +803,8 @@ module NewRelic
839
803
  # server. Returns a literal hash containing the options
840
804
  def connect_settings
841
805
  sanitize_environment_report
842
- {
806
+
807
+ settings = {
843
808
  :pid => $$,
844
809
  :host => local_host,
845
810
  :app_name => Agent.config.app_names,
@@ -850,6 +815,12 @@ module NewRelic
850
815
  :settings => Agent.config.to_collector_hash,
851
816
  :high_security => Agent.config[:high_security]
852
817
  }
818
+
819
+ unless Agent.config[:disable_utilization]
820
+ settings[:utilization] = UtilizationData.new.to_collector_hash
821
+ end
822
+
823
+ settings
853
824
  end
854
825
 
855
826
  # Returns connect data passed back from the server
@@ -878,7 +849,7 @@ module NewRelic
878
849
  def finish_setup(config_data)
879
850
  return if config_data == nil
880
851
 
881
- @service.agent_id = config_data['agent_run_id'] if @service
852
+ @service.agent_id = config_data['agent_run_id']
882
853
 
883
854
  if config_data['agent_config']
884
855
  ::NewRelic::Agent.logger.debug "Using config from server"
@@ -887,7 +858,7 @@ module NewRelic
887
858
  ::NewRelic::Agent.logger.debug "Server provided config: #{config_data.inspect}"
888
859
  server_config = NewRelic::Agent::Configuration::ServerSource.new(config_data, Agent.config)
889
860
  Agent.config.replace_or_add_config(server_config)
890
- log_connection!(config_data) if @service
861
+ log_connection!(config_data)
891
862
 
892
863
  @transaction_rules = RulesEngine.create_transaction_rules(config_data)
893
864
  @stats_engine.metric_rules = RulesEngine.create_metric_rules(config_data)
@@ -1086,10 +1057,6 @@ module NewRelic
1086
1057
  harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
1087
1058
  end
1088
1059
 
1089
- def harvest_and_send_utilization_data
1090
- harvest_and_send_from_container(@utilization_data, :utilization_data)
1091
- end
1092
-
1093
1060
  def check_for_and_handle_agent_commands
1094
1061
  begin
1095
1062
  @agent_command_router.check_for_and_handle_agent_commands
@@ -1108,39 +1075,25 @@ module NewRelic
1108
1075
  NewRelic::Agent.record_metric("Supportability/remote_unavailable/#{endpoint.to_s}", 0.0)
1109
1076
  end
1110
1077
 
1111
- def transmit_data
1112
- harvest_lock.synchronize do
1113
- transmit_data_already_locked
1114
- end
1115
- end
1116
-
1117
1078
  def transmit_event_data
1118
1079
  transmit_single_data_type(:harvest_and_send_analytic_event_data, "TransactionEvent")
1119
1080
  end
1120
1081
 
1121
- def transmit_utilization_data
1122
- transmit_single_data_type(:harvest_and_send_utilization_data, "UtilizationData")
1123
- end
1124
-
1125
1082
  def transmit_single_data_type(harvest_method, supportability_name)
1126
1083
  now = Time.now
1127
1084
 
1128
1085
  msg = "Sending #{harvest_method.to_s.gsub("harvest_and_send_", "")} to New Relic Service"
1129
1086
  ::NewRelic::Agent.logger.debug msg
1130
1087
 
1131
- harvest_lock.synchronize do
1132
- @service.session do # use http keep-alive
1133
- self.send(harvest_method)
1134
- end
1088
+ @service.session do # use http keep-alive
1089
+ self.send(harvest_method)
1135
1090
  end
1136
1091
  ensure
1137
1092
  duration = (Time.now - now).to_f
1138
1093
  NewRelic::Agent.record_metric("Supportability/#{supportability_name}Harvest", duration)
1139
1094
  end
1140
1095
 
1141
- # This method is expected to only be called with the harvest_lock
1142
- # already held
1143
- def transmit_data_already_locked
1096
+ def transmit_data
1144
1097
  now = Time.now
1145
1098
  ::NewRelic::Agent.logger.debug "Sending data to New Relic Service"
1146
1099
 
@@ -1160,8 +1113,6 @@ module NewRelic
1160
1113
  NewRelic::Agent.record_metric('Supportability/Harvest', duration)
1161
1114
  end
1162
1115
 
1163
- private :transmit_data_already_locked
1164
-
1165
1116
  # This method contacts the server to send remaining data and
1166
1117
  # let the server know that the agent is shutting down - this
1167
1118
  # allows us to do things like accurately set the end of the
@@ -1177,7 +1128,6 @@ module NewRelic
1177
1128
  @events.notify(:before_shutdown)
1178
1129
  transmit_data
1179
1130
  transmit_event_data
1180
- transmit_utilization_data if NewRelic::Agent.config[:collect_utilization]
1181
1131
 
1182
1132
  if @connected_pid == $$ && !@service.kind_of?(NewRelic::Agent::NewRelicService)
1183
1133
  ::NewRelic::Agent.logger.debug "Sending New Relic service agent run shutdown message"
@@ -5,10 +5,12 @@
5
5
  require 'thread'
6
6
  require 'logger'
7
7
  require 'new_relic/agent/hostname'
8
+ require 'new_relic/agent/log_once'
8
9
 
9
10
  module NewRelic
10
11
  module Agent
11
12
  class AgentLogger
13
+ include LogOnce
12
14
 
13
15
  def initialize(root = "", override_logger=nil)
14
16
  @already_logged_lock = Mutex.new
@@ -40,30 +42,6 @@ module NewRelic
40
42
  format_and_send(:debug, msgs, &blk)
41
43
  end
42
44
 
43
- NUM_LOG_ONCE_KEYS = 1000
44
-
45
- def log_once(level, key, *msgs)
46
- @already_logged_lock.synchronize do
47
- return if @already_logged.include?(key)
48
-
49
- if @already_logged.size >= NUM_LOG_ONCE_KEYS && key.kind_of?(String)
50
- # The reason for preventing too many keys in `logged` is for
51
- # memory concerns.
52
- # The reason for checking the type of the key is that we always want
53
- # to allow symbols to log, since there are very few of them.
54
- # The assumption here is that you would NEVER pass dynamically-created
55
- # symbols, because you would never create symbols dynamically in the
56
- # first place, as that would already be a memory leak in most Rubies,
57
- # even if we didn't hang on to them all here.
58
- return
59
- end
60
-
61
- @already_logged[key] = true
62
- end
63
-
64
- self.send(level, *msgs)
65
- end
66
-
67
45
  def is_startup_logger?
68
46
  @log.is_a?(NullLogger)
69
47
  end
@@ -84,6 +62,12 @@ module NewRelic
84
62
  end
85
63
  end
86
64
 
65
+ def log_formatter=(formatter)
66
+ @log.formatter = formatter
67
+ end
68
+
69
+ private
70
+
87
71
  def backtrace_from_exception(e)
88
72
  # We've seen that often the backtrace on a SystemStackError is bunk
89
73
  # so massage the caller instead at a known depth.
@@ -110,6 +94,7 @@ module NewRelic
110
94
  else @log.send(level, item)
111
95
  end
112
96
  end
97
+ nil
113
98
  end
114
99
 
115
100
  def create_log(root, override_logger)
@@ -146,12 +131,6 @@ module NewRelic
146
131
  @log = ::NewRelic::Agent::NullLogger.new
147
132
  end
148
133
 
149
- def clear_already_logged
150
- @already_logged_lock.synchronize do
151
- @already_logged = {}
152
- end
153
- end
154
-
155
134
  def wants_stdout?
156
135
  ::NewRelic::Agent.config[:log_file_path].upcase == "STDOUT"
157
136
  end
@@ -194,9 +173,6 @@ module NewRelic
194
173
  StartupLogger.instance.dump(self)
195
174
  end
196
175
 
197
- def log_formatter=(formatter)
198
- @log.formatter = formatter
199
- end
200
176
  end
201
177
 
202
178
  # In an effort to not lose messages during startup, we trap them in memory