newrelic_rpm 6.6.0.358 → 6.11.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of newrelic_rpm might be problematic. Click here for more details.

Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +65 -5
  4. data/CHANGELOG.md +222 -0
  5. data/Gemfile +5 -2
  6. data/Guardfile +18 -1
  7. data/LICENSE +1 -1
  8. data/Rakefile +2 -0
  9. data/lib/new_relic/agent.rb +89 -7
  10. data/lib/new_relic/agent/agent.rb +114 -55
  11. data/lib/new_relic/agent/agent_logger.rb +4 -0
  12. data/lib/new_relic/agent/attribute_filter.rb +7 -7
  13. data/lib/new_relic/agent/attributes.rb +150 -0
  14. data/lib/new_relic/agent/autostart.rb +19 -14
  15. data/lib/new_relic/agent/configuration/default_source.rb +127 -9
  16. data/lib/new_relic/agent/configuration/event_harvest_config.rb +11 -5
  17. data/lib/new_relic/agent/configuration/manager.rb +0 -8
  18. data/lib/new_relic/agent/configuration/server_source.rb +3 -2
  19. data/lib/new_relic/agent/configuration/yaml_source.rb +11 -6
  20. data/lib/new_relic/agent/connect/request_builder.rb +5 -13
  21. data/lib/new_relic/agent/database.rb +1 -2
  22. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  23. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -2
  24. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +8 -8
  25. data/lib/new_relic/agent/distributed_tracing.rb +155 -6
  26. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +0 -0
  27. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +60 -45
  28. data/lib/new_relic/agent/distributed_tracing/distributed_trace_intrinsics.rb +80 -0
  29. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  30. data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +23 -99
  31. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  32. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  33. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
  34. data/lib/new_relic/agent/error_collector.rb +33 -16
  35. data/lib/new_relic/agent/error_event_aggregator.rb +7 -5
  36. data/lib/new_relic/agent/external.rb +7 -7
  37. data/lib/new_relic/agent/guid_generator.rb +28 -0
  38. data/lib/new_relic/agent/hostname.rb +7 -1
  39. data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
  40. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +24 -19
  41. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +28 -13
  42. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +17 -21
  43. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +10 -11
  44. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +16 -4
  45. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -6
  46. data/lib/new_relic/agent/http_clients/uri_util.rb +3 -2
  47. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +5 -7
  48. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -0
  49. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +11 -2
  50. data/lib/new_relic/agent/instrumentation/active_record.rb +4 -2
  51. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +7 -2
  52. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +8 -4
  53. data/lib/new_relic/agent/instrumentation/bunny.rb +45 -28
  54. data/lib/new_relic/agent/instrumentation/curb.rb +59 -18
  55. data/lib/new_relic/agent/instrumentation/data_mapper.rb +3 -1
  56. data/lib/new_relic/agent/instrumentation/excon.rb +1 -1
  57. data/lib/new_relic/agent/instrumentation/excon/connection.rb +6 -3
  58. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -1
  59. data/lib/new_relic/agent/instrumentation/grape.rb +5 -10
  60. data/lib/new_relic/agent/instrumentation/http.rb +6 -3
  61. data/lib/new_relic/agent/instrumentation/httpclient.rb +5 -3
  62. data/lib/new_relic/agent/instrumentation/memcache.rb +3 -1
  63. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +6 -2
  64. data/lib/new_relic/agent/instrumentation/mongo.rb +9 -3
  65. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +13 -0
  66. data/lib/new_relic/agent/instrumentation/net.rb +6 -3
  67. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +25 -1
  68. data/lib/new_relic/agent/instrumentation/redis.rb +9 -3
  69. data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
  70. data/lib/new_relic/agent/instrumentation/sidekiq.rb +0 -1
  71. data/lib/new_relic/agent/instrumentation/typhoeus.rb +23 -6
  72. data/lib/new_relic/agent/logging.rb +139 -0
  73. data/lib/new_relic/agent/messaging.rb +5 -73
  74. data/lib/new_relic/agent/method_tracer.rb +3 -2
  75. data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
  76. data/lib/new_relic/agent/monitors.rb +27 -0
  77. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  78. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  79. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +1 -1
  80. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
  81. data/lib/new_relic/agent/new_relic_service.rb +7 -5
  82. data/lib/new_relic/agent/noticible_error.rb +22 -0
  83. data/lib/new_relic/agent/span_event_aggregator.rb +1 -0
  84. data/lib/new_relic/agent/span_event_primitive.rb +82 -53
  85. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  86. data/lib/new_relic/agent/supported_versions.rb +2 -2
  87. data/lib/new_relic/agent/tracer.rb +65 -18
  88. data/lib/new_relic/agent/transaction.rb +84 -79
  89. data/lib/new_relic/agent/transaction/abstract_segment.rb +28 -2
  90. data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
  91. data/lib/new_relic/agent/transaction/distributed_tracing.rb +57 -146
  92. data/lib/new_relic/agent/transaction/external_request_segment.rb +29 -36
  93. data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -11
  94. data/lib/new_relic/agent/transaction/segment.rb +7 -1
  95. data/lib/new_relic/agent/transaction/trace.rb +2 -4
  96. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  97. data/lib/new_relic/agent/transaction/trace_node.rb +10 -8
  98. data/lib/new_relic/agent/transaction_error_primitive.rb +10 -15
  99. data/lib/new_relic/agent/transaction_event_primitive.rb +28 -39
  100. data/lib/new_relic/cli/commands/deployments.rb +1 -1
  101. data/lib/new_relic/cli/commands/install.rb +3 -2
  102. data/lib/new_relic/coerce.rb +31 -6
  103. data/lib/new_relic/constants.rb +34 -0
  104. data/lib/new_relic/control/instance_methods.rb +10 -1
  105. data/lib/new_relic/dependency_detection.rb +4 -4
  106. data/lib/new_relic/noticed_error.rb +38 -17
  107. data/lib/new_relic/rack/browser_monitoring.rb +5 -0
  108. data/lib/new_relic/supportability_helper.rb +14 -0
  109. data/lib/new_relic/version.rb +1 -1
  110. data/lib/tasks/multiverse.rb +25 -0
  111. data/lib/tasks/tests.rake +6 -1
  112. data/newrelic_rpm.gemspec +18 -7
  113. data/test/agent_helper.rb +322 -70
  114. metadata +98 -32
  115. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  116. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
  117. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  118. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  119. data/lib/tasks/versions.html.erb +0 -28
  120. data/lib/tasks/versions.postface.html +0 -8
  121. data/lib/tasks/versions.preface.html +0 -9
  122. data/lib/tasks/versions.rake +0 -65
  123. data/lib/tasks/versions.txt.erb +0 -14
@@ -8,6 +8,8 @@ require 'net/http'
8
8
  require 'logger'
9
9
  require 'zlib'
10
10
  require 'stringio'
11
+ require 'new_relic/constants'
12
+ require 'new_relic/coerce'
11
13
  require 'new_relic/agent/autostart'
12
14
  require 'new_relic/agent/harvester'
13
15
  require 'new_relic/agent/hostname'
@@ -17,9 +19,8 @@ require 'new_relic/agent/configuration/manager'
17
19
  require 'new_relic/agent/database'
18
20
  require 'new_relic/agent/commands/agent_command_router'
19
21
  require 'new_relic/agent/event_listener'
20
- require 'new_relic/agent/cross_app_monitor'
21
- require 'new_relic/agent/distributed_trace_monitor'
22
- require 'new_relic/agent/synthetics_monitor'
22
+ require 'new_relic/agent/distributed_tracing'
23
+ require 'new_relic/agent/monitors'
23
24
  require 'new_relic/agent/transaction_event_recorder'
24
25
  require 'new_relic/agent/custom_event_aggregator'
25
26
  require 'new_relic/agent/span_event_aggregator'
@@ -48,31 +49,30 @@ module NewRelic
48
49
  def initialize
49
50
  @started = false
50
51
  @event_loop = nil
52
+ @worker_thread = nil
51
53
 
52
54
  @service = NewRelicService.new
53
55
 
54
- @events = NewRelic::Agent::EventListener.new
55
- @stats_engine = NewRelic::Agent::StatsEngine.new
56
- @transaction_sampler = NewRelic::Agent::TransactionSampler.new
57
- @sql_sampler = NewRelic::Agent::SqlSampler.new
58
- @agent_command_router = NewRelic::Agent::Commands::AgentCommandRouter.new(@events)
59
- @cross_app_monitor = NewRelic::Agent::CrossAppMonitor.new(@events)
60
- @distributed_trace_monitor = NewRelic::Agent::DistributedTraceMonitor.new(@events)
61
- @synthetics_monitor = NewRelic::Agent::SyntheticsMonitor.new(@events)
62
- @error_collector = NewRelic::Agent::ErrorCollector.new @events
63
- @transaction_rules = NewRelic::Agent::RulesEngine.new
64
- @harvest_samplers = NewRelic::Agent::SamplerCollection.new(@events)
65
- @monotonic_gc_profiler = NewRelic::Agent::VM::MonotonicGCProfiler.new
66
- @javascript_instrumentor = NewRelic::Agent::JavascriptInstrumentor.new(@events)
67
- @adaptive_sampler = NewRelic::Agent::AdaptiveSampler.new(self.class.config[:sampling_target],
68
- self.class.config[:sampling_target_period_in_seconds])
69
-
70
- @harvester = NewRelic::Agent::Harvester.new(@events)
56
+ @events = EventListener.new
57
+ @stats_engine = StatsEngine.new
58
+ @transaction_sampler = TransactionSampler.new
59
+ @sql_sampler = SqlSampler.new
60
+ @agent_command_router = Commands::AgentCommandRouter.new @events
61
+ @monitors = Monitors.new @events
62
+ @error_collector = ErrorCollector.new @events
63
+ @transaction_rules = RulesEngine.new
64
+ @harvest_samplers = SamplerCollection.new @events
65
+ @monotonic_gc_profiler = VM::MonotonicGCProfiler.new
66
+ @javascript_instrumentor = JavascriptInstrumentor.new @events
67
+ @adaptive_sampler = AdaptiveSampler.new(Agent.config[:sampling_target],
68
+ Agent.config[:sampling_target_period_in_seconds])
69
+
70
+ @harvester = Harvester.new @events
71
71
  @after_fork_lock = Mutex.new
72
72
 
73
- @transaction_event_recorder = NewRelic::Agent::TransactionEventRecorder.new @events
74
- @custom_event_aggregator = NewRelic::Agent::CustomEventAggregator.new @events
75
- @span_event_aggregator = NewRelic::Agent::SpanEventAggregator.new @events
73
+ @transaction_event_recorder = TransactionEventRecorder.new @events
74
+ @custom_event_aggregator = CustomEventAggregator.new @events
75
+ @span_event_aggregator = SpanEventAggregator.new @events
76
76
 
77
77
  @connect_state = :pending
78
78
  @connect_attempts = 0
@@ -94,7 +94,7 @@ module NewRelic
94
94
  end
95
95
 
96
96
  def refresh_attribute_filter
97
- @attribute_filter = NewRelic::Agent::AttributeFilter.new(NewRelic::Agent.config)
97
+ @attribute_filter = AttributeFilter.new(Agent.config)
98
98
  end
99
99
 
100
100
  # contains all the class-level methods for NewRelic::Agent::Agent
@@ -127,13 +127,16 @@ module NewRelic
127
127
  # cross application tracing ids and encoding
128
128
  attr_reader :cross_process_id
129
129
  attr_reader :cross_app_encoding_bytes
130
- attr_reader :cross_app_monitor
131
130
  # service for communicating with collector
132
131
  attr_accessor :service
133
132
  # Global events dispatcher. This will provides our primary mechanism
134
133
  # for agent-wide events, such as finishing configuration, error notification
135
134
  # and request before/after from Rack.
136
135
  attr_reader :events
136
+
137
+ # listens and responds to events that need to process headers
138
+ # for synthetics and distributed tracing
139
+ attr_reader :monitors
137
140
  # Transaction and metric renaming rules as provided by the
138
141
  # collector on connect. The former are applied during txns,
139
142
  # the latter during harvest.
@@ -147,6 +150,7 @@ module NewRelic
147
150
  attr_reader :transaction_event_recorder
148
151
  attr_reader :attribute_filter
149
152
  attr_reader :adaptive_sampler
153
+ attr_reader :environment_report
150
154
 
151
155
  def transaction_event_aggregator
152
156
  @transaction_event_recorder.transaction_event_aggregator
@@ -205,7 +209,7 @@ module NewRelic
205
209
  end
206
210
 
207
211
  def install_pipe_service(channel_id)
208
- @service = NewRelic::Agent::PipeService.new(channel_id)
212
+ @service = PipeService.new(channel_id)
209
213
  if connected?
210
214
  @connected_pid = Process.pid
211
215
  else
@@ -236,12 +240,18 @@ module NewRelic
236
240
  end
237
241
 
238
242
  def revert_to_default_configuration
239
- NewRelic::Agent.config.remove_config_type(:manual)
240
- NewRelic::Agent.config.remove_config_type(:server)
243
+ Agent.config.remove_config_type(:manual)
244
+ Agent.config.remove_config_type(:server)
241
245
  end
242
246
 
243
247
  def stop_event_loop
244
248
  @event_loop.stop if @event_loop
249
+ # Wait the end of the event loop thread.
250
+ if @worker_thread
251
+ unless @worker_thread.join(3)
252
+ ::NewRelic::Agent.logger.debug "Event loop thread did not stop within 3 seconds"
253
+ end
254
+ end
245
255
  end
246
256
 
247
257
  def trap_signals_for_litespeed
@@ -332,7 +342,7 @@ module NewRelic
332
342
  end
333
343
 
334
344
  def log_app_name
335
- ::NewRelic::Agent.logger.info "Application: #{Agent.config.app_names.join(", ")}"
345
+ ::NewRelic::Agent.logger.info "Application: #{Agent.config[:app_name].join(", ")}"
336
346
  end
337
347
 
338
348
  def log_ignore_url_regexes
@@ -345,7 +355,7 @@ module NewRelic
345
355
 
346
356
  # Logs the configured application names
347
357
  def app_name_configured?
348
- names = Agent.config.app_names
358
+ names = Agent.config[:app_name]
349
359
  return names.respond_to?(:any?) && names.any?
350
360
  end
351
361
 
@@ -456,11 +466,11 @@ module NewRelic
456
466
  def defer_for_resque?
457
467
  NewRelic::Agent.config[:dispatcher] == :resque &&
458
468
  NewRelic::LanguageSupport.can_fork? &&
459
- !NewRelic::Agent::PipeChannelManager.listener.started?
469
+ !PipeChannelManager.listener.started?
460
470
  end
461
471
 
462
472
  def in_resque_child_process?
463
- defined?(@service) && @service.is_a?(NewRelic::Agent::PipeService)
473
+ defined?(@service) && @service.is_a?(PipeService)
464
474
  end
465
475
 
466
476
  # Sanity-check the agent configuration and start the agent,
@@ -482,6 +492,7 @@ module NewRelic
482
492
 
483
493
  unless in_resque_child_process?
484
494
  install_exit_handler
495
+ environment_for_connect
485
496
  @harvest_samplers.load_samplers unless Agent.config[:disable_samplers]
486
497
  end
487
498
 
@@ -555,13 +566,16 @@ module NewRelic
555
566
  # This is necessary for cases where we're in a forked child and Ruby
556
567
  # might be holding locks for background thread that aren't there anymore.
557
568
  def reset_objects_with_locks
558
- @stats_engine = NewRelic::Agent::StatsEngine.new
569
+ @stats_engine = StatsEngine.new
559
570
  end
560
571
 
561
572
  def flush_pipe_data
562
- if connected? && @service.is_a?(::NewRelic::Agent::PipeService)
573
+ if connected? && @service.is_a?(PipeService)
563
574
  transmit_data
564
- transmit_event_data
575
+ transmit_analytic_event_data
576
+ transmit_custom_event_data
577
+ transmit_error_event_data
578
+ transmit_span_event_data
565
579
  end
566
580
  end
567
581
 
@@ -577,20 +591,46 @@ module NewRelic
577
591
 
578
592
  LOG_ONCE_KEYS_RESET_PERIOD = 60.0
579
593
 
594
+ # Certain event types may sometimes need to be on the same interval as metrics,
595
+ # so we will check config assigned in EventHarvestConfig to determine the interval
596
+ # on which to report them
597
+ def interval_for event_type
598
+ interval = Agent.config[:"event_report_period.#{event_type}"]
599
+ :"#{interval}_second_harvest"
600
+ end
601
+
602
+ ANALYTIC_EVENT_DATA = "analytic_event_data".freeze
603
+ CUSTOM_EVENT_DATA = "custom_event_data".freeze
604
+ ERROR_EVENT_DATA = "error_event_data".freeze
605
+ SPAN_EVENT_DATA = "span_event_data".freeze
606
+
580
607
  def create_and_run_event_loop
608
+ data_harvest = :"#{Agent.config[:data_report_period]}_second_harvest"
609
+ event_harvest = :"#{Agent.config[:event_report_period]}_second_harvest"
610
+
581
611
  @event_loop = create_event_loop
582
- @event_loop.on(:report_data) do
612
+ @event_loop.on(data_harvest) do
583
613
  transmit_data
584
614
  end
585
- @event_loop.on(:report_event_data) do
586
- transmit_event_data
615
+
616
+ @event_loop.on(interval_for ANALYTIC_EVENT_DATA) do
617
+ transmit_analytic_event_data
618
+ end
619
+ @event_loop.on(interval_for CUSTOM_EVENT_DATA) do
620
+ transmit_custom_event_data
621
+ end
622
+ @event_loop.on(interval_for ERROR_EVENT_DATA) do
623
+ transmit_error_event_data
624
+ end
625
+ @event_loop.on(interval_for SPAN_EVENT_DATA) do
626
+ transmit_span_event_data
587
627
  end
588
628
  @event_loop.on(:reset_log_once_keys) do
589
629
  ::NewRelic::Agent.logger.clear_already_logged
590
630
  end
591
- @event_loop.fire_every(Agent.config[:data_report_period], :report_data)
592
- @event_loop.fire_every(Agent.config[:event_report_period], :report_event_data)
593
- @event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD, :reset_log_once_keys)
631
+ @event_loop.fire_every(Agent.config[:data_report_period], data_harvest)
632
+ @event_loop.fire_every(Agent.config[:event_report_period], event_harvest)
633
+ @event_loop.fire_every(LOG_ONCE_KEYS_RESET_PERIOD, :reset_log_once_keys)
594
634
 
595
635
  @event_loop.run
596
636
  end
@@ -674,7 +714,7 @@ module NewRelic
674
714
  end
675
715
 
676
716
  ::NewRelic::Agent.logger.debug "Creating Ruby Agent worker thread."
677
- @worker_thread = NewRelic::Agent::Threading::AgentThread.create('Worker Loop') do
717
+ @worker_thread = Threading::AgentThread.create('Worker Loop') do
678
718
  deferred_work!(connection_options)
679
719
  end
680
720
  end
@@ -760,23 +800,24 @@ module NewRelic
760
800
  # require calls in Rails environments, so this method should only
761
801
  # be called synchronously from on the main thread.
762
802
  def environment_for_connect
763
- Agent.config[:send_environment_info] ? Array(EnvironmentReport.new) : []
803
+ @environment_report ||= Agent.config[:send_environment_info] ? Array(EnvironmentReport.new) : []
764
804
  end
765
805
 
766
- # Constructs and memoizes an event_harvest_config hash to be used in
806
+ # Constructs and memoizes an event_harvest_config hash to be used in
767
807
  # the payload sent during connect (and reconnect)
768
808
  def event_harvest_config
769
809
  @event_harvest_config ||= Configuration::EventHarvestConfig.from_config(Agent.config)
770
810
  end
771
811
 
772
812
  # Builds the payload to send to the connect service,
773
- # connects, then configures the agent using the response from
813
+ # connects, then configures the agent using the response from
774
814
  # the connect service
775
815
  def connect_to_server
776
816
  request_builder = ::NewRelic::Agent::Connect::RequestBuilder.new \
777
817
  @service,
778
818
  Agent.config,
779
- event_harvest_config
819
+ event_harvest_config,
820
+ environment_for_connect
780
821
  connect_response = @service.connect request_builder.connect_payload
781
822
 
782
823
  response_handler = ::NewRelic::Agent::Connect::ResponseHandler.new(self, Agent.config)
@@ -990,7 +1031,7 @@ module NewRelic
990
1031
  end
991
1032
 
992
1033
  def harvest_and_send_timeslice_data
993
- NewRelic::Agent::TransactionTimeAggregator.harvest!
1034
+ TransactionTimeAggregator.harvest!
994
1035
  harvest_and_send_from_container(@stats_engine, :metric_data)
995
1036
  end
996
1037
 
@@ -1019,17 +1060,20 @@ module NewRelic
1019
1060
  def harvest_and_send_analytic_event_data
1020
1061
  harvest_and_send_from_container(transaction_event_aggregator, :analytic_event_data)
1021
1062
  harvest_and_send_from_container(synthetics_event_aggregator, :analytic_event_data)
1022
- harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
1023
1063
  end
1024
1064
 
1025
- def harvest_and_send_span_event_data
1026
- harvest_and_send_from_container(span_event_aggregator, :span_event_data)
1065
+ def harvest_and_send_custom_event_data
1066
+ harvest_and_send_from_container(@custom_event_aggregator, :custom_event_data)
1027
1067
  end
1028
1068
 
1029
1069
  def harvest_and_send_error_event_data
1030
1070
  harvest_and_send_from_container @error_collector.error_event_aggregator, :error_event_data
1031
1071
  end
1032
1072
 
1073
+ def harvest_and_send_span_event_data
1074
+ harvest_and_send_from_container(span_event_aggregator, :span_event_data)
1075
+ end
1076
+
1033
1077
  def check_for_and_handle_agent_commands
1034
1078
  begin
1035
1079
  @agent_command_router.check_for_and_handle_agent_commands
@@ -1050,18 +1094,30 @@ module NewRelic
1050
1094
  NewRelic::Agent.record_metric("Supportability/remote_unavailable/#{endpoint.to_s}", 0.0)
1051
1095
  end
1052
1096
 
1053
- def transmit_event_data
1054
- transmit_single_data_type(:harvest_and_send_analytic_event_data, "TransactionEvent")
1097
+ TRANSACTION_EVENT = "TransactionEvent".freeze
1098
+ def transmit_analytic_event_data
1099
+ transmit_single_data_type(:harvest_and_send_analytic_event_data, TRANSACTION_EVENT)
1100
+ end
1101
+
1102
+ CUSTOM_EVENT = "CustomEvent".freeze
1103
+ def transmit_custom_event_data
1104
+ transmit_single_data_type(:harvest_and_send_custom_event_data, CUSTOM_EVENT)
1105
+ end
1106
+
1107
+ ERROR_EVENT = "ErrorEvent".freeze
1108
+ def transmit_error_event_data
1109
+ transmit_single_data_type(:harvest_and_send_error_event_data, ERROR_EVENT)
1055
1110
  end
1056
1111
 
1112
+ SPAN_EVENT = "SpanEvent".freeze
1057
1113
  def transmit_span_event_data
1058
- transmit_single_data_type(:harvest_and_send_span_event_data, "SpanEvent")
1114
+ transmit_single_data_type(:harvest_and_send_span_event_data, SPAN_EVENT)
1059
1115
  end
1060
1116
 
1061
1117
  def transmit_single_data_type(harvest_method, supportability_name)
1062
1118
  now = Time.now
1063
1119
 
1064
- msg = "Sending #{harvest_method.to_s.gsub("harvest_and_send_", "")} to New Relic Service"
1120
+ msg = "Sending #{supportability_name} data to New Relic Service"
1065
1121
  ::NewRelic::Agent.logger.debug msg
1066
1122
 
1067
1123
  @service.session do # use http keep-alive
@@ -1108,7 +1164,10 @@ module NewRelic
1108
1164
 
1109
1165
  @events.notify(:before_shutdown)
1110
1166
  transmit_data
1111
- transmit_event_data
1167
+ transmit_analytic_event_data
1168
+ transmit_custom_event_data
1169
+ transmit_error_event_data
1170
+ transmit_span_event_data
1112
1171
 
1113
1172
  if @connected_pid == $$ && !@service.kind_of?(NewRelic::Agent::NewRelicService)
1114
1173
  ::NewRelic::Agent.logger.debug "Sending New Relic service agent run shutdown message"
@@ -173,6 +173,10 @@ module NewRelic
173
173
  StartupLogger.instance.dump(self)
174
174
  end
175
175
 
176
+ def self.format_fatal_error message
177
+ "** [NewRelic] FATAL : #{message}\n"
178
+ end
179
+
176
180
  end
177
181
 
178
182
  # In an effort to not lose messages during startup, we trap them in memory
@@ -121,7 +121,7 @@ module NewRelic
121
121
  @high_security = config[:high_security]
122
122
 
123
123
  setup_key_cache
124
- cache_prefix_blacklist
124
+ cache_prefix_denylist
125
125
  end
126
126
 
127
127
  # Note the key_cache is a global cache, accessible by multiple threads,
@@ -222,16 +222,16 @@ module NewRelic
222
222
  # arguments for Sidekiq and Resque in the common case, since none of
223
223
  # these attributes are captured by default.
224
224
  #
225
- def cache_prefix_blacklist
226
- @prefix_blacklist = {}
227
- @prefix_blacklist[:'request.parameters'] = true unless might_allow_prefix_uncached?(:'request.parameters')
228
- @prefix_blacklist[:'job.sidekiq.args'] = true unless might_allow_prefix_uncached?(:'job.sidekiq.args')
229
- @prefix_blacklist[:'job.resque.args'] = true unless might_allow_prefix_uncached?(:'job.resque.args')
225
+ def cache_prefix_denylist
226
+ @prefix_denylist = {}
227
+ @prefix_denylist[:'request.parameters'] = true unless might_allow_prefix_uncached?(:'request.parameters')
228
+ @prefix_denylist[:'job.sidekiq.args'] = true unless might_allow_prefix_uncached?(:'job.sidekiq.args')
229
+ @prefix_denylist[:'job.resque.args'] = true unless might_allow_prefix_uncached?(:'job.resque.args')
230
230
  end
231
231
 
232
232
  # Note that the given prefix *must* be a Symbol
233
233
  def might_allow_prefix?(prefix)
234
- !@prefix_blacklist.include?(prefix)
234
+ !@prefix_denylist.include?(prefix)
235
235
  end
236
236
 
237
237
  def might_allow_prefix_uncached?(prefix)
@@ -0,0 +1,150 @@
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 'new_relic/agent/attribute_processing'
6
+
7
+ module NewRelic
8
+ module Agent
9
+ class Attributes
10
+ KEY_LIMIT = 255
11
+ VALUE_LIMIT = 255
12
+ COUNT_LIMIT = 64
13
+
14
+ def initialize(filter)
15
+ @filter = filter
16
+
17
+ @custom_attributes = {}
18
+ @agent_attributes = {}
19
+ @intrinsic_attributes = {}
20
+
21
+ @custom_destinations = {}
22
+ @agent_destinations = {}
23
+ @already_warned_count_limit = nil
24
+ end
25
+
26
+ def add_agent_attribute(key, value, default_destinations)
27
+ destinations = @filter.apply(key, default_destinations)
28
+ return if destinations == AttributeFilter::DST_NONE
29
+
30
+ @agent_destinations[key] = destinations
31
+ add(@agent_attributes, key, value)
32
+ end
33
+
34
+ def add_agent_attribute_with_key_check(key, value, default_destinations)
35
+ if exceeds_bytesize_limit? key, KEY_LIMIT
36
+ NewRelic::Agent.logger.debug("Agent attribute #{key} was dropped for exceeding key length limit #{KEY_LIMIT}")
37
+ return
38
+ end
39
+
40
+ add_agent_attribute(key, value, default_destinations)
41
+ end
42
+
43
+ def add_intrinsic_attribute(key, value)
44
+ add(@intrinsic_attributes, key, value)
45
+ end
46
+
47
+ def merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
48
+ return if @filter.high_security?
49
+ return if !@filter.might_allow_prefix?(prefix)
50
+
51
+ AttributeProcessing.flatten_and_coerce(attributes, prefix) do |k, v|
52
+ add_agent_attribute_with_key_check(k, v, AttributeFilter::DST_NONE)
53
+ end
54
+ end
55
+
56
+ def merge_custom_attributes(other)
57
+ return unless Agent.config[:'custom_attributes.enabled']
58
+ return if other.empty?
59
+ AttributeProcessing.flatten_and_coerce(other) do |k, v|
60
+ add_custom_attribute(k, v)
61
+ end
62
+ end
63
+
64
+ def custom_attributes_for(destination)
65
+ for_destination(@custom_attributes, @custom_destinations, destination)
66
+ end
67
+
68
+ def agent_attributes_for(destination)
69
+ for_destination(@agent_attributes, @agent_destinations, destination)
70
+ end
71
+
72
+ def intrinsic_attributes_for(destination)
73
+ if destination == NewRelic::Agent::AttributeFilter::DST_TRANSACTION_TRACER ||
74
+ destination == NewRelic::Agent::AttributeFilter::DST_ERROR_COLLECTOR
75
+ @intrinsic_attributes
76
+ else
77
+ NewRelic::EMPTY_HASH
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def add_custom_attribute(key, value)
84
+ if @custom_attributes.size >= COUNT_LIMIT
85
+ unless @already_warned_count_limit
86
+ NewRelic::Agent.logger.warn("Custom attributes count exceeded limit of #{COUNT_LIMIT}. Any additional custom attributes during this transaction will be dropped.")
87
+ @already_warned_count_limit = true
88
+ end
89
+ return
90
+ end
91
+
92
+ if @filter.high_security?
93
+ NewRelic::Agent.logger.debug("Unable to add custom attribute #{key} while in high security mode.")
94
+ return
95
+ end
96
+
97
+ if exceeds_bytesize_limit?(key, KEY_LIMIT)
98
+ NewRelic::Agent.logger.warn("Custom attribute key '#{key}' was longer than limit of #{KEY_LIMIT} bytes. This attribute will be dropped.")
99
+ return
100
+ end
101
+
102
+ destinations = @filter.apply(key, AttributeFilter::DST_ALL)
103
+ return if destinations == AttributeFilter::DST_NONE
104
+
105
+ @custom_destinations[key] = destinations
106
+ add(@custom_attributes, key, value)
107
+ end
108
+
109
+ def add(attributes, key, value)
110
+ return if value.nil?
111
+
112
+ if exceeds_bytesize_limit?(value, VALUE_LIMIT)
113
+ value = slice(value)
114
+ end
115
+
116
+ attributes[key] = value
117
+ end
118
+
119
+ def for_destination(attributes, calculated_destinations, destination)
120
+ # Avoid allocating anything if there are no attrs at all
121
+ return NewRelic::EMPTY_HASH if attributes.empty?
122
+
123
+ attributes.inject({}) do |memo, (key, value)|
124
+ if @filter.allows?(calculated_destinations[key], destination)
125
+ memo[key] = value
126
+ end
127
+ memo
128
+ end
129
+ end
130
+
131
+ def exceeds_bytesize_limit?(value, limit)
132
+ if value.respond_to?(:bytesize)
133
+ value.bytesize > limit
134
+ elsif value.is_a?(Symbol)
135
+ value.to_s.bytesize > limit
136
+ else
137
+ false
138
+ end
139
+ end
140
+
141
+ # Take one byte past our limit. Why? This lets us unconditionally chop!
142
+ # the end. It'll either remove the one-character-too-many we have, or
143
+ # peel off the partial, mangled character left by the byteslice.
144
+ def slice(incoming)
145
+ result = incoming.to_s.byteslice(0, VALUE_LIMIT + 1)
146
+ result.chop!
147
+ end
148
+ end
149
+ end
150
+ end