newrelic_rpm 6.3.0.355 → 6.8.0.360

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +50 -10
  4. data/CHANGELOG.md +198 -0
  5. data/Guardfile +7 -1
  6. data/lib/new_relic/agent.rb +80 -0
  7. data/lib/new_relic/agent/agent.rb +87 -26
  8. data/lib/new_relic/agent/agent_logger.rb +4 -0
  9. data/lib/new_relic/agent/attribute_filter.rb +7 -7
  10. data/lib/new_relic/agent/attributes.rb +152 -0
  11. data/lib/new_relic/agent/autostart.rb +19 -14
  12. data/lib/new_relic/agent/commands/agent_command_router.rb +2 -21
  13. data/lib/new_relic/agent/configuration/default_source.rb +129 -39
  14. data/lib/new_relic/agent/configuration/environment_source.rb +4 -2
  15. data/lib/new_relic/agent/configuration/event_harvest_config.rb +45 -0
  16. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  17. data/lib/new_relic/agent/configuration/manager.rb +13 -9
  18. data/lib/new_relic/agent/configuration/server_source.rb +33 -9
  19. data/lib/new_relic/agent/configuration/yaml_source.rb +10 -5
  20. data/lib/new_relic/agent/connect/request_builder.rb +11 -13
  21. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  22. data/lib/new_relic/agent/cross_app_monitor.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_trace_intrinsics.rb +90 -0
  26. data/lib/new_relic/agent/distributed_trace_metrics.rb +74 -0
  27. data/lib/new_relic/agent/distributed_trace_monitor.rb +2 -12
  28. data/lib/new_relic/agent/distributed_trace_payload.rb +9 -76
  29. data/lib/new_relic/agent/distributed_trace_transport_type.rb +43 -0
  30. data/lib/new_relic/agent/error_collector.rb +2 -2
  31. data/lib/new_relic/agent/error_event_aggregator.rb +2 -1
  32. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -0
  33. data/lib/new_relic/agent/event_aggregator.rb +26 -32
  34. data/lib/new_relic/agent/guid_generator.rb +28 -0
  35. data/lib/new_relic/agent/inbound_request_monitor.rb +2 -2
  36. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +24 -42
  37. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +45 -69
  38. data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +70 -53
  39. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +25 -18
  40. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +33 -47
  41. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +4 -4
  42. data/lib/new_relic/agent/instrumentation/grape.rb +2 -3
  43. data/lib/new_relic/agent/instrumentation/{evented_subscriber.rb → notifications_subscriber.rb} +7 -66
  44. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +2 -3
  45. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
  46. data/lib/new_relic/agent/logging.rb +129 -0
  47. data/lib/new_relic/agent/new_relic_service.rb +7 -9
  48. data/lib/new_relic/agent/priority_sampled_buffer.rb +2 -0
  49. data/lib/new_relic/agent/span_event_aggregator.rb +2 -4
  50. data/lib/new_relic/agent/span_event_primitive.rb +29 -7
  51. data/lib/new_relic/agent/sql_sampler.rb +1 -1
  52. data/lib/new_relic/agent/threading/backtrace_service.rb +3 -3
  53. data/lib/new_relic/agent/threading/thread_profile.rb +9 -23
  54. data/lib/new_relic/agent/trace_context.rb +244 -0
  55. data/lib/new_relic/agent/trace_context_payload.rb +134 -0
  56. data/lib/new_relic/agent/trace_context_request_monitor.rb +42 -0
  57. data/lib/new_relic/agent/tracer.rb +32 -0
  58. data/lib/new_relic/agent/transaction.rb +26 -20
  59. data/lib/new_relic/agent/transaction/abstract_segment.rb +2 -2
  60. data/lib/new_relic/agent/transaction/distributed_tracing.rb +20 -101
  61. data/lib/new_relic/agent/transaction/external_request_segment.rb +18 -5
  62. data/lib/new_relic/agent/transaction/segment.rb +7 -1
  63. data/lib/new_relic/agent/transaction/trace.rb +3 -8
  64. data/lib/new_relic/agent/transaction/trace_builder.rb +0 -1
  65. data/lib/new_relic/agent/transaction/trace_context.rb +159 -0
  66. data/lib/new_relic/agent/transaction/trace_node.rb +8 -3
  67. data/lib/new_relic/agent/transaction_error_primitive.rb +4 -11
  68. data/lib/new_relic/agent/transaction_event_primitive.rb +3 -11
  69. data/lib/new_relic/agent/transaction_event_recorder.rb +3 -3
  70. data/lib/new_relic/agent/transaction_sampler.rb +1 -5
  71. data/lib/new_relic/cli/commands/deployments.rb +1 -1
  72. data/lib/new_relic/coerce.rb +29 -6
  73. data/lib/new_relic/control/instance_methods.rb +10 -1
  74. data/lib/new_relic/dependency_detection.rb +4 -4
  75. data/lib/new_relic/noticed_error.rb +8 -4
  76. data/lib/new_relic/rack/browser_monitoring.rb +10 -8
  77. data/lib/new_relic/version.rb +1 -1
  78. data/lib/tasks/config.rake +1 -2
  79. data/newrelic_rpm.gemspec +13 -4
  80. data/test/agent_helper.rb +95 -9
  81. data/true +0 -0
  82. metadata +58 -24
  83. data/lib/new_relic/agent/commands/xray_session.rb +0 -55
  84. data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
  85. data/lib/new_relic/agent/configuration/event_data.rb +0 -39
  86. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  87. data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
  88. data/lib/tasks/versions.html.erb +0 -28
  89. data/lib/tasks/versions.postface.html +0 -8
  90. data/lib/tasks/versions.preface.html +0 -9
  91. data/lib/tasks/versions.rake +0 -65
  92. data/lib/tasks/versions.txt.erb +0 -14
@@ -1,55 +0,0 @@
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 'forwardable'
6
-
7
- module NewRelic
8
- module Agent
9
- module Commands
10
- class XraySession
11
- extend Forwardable
12
-
13
- attr_reader :id, :command_arguments
14
- attr_reader :xray_session_name, :key_transaction_name,
15
- :requested_trace_count, :duration, :sample_period
16
-
17
- def initialize(command_arguments)
18
- @command_arguments = command_arguments
19
- @id = command_arguments.fetch("x_ray_id", nil)
20
- @xray_session_name = command_arguments.fetch("xray_session_name", "")
21
- @key_transaction_name = command_arguments.fetch("key_transaction_name", "")
22
- @requested_trace_count = command_arguments.fetch("requested_trace_count", 100)
23
- @duration = command_arguments.fetch("duration", 86400)
24
- @sample_period = command_arguments.fetch("sample_period", 0.1)
25
- @run_profiler = command_arguments.fetch("run_profiler", true)
26
- end
27
-
28
- def active?
29
- @active
30
- end
31
-
32
- def run_profiler?
33
- @run_profiler && NewRelic::Agent.config[:'xray_session.allow_profiles']
34
- end
35
-
36
- def activate
37
- @active = true
38
- @start_time = Time.now
39
- end
40
-
41
- def deactivate
42
- @active = false
43
- end
44
-
45
- def requested_period
46
- @sample_period
47
- end
48
-
49
- def finished?
50
- @start_time + @duration < Time.now
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,161 +0,0 @@
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 'forwardable'
6
- require 'thread'
7
- require 'new_relic/agent/commands/xray_session'
8
-
9
- module NewRelic
10
- module Agent
11
- module Commands
12
- class XraySessionCollection
13
- extend Forwardable
14
-
15
- def initialize(backtrace_service, event_listener)
16
- @backtrace_service = backtrace_service
17
-
18
- # This lock protects access to the sessions hash, but it's expected
19
- # that individual session objects within the hash will be manipulated
20
- # outside the lock. This is safe because manipulation of the session
21
- # objects is expected from only a single thread (the harvest thread)
22
- @sessions_lock = Mutex.new
23
- @sessions = {}
24
-
25
- if event_listener
26
- event_listener.subscribe(:before_harvest, &method(:cleanup_finished_sessions))
27
- end
28
- end
29
-
30
- def handle_active_xray_sessions(agent_command)
31
- # If X-Rays are disabled, just be quiet about it and don't start the
32
- # command. Other hosts might be running the X-Ray, so we don't need
33
- # to bark on every get_agent_commands.
34
- if !NewRelic::Agent.config[:'xray_session.enabled']
35
- NewRelic::Agent.logger.debug("Not responding to X-Ray command because of config 'xray_session.enabled' = #{NewRelic::Agent.config[:'xray_session.enabled']}")
36
- return
37
- end
38
-
39
- incoming_ids = agent_command.arguments["xray_ids"]
40
- deactivate_for_incoming_sessions(incoming_ids)
41
- activate_sessions(incoming_ids)
42
- end
43
-
44
- def session_id_for_transaction_name(name)
45
- @sessions_lock.synchronize do
46
- @sessions.each do |id, session|
47
- return id if session.key_transaction_name == name
48
- end
49
- end
50
- nil
51
- end
52
-
53
- NO_PROFILES = [].freeze
54
-
55
- def harvest_thread_profiles
56
- return NO_PROFILES unless NewRelic::Agent::Threading::BacktraceService.is_supported?
57
-
58
- profiles = active_thread_profiling_sessions.map do |session|
59
- NewRelic::Agent.logger.debug("Harvesting profile for X-Ray session #{session.inspect}")
60
- @backtrace_service.harvest(session.key_transaction_name)
61
- end
62
- profiles.reject! {|p| p.empty?}
63
- profiles.compact
64
- end
65
-
66
- def stop_all_sessions
67
- deactivate_for_incoming_sessions([])
68
- end
69
-
70
- def cleanup_finished_sessions
71
- finished_session_ids.each do |id|
72
- NewRelic::Agent.logger.debug("Finished X-Ray session #{id} by duration. Removing it from active sessions.")
73
- remove_session_by_id(id)
74
- end
75
- end
76
-
77
-
78
- ### Internals
79
-
80
- def new_relic_service
81
- NewRelic::Agent.instance.service
82
- end
83
-
84
- # These are unsynchonized and should only be used for testing
85
- def_delegators :@sessions, :[], :include?
86
-
87
- def active_thread_profiling_sessions
88
- @sessions_lock.synchronize do
89
- @sessions.values.select { |s| s.active? && s.run_profiler? }
90
- end
91
- end
92
-
93
- ### Session activation
94
-
95
- def activate_sessions(incoming_ids)
96
- lookup_metadata_for(ids_to_activate(incoming_ids)).each do |raw|
97
- add_session(XraySession.new(raw))
98
- end
99
- end
100
-
101
- def ids_to_activate(incoming_ids)
102
- @sessions_lock.synchronize { incoming_ids - @sessions.keys }
103
- end
104
-
105
- # Please don't hold the @sessions_lock across me! Calling the service
106
- # is time-consuming, and will block request threads. Which is rude.
107
- def lookup_metadata_for(ids_to_activate)
108
- return [] if ids_to_activate.empty?
109
-
110
- NewRelic::Agent.logger.debug("Retrieving metadata for X-Ray sessions #{ids_to_activate.inspect}")
111
- new_relic_service.get_xray_metadata(ids_to_activate)
112
- end
113
-
114
- def add_session(session)
115
- NewRelic::Agent.logger.debug("Adding X-Ray session #{session.inspect}")
116
- NewRelic::Agent.increment_metric("Supportability/XraySessions/Starts")
117
-
118
- @sessions_lock.synchronize { @sessions[session.id] = session }
119
-
120
- session.activate
121
- if session.run_profiler?
122
- @backtrace_service.subscribe(session.key_transaction_name, session.command_arguments)
123
- end
124
- end
125
-
126
- ### Session deactivation
127
-
128
- def deactivate_for_incoming_sessions(incoming_ids)
129
- ids_to_remove(incoming_ids).each do |session_id|
130
- remove_session_by_id(session_id)
131
- end
132
- end
133
-
134
- def ids_to_remove(incoming_ids)
135
- @sessions_lock.synchronize { @sessions.keys - incoming_ids }
136
- end
137
-
138
- def remove_session_by_id(id)
139
- session = @sessions_lock.synchronize { @sessions.delete(id) }
140
-
141
- if session
142
- NewRelic::Agent.logger.debug("Removing X-Ray session #{session.inspect}")
143
- NewRelic::Agent.increment_metric("Supportability/XraySessions/Stops")
144
-
145
- if session.run_profiler?
146
- @backtrace_service.unsubscribe(session.key_transaction_name)
147
- end
148
- session.deactivate
149
- end
150
- end
151
-
152
- def finished_session_ids
153
- @sessions_lock.synchronize do
154
- @sessions.map{|k, s| k if s.finished?}.compact
155
- end
156
- end
157
-
158
- end
159
- end
160
- end
161
- end
@@ -1,39 +0,0 @@
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
- module NewRelic
6
- module Agent
7
- module Configuration
8
- module EventData
9
-
10
- extend self
11
-
12
- EVENT_DATA_CONFIG_KEY_MAPPING = {
13
- :analytic_event_data => :'analytics_events.max_samples_stored',
14
- :custom_event_data => :'custom_insights_events.max_samples_stored',
15
- :error_event_data => :'error_collector.max_event_samples_stored'
16
- }
17
-
18
- def from_config(config)
19
- {:harvest_limits => EVENT_DATA_CONFIG_KEY_MAPPING.inject({}) do
20
- |event_data, (event_data_key, config_key)|
21
- event_data[event_data_key] = config[config_key]
22
- event_data
23
- end
24
- }
25
- end
26
-
27
- def to_config_hash(connect_reply)
28
- config_hash = EVENT_DATA_CONFIG_KEY_MAPPING.inject({}) do
29
- |event_data, (event_data_key, config_key)|
30
- event_data[config_key] = connect_reply['event_data']['harvest_limits'][event_data_key.to_s]
31
- event_data
32
- end
33
- config_hash[:event_report_period] = connect_reply['event_data']['report_period_ms'] / 1000
34
- config_hash
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,154 +0,0 @@
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 Transaction
10
- class Attributes
11
- KEY_LIMIT = 255
12
- VALUE_LIMIT = 255
13
- COUNT_LIMIT = 64
14
-
15
- EMPTY_HASH = {}.freeze
16
-
17
- def initialize(filter)
18
- @filter = filter
19
-
20
- @custom_attributes = {}
21
- @agent_attributes = {}
22
- @intrinsic_attributes = {}
23
-
24
- @custom_destinations = {}
25
- @agent_destinations = {}
26
- @already_warned_count_limit = nil
27
- end
28
-
29
- def add_agent_attribute(key, value, default_destinations)
30
- destinations = @filter.apply(key, default_destinations)
31
- return if destinations == AttributeFilter::DST_NONE
32
-
33
- @agent_destinations[key] = destinations
34
- add(@agent_attributes, key, value)
35
- end
36
-
37
- def add_agent_attribute_with_key_check(key, value, default_destinations)
38
- if exceeds_bytesize_limit? key, KEY_LIMIT
39
- NewRelic::Agent.logger.debug("Agent attribute #{key} was dropped for exceeding key length limit #{KEY_LIMIT}")
40
- return
41
- end
42
-
43
- add_agent_attribute(key, value, default_destinations)
44
- end
45
-
46
- def add_intrinsic_attribute(key, value)
47
- add(@intrinsic_attributes, key, value)
48
- end
49
-
50
- def merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
51
- return if @filter.high_security?
52
- return if !@filter.might_allow_prefix?(prefix)
53
-
54
- AttributeProcessing.flatten_and_coerce(attributes, prefix) do |k, v|
55
- add_agent_attribute_with_key_check(k, v, AttributeFilter::DST_NONE)
56
- end
57
- end
58
-
59
- def merge_custom_attributes(other)
60
- return unless Agent.config[:'custom_attributes.enabled']
61
- return if other.empty?
62
- AttributeProcessing.flatten_and_coerce(other) do |k, v|
63
- add_custom_attribute(k, v)
64
- end
65
- end
66
-
67
- def custom_attributes_for(destination)
68
- for_destination(@custom_attributes, @custom_destinations, destination)
69
- end
70
-
71
- def agent_attributes_for(destination)
72
- for_destination(@agent_attributes, @agent_destinations, destination)
73
- end
74
-
75
- def intrinsic_attributes_for(destination)
76
- if destination == NewRelic::Agent::AttributeFilter::DST_TRANSACTION_TRACER ||
77
- destination == NewRelic::Agent::AttributeFilter::DST_ERROR_COLLECTOR
78
- @intrinsic_attributes
79
- else
80
- EMPTY_HASH
81
- end
82
- end
83
-
84
- private
85
-
86
- def add_custom_attribute(key, value)
87
- if @custom_attributes.size >= COUNT_LIMIT
88
- unless @already_warned_count_limit
89
- NewRelic::Agent.logger.warn("Custom attributes count exceeded limit of #{COUNT_LIMIT}. Any additional custom attributes during this transaction will be dropped.")
90
- @already_warned_count_limit = true
91
- end
92
- return
93
- end
94
-
95
- if @filter.high_security?
96
- NewRelic::Agent.logger.debug("Unable to add custom attribute #{key} while in high security mode.")
97
- return
98
- end
99
-
100
- if exceeds_bytesize_limit?(key, KEY_LIMIT)
101
- NewRelic::Agent.logger.warn("Custom attribute key '#{key}' was longer than limit of #{KEY_LIMIT} bytes. This attribute will be dropped.")
102
- return
103
- end
104
-
105
- destinations = @filter.apply(key, AttributeFilter::DST_ALL)
106
- return if destinations == AttributeFilter::DST_NONE
107
-
108
- @custom_destinations[key] = destinations
109
- add(@custom_attributes, key, value)
110
- end
111
-
112
- def add(attributes, key, value)
113
- return if value.nil?
114
-
115
- if exceeds_bytesize_limit?(value, VALUE_LIMIT)
116
- value = slice(value)
117
- end
118
-
119
- attributes[key] = value
120
- end
121
-
122
- def for_destination(attributes, calculated_destinations, destination)
123
- # Avoid allocating anything if there are no attrs at all
124
- return EMPTY_HASH if attributes.empty?
125
-
126
- attributes.inject({}) do |memo, (key, value)|
127
- if @filter.allows?(calculated_destinations[key], destination)
128
- memo[key] = value
129
- end
130
- memo
131
- end
132
- end
133
-
134
- def exceeds_bytesize_limit?(value, limit)
135
- if value.respond_to?(:bytesize)
136
- value.bytesize > limit
137
- elsif value.is_a?(Symbol)
138
- value.to_s.bytesize > limit
139
- else
140
- false
141
- end
142
- end
143
-
144
- # Take one byte past our limit. Why? This lets us unconditionally chop!
145
- # the end. It'll either remove the one-character-too-many we have, or
146
- # peel off the partial, mangled character left by the byteslice.
147
- def slice(incoming)
148
- result = incoming.to_s.byteslice(0, VALUE_LIMIT + 1)
149
- result.chop!
150
- end
151
- end
152
- end
153
- end
154
- end
@@ -1,64 +0,0 @@
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/transaction/transaction_sample_buffer'
6
-
7
- module NewRelic
8
- module Agent
9
- class Transaction
10
- class XraySampleBuffer < TransactionSampleBuffer
11
-
12
- attr_writer :xray_session_collection
13
-
14
- def initialize
15
- super
16
-
17
- # Memoize the config setting since this happens per request
18
- @enabled = NewRelic::Agent.config[:'xray_session.allow_traces']
19
- NewRelic::Agent.config.register_callback(:'xray_session.allow_traces') do |new_value|
20
- @enabled = new_value
21
- end
22
-
23
- @capacity = NewRelic::Agent.config[:'xray_session.max_samples']
24
- NewRelic::Agent.config.register_callback(:'xray_session.max_samples') do |new_value|
25
- @capacity = new_value
26
- end
27
- end
28
-
29
- def xray_session_collection
30
- @xray_session_collection ||= NewRelic::Agent.instance.agent_command_router.xray_session_collection
31
- end
32
-
33
- def capacity
34
- @capacity
35
- end
36
-
37
- def truncate_samples
38
- # First in wins, so stop on allow_sample? instead of truncating
39
- end
40
-
41
- def allow_sample?(sample)
42
- !full? && !lookup_session_id(sample).nil?
43
- end
44
-
45
- def enabled?
46
- @enabled
47
- end
48
-
49
-
50
- private
51
-
52
- def add_sample(sample)
53
- super(sample)
54
- sample.xray_session_id = lookup_session_id(sample)
55
- end
56
-
57
- def lookup_session_id(sample)
58
- xray_session_collection.session_id_for_transaction_name(sample.transaction_name)
59
- end
60
-
61
- end
62
- end
63
- end
64
- end