newrelic_rpm 6.5.0.357 → 6.10.0.364

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +65 -5
  4. data/CHANGELOG.md +243 -0
  5. data/Guardfile +18 -1
  6. data/lib/new_relic/agent.rb +89 -7
  7. data/lib/new_relic/agent/agent.rb +116 -57
  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 +150 -0
  11. data/lib/new_relic/agent/autostart.rb +19 -14
  12. data/lib/new_relic/agent/configuration/default_source.rb +132 -13
  13. data/lib/new_relic/agent/configuration/event_harvest_config.rb +11 -5
  14. data/lib/new_relic/agent/configuration/manager.rb +13 -9
  15. data/lib/new_relic/agent/configuration/server_source.rb +3 -2
  16. data/lib/new_relic/agent/configuration/yaml_source.rb +11 -6
  17. data/lib/new_relic/agent/connect/request_builder.rb +5 -13
  18. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  19. data/lib/new_relic/agent/database.rb +1 -2
  20. data/lib/new_relic/agent/datastores/mongo.rb +1 -1
  21. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -2
  22. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +8 -8
  23. data/lib/new_relic/agent/distributed_tracing.rb +155 -6
  24. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +0 -0
  25. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +60 -45
  26. data/lib/new_relic/agent/distributed_tracing/distributed_trace_intrinsics.rb +80 -0
  27. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  28. data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +23 -99
  29. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  30. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  31. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
  32. data/lib/new_relic/agent/error_collector.rb +35 -18
  33. data/lib/new_relic/agent/error_event_aggregator.rb +9 -6
  34. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -0
  35. data/lib/new_relic/agent/event_aggregator.rb +26 -32
  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/rails_notifications/action_cable.rb +2 -3
  69. data/lib/new_relic/agent/instrumentation/redis.rb +9 -3
  70. data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
  71. data/lib/new_relic/agent/instrumentation/sidekiq.rb +0 -1
  72. data/lib/new_relic/agent/instrumentation/typhoeus.rb +23 -6
  73. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
  74. data/lib/new_relic/agent/logging.rb +139 -0
  75. data/lib/new_relic/agent/messaging.rb +5 -73
  76. data/lib/new_relic/agent/method_tracer.rb +3 -2
  77. data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
  78. data/lib/new_relic/agent/monitors.rb +27 -0
  79. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  80. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  81. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +3 -3
  82. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
  83. data/lib/new_relic/agent/new_relic_service.rb +7 -5
  84. data/lib/new_relic/agent/noticible_error.rb +22 -0
  85. data/lib/new_relic/agent/span_event_aggregator.rb +2 -4
  86. data/lib/new_relic/agent/span_event_primitive.rb +82 -53
  87. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  88. data/lib/new_relic/agent/supported_versions.rb +2 -2
  89. data/lib/new_relic/agent/tracer.rb +65 -18
  90. data/lib/new_relic/agent/transaction.rb +84 -79
  91. data/lib/new_relic/agent/transaction/abstract_segment.rb +28 -2
  92. data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
  93. data/lib/new_relic/agent/transaction/distributed_tracing.rb +57 -146
  94. data/lib/new_relic/agent/transaction/external_request_segment.rb +29 -36
  95. data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -11
  96. data/lib/new_relic/agent/transaction/segment.rb +7 -1
  97. data/lib/new_relic/agent/transaction/trace.rb +2 -4
  98. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  99. data/lib/new_relic/agent/transaction/trace_node.rb +10 -8
  100. data/lib/new_relic/agent/transaction_error_primitive.rb +10 -15
  101. data/lib/new_relic/agent/transaction_event_primitive.rb +28 -39
  102. data/lib/new_relic/agent/transaction_event_recorder.rb +3 -3
  103. data/lib/new_relic/cli/commands/deployments.rb +1 -1
  104. data/lib/new_relic/cli/commands/install.rb +3 -2
  105. data/lib/new_relic/coerce.rb +31 -6
  106. data/lib/new_relic/constants.rb +34 -0
  107. data/lib/new_relic/control/instance_methods.rb +10 -1
  108. data/lib/new_relic/dependency_detection.rb +4 -4
  109. data/lib/new_relic/noticed_error.rb +38 -17
  110. data/lib/new_relic/rack/browser_monitoring.rb +5 -0
  111. data/lib/new_relic/supportability_helper.rb +14 -0
  112. data/lib/new_relic/version.rb +1 -1
  113. data/lib/tasks/multiverse.rb +25 -0
  114. data/lib/tasks/tests.rake +6 -1
  115. data/newrelic_rpm.gemspec +16 -5
  116. data/test/agent_helper.rb +329 -70
  117. data/true +0 -0
  118. metadata +98 -30
  119. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  120. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
  121. data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
  122. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  123. data/lib/tasks/versions.html.erb +0 -28
  124. data/lib/tasks/versions.postface.html +0 -8
  125. data/lib/tasks/versions.preface.html +0 -9
  126. data/lib/tasks/versions.rake +0 -65
  127. data/lib/tasks/versions.txt.erb +0 -14
@@ -0,0 +1,126 @@
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/coerce'
6
+
7
+ module NewRelic
8
+ module Agent
9
+ class TraceContextPayload
10
+ VERSION = 0
11
+ PARENT_TYPE = 0
12
+ DELIMITER = "-".freeze
13
+ SUPPORTABILITY_PARSE_EXCEPTION = "Supportability/TraceContext/Parse/Exception".freeze
14
+
15
+ TRUE_CHAR = '1'.freeze
16
+ FALSE_CHAR = '0'.freeze
17
+
18
+ PARENT_TYPES = %w(App Browser Mobile).map(&:freeze).freeze
19
+
20
+ class << self
21
+ def create version: VERSION,
22
+ parent_type: PARENT_TYPE,
23
+ parent_account_id: nil,
24
+ parent_app_id: nil,
25
+ id: nil,
26
+ transaction_id: nil,
27
+ sampled: nil,
28
+ priority: nil,
29
+ timestamp: now_ms
30
+
31
+ new version, parent_type, parent_account_id, parent_app_id, id,
32
+ transaction_id, sampled, priority, timestamp
33
+ end
34
+
35
+ include NewRelic::Coerce
36
+
37
+ def from_s payload_string
38
+ attrs = payload_string.split(DELIMITER)
39
+
40
+ payload = create \
41
+ version: int!(attrs[0]),
42
+ parent_type: int!(attrs[1]),
43
+ parent_account_id: attrs[2],
44
+ parent_app_id: attrs[3],
45
+ id: value_or_nil(attrs[4]),
46
+ transaction_id: value_or_nil(attrs[5]),
47
+ sampled: value_or_nil(attrs[6]) ? boolean_int!(attrs[6]) == 1 : nil,
48
+ priority: float!(attrs[7]),
49
+ timestamp: int!(attrs[8])
50
+ handle_invalid_payload message: 'payload missing attributes' unless payload.valid?
51
+ payload
52
+ rescue => e
53
+ handle_invalid_payload error: e
54
+ raise
55
+ end
56
+
57
+ private
58
+
59
+ def now_ms
60
+ (Time.now.to_f * 1000).round
61
+ end
62
+
63
+ def handle_invalid_payload error: nil, message: nil
64
+ NewRelic::Agent.increment_metric SUPPORTABILITY_PARSE_EXCEPTION
65
+ if error
66
+ NewRelic::Agent.logger.warn "Error parsing trace context payload", error
67
+ elsif message
68
+ NewRelic::Agent.logger.warn "Error parsing trace context payload: #{message}"
69
+ end
70
+ end
71
+ end
72
+
73
+ attr_accessor :version,
74
+ :parent_type_id,
75
+ :parent_account_id,
76
+ :parent_app_id,
77
+ :id,
78
+ :transaction_id,
79
+ :sampled,
80
+ :priority,
81
+ :timestamp
82
+
83
+ alias_method :sampled?, :sampled
84
+
85
+ def initialize version, parent_type_id, parent_account_id, parent_app_id,
86
+ id, transaction_id, sampled, priority, timestamp
87
+ @version = version
88
+ @parent_type_id = parent_type_id
89
+ @parent_account_id = parent_account_id
90
+ @parent_app_id = parent_app_id
91
+ @id = id
92
+ @transaction_id = transaction_id
93
+ @sampled = sampled
94
+ @priority = priority
95
+ @timestamp = timestamp
96
+ end
97
+
98
+ def parent_type
99
+ @parent_type_string ||= PARENT_TYPES[@parent_type_id]
100
+ end
101
+
102
+ def valid?
103
+ version \
104
+ && parent_type_id \
105
+ && !parent_account_id.empty? \
106
+ && !parent_app_id.empty? \
107
+ && timestamp
108
+ rescue
109
+ false
110
+ end
111
+
112
+ def to_s
113
+ result = version.to_s
114
+ result << DELIMITER << parent_type_id.to_s
115
+ result << DELIMITER << parent_account_id
116
+ result << DELIMITER << parent_app_id
117
+ result << DELIMITER << (id || NewRelic::EMPTY_STR)
118
+ result << DELIMITER << (transaction_id || NewRelic::EMPTY_STR)
119
+ result << DELIMITER << (sampled ? TRUE_CHAR : FALSE_CHAR)
120
+ result << DELIMITER << sprintf("%.6f", priority)
121
+ result << DELIMITER << timestamp.to_s
122
+ result
123
+ end
124
+ end
125
+ end
126
+ end
@@ -18,9 +18,9 @@ module NewRelic
18
18
  attr_reader :error_trace_aggregator, :error_event_aggregator
19
19
 
20
20
  # Returns a new error collector
21
- def initialize
21
+ def initialize events
22
22
  @error_trace_aggregator = ErrorTraceAggregator.new(MAX_ERROR_QUEUE_LENGTH)
23
- @error_event_aggregator = ErrorEventAggregator.new
23
+ @error_event_aggregator = ErrorEventAggregator.new events
24
24
 
25
25
  # lookup of exception class names to ignore. Hash for fast access
26
26
  @ignore = {}
@@ -32,7 +32,6 @@ module NewRelic
32
32
  end
33
33
  end
34
34
 
35
-
36
35
  def initialize_ignored_errors(ignore_errors)
37
36
  @ignore.clear
38
37
  ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String
@@ -74,7 +73,7 @@ module NewRelic
74
73
  end
75
74
 
76
75
  def self.ignore_error_filter
77
- @ignore_filter
76
+ defined?(@ignore_filter) ? @ignore_filter : nil
78
77
  end
79
78
 
80
79
  # errors is an array of Exception Class Names
@@ -117,14 +116,22 @@ module NewRelic
117
116
  NewRelic::LanguageSupport.jruby? && exception.respond_to?(:java_class)
118
117
  end
119
118
 
120
- def exception_tagged?(exception)
119
+ def exception_tagged_with?(ivar, exception)
121
120
  return false if exception_is_java_object?(exception)
122
- exception.instance_variable_defined?(EXCEPTION_TAG_IVAR)
121
+ exception.instance_variable_defined?(ivar)
122
+ end
123
+
124
+ def tag_exception_using(ivar, exception)
125
+ return if exception_is_java_object?(exception) || exception.frozen?
126
+ begin
127
+ exception.instance_variable_set(ivar, true)
128
+ rescue => e
129
+ NewRelic::Agent.logger.warn("Failed to tag exception: #{exception}: ", e)
130
+ end
123
131
  end
124
132
 
125
133
  def tag_exception(exception)
126
- return if exception_is_java_object?(exception)
127
- return if exception.frozen?
134
+ return if exception_is_java_object?(exception) || exception.frozen?
128
135
  begin
129
136
  exception.instance_variable_set(EXCEPTION_TAG_IVAR, true)
130
137
  rescue => e
@@ -169,9 +176,9 @@ module NewRelic
169
176
 
170
177
  def skip_notice_error?(exception)
171
178
  disabled? ||
172
- error_is_ignored?(exception) ||
173
- exception.nil? ||
174
- exception_tagged?(exception)
179
+ error_is_ignored?(exception) ||
180
+ exception.nil? ||
181
+ exception_tagged_with?(EXCEPTION_TAG_IVAR, exception)
175
182
  end
176
183
 
177
184
  # calls a method on an object, if it responds to it - used for
@@ -191,8 +198,18 @@ module NewRelic
191
198
  sense_method(actual_exception, :backtrace) || '<no stack trace>'
192
199
  end
193
200
 
201
+ def notice_segment_error(segment, exception, options={})
202
+ return if skip_notice_error?(exception)
203
+
204
+ segment.set_noticed_error create_noticed_error(exception, options)
205
+ exception
206
+ rescue => e
207
+ ::NewRelic::Agent.logger.warn("Failure when capturing segment error '#{exception}':", e)
208
+ nil
209
+ end
210
+
194
211
  # See NewRelic::Agent.notice_error for options and commentary
195
- def notice_error(exception, options={}) #THREAD_LOCAL_ACCESS
212
+ def notice_error(exception, options={}, span_id=nil)
196
213
  return if skip_notice_error?(exception)
197
214
 
198
215
  tag_exception(exception)
@@ -205,8 +222,10 @@ module NewRelic
205
222
 
206
223
  noticed_error = create_noticed_error(exception, options)
207
224
  error_trace_aggregator.add_to_error_queue(noticed_error)
208
- payload = state.current_transaction ? state.current_transaction.payload : nil
209
- error_event_aggregator.record(noticed_error, payload)
225
+ transaction = state.current_transaction
226
+ payload = transaction ? transaction.payload : nil
227
+ span_id ||= (transaction && transaction.current_segment) ? transaction.current_segment.guid : nil
228
+ error_event_aggregator.record(noticed_error, payload, span_id)
210
229
  exception
211
230
  rescue => e
212
231
  ::NewRelic::Agent.logger.warn("Failure when capturing error '#{exception}':", e)
@@ -227,13 +246,11 @@ module NewRelic
227
246
  truncated_trace
228
247
  end
229
248
 
230
- EMPTY_STRING = ''.freeze
231
-
232
249
  def create_noticed_error(exception, options)
233
- error_metric = options.delete(:metric) || EMPTY_STRING
250
+ error_metric = options.delete(:metric) || NewRelic::EMPTY_STR
234
251
 
235
252
  noticed_error = NewRelic::NoticedError.new(error_metric, exception)
236
- noticed_error.request_uri = options.delete(:uri) || EMPTY_STRING
253
+ noticed_error.request_uri = options.delete(:uri) || NewRelic::EMPTY_STR
237
254
  noticed_error.request_port = options.delete(:port)
238
255
  noticed_error.attributes = options.delete(:attributes)
239
256
 
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
  # This file is distributed under New Relic's license terms.
4
4
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
5
+ # frozen_string_literal: true
5
6
 
6
7
  require 'new_relic/agent/event_aggregator'
7
8
  require 'new_relic/agent/transaction_error_primitive'
@@ -10,20 +11,22 @@ require 'new_relic/agent/priority_sampled_buffer'
10
11
  module NewRelic
11
12
  module Agent
12
13
  class ErrorEventAggregator < EventAggregator
14
+ include NewRelic::Coerce
13
15
 
14
16
  named :ErrorEventAggregator
15
17
  capacity_key :'error_collector.max_event_samples_stored'
16
- enabled_key :'error_collector.capture_events'
18
+ enabled_keys :'error_collector.enabled',
19
+ :'error_collector.capture_events'
17
20
  buffer_class PrioritySampledBuffer
18
21
 
19
- def record noticed_error, transaction_payload = nil
22
+ def record noticed_error, transaction_payload = nil, span_id = nil
20
23
  return unless enabled?
21
24
 
22
- priority = (transaction_payload && transaction_payload[:priority]) || rand.round(6)
25
+ priority = float!((transaction_payload && transaction_payload[:priority]) || rand)
23
26
 
24
27
  @lock.synchronize do
25
28
  @buffer.append(priority: priority) do
26
- create_event(noticed_error, transaction_payload)
29
+ create_event(noticed_error, transaction_payload, span_id)
27
30
  end
28
31
  notify_if_full
29
32
  end
@@ -31,8 +34,8 @@ module NewRelic
31
34
 
32
35
  private
33
36
 
34
- def create_event noticed_error, transaction_payload
35
- TransactionErrorPrimitive.create noticed_error, transaction_payload
37
+ def create_event noticed_error, transaction_payload, span_id
38
+ TransactionErrorPrimitive.create noticed_error, transaction_payload, span_id
36
39
  end
37
40
  end
38
41
  end
@@ -91,6 +91,7 @@ module NewRelic
91
91
 
92
92
  def register_config_callbacks
93
93
  Agent.config.register_callback(:'error_collector.enabled') do |enabled|
94
+ reset! if enabled == false
94
95
  ::NewRelic::Agent.logger.debug "Error traces will #{enabled ? '' : 'not '}be sent to the New Relic service."
95
96
  end
96
97
  end
@@ -8,20 +8,6 @@ module NewRelic
8
8
  module Agent
9
9
  class EventAggregator
10
10
  class << self
11
- # This architecture requires that every aggregator
12
- # implementation provide its own `named`, `capacity_key`, and
13
- # `enabled_...` settings. In particular, we do not allow
14
- # subclasses to share these values from an intermediate
15
- # superclass.
16
-
17
- def inherited(subclass)
18
- # Prevent uninitialized variable warnings; we have to do
19
- # this as soon as the subclass is defined, before its
20
- # implementor calls enabled_key() or enabled_fn().
21
- subclass.instance_variable_set(:@enabled_key, nil)
22
- subclass.instance_variable_set(:@enabled_fn, nil)
23
- end
24
-
25
11
  def named named = nil
26
12
  named ? @named = named.to_s.freeze : @named
27
13
  end
@@ -30,10 +16,25 @@ module NewRelic
30
16
  key ? @capacity_key = key : @capacity_key
31
17
  end
32
18
 
33
- def enabled_key key = nil
34
- key ? @enabled_key = key : @enabled_key
19
+ # An aggregator can specify one or more keys to check to see if it is
20
+ # enabled. Multiple keys will be &&'d and the enabled status of the
21
+ # aggregator will be reset when agent configuration changes.
22
+
23
+ def enabled_keys *keys
24
+ if keys.empty?
25
+ @enabled_keys ||= []
26
+ else
27
+ @enabled_keys = Array(keys)
28
+ @enabled_fn = ->(){ @enabled_keys.all? { |k| Agent.config[k] } }
29
+ end
35
30
  end
36
31
 
32
+ alias_method :enabled_key, :enabled_keys
33
+
34
+ # This can be used instead of `enabled_key(s)` for more fine grained
35
+ # control over whether an aggregator should be enabled. The enabled fn
36
+ # will be reevaluated after configuration changes
37
+
37
38
  def enabled_fn fn = nil
38
39
  fn ? @enabled_fn = fn : @enabled_fn
39
40
  end
@@ -47,13 +48,13 @@ module NewRelic
47
48
  end
48
49
  end
49
50
 
50
- def initialize
51
+ def initialize events
51
52
  @lock = Mutex.new
52
53
  @buffer = self.class.buffer_class.new NewRelic::Agent.config[self.class.capacity_key]
53
- @enabled = false
54
+ @enabled = self.class.enabled_fn ? self.class.enabled_fn.call : false
54
55
  @notified_full = false
55
56
  register_capacity_callback
56
- register_enabled_callback
57
+ register_enabled_callback events
57
58
  after_initialize
58
59
  end
59
60
 
@@ -66,7 +67,6 @@ module NewRelic
66
67
  end
67
68
 
68
69
  def enabled?
69
- return self.class.enabled_fn.call if self.class.enabled_fn
70
70
  @enabled
71
71
  end
72
72
 
@@ -126,18 +126,12 @@ module NewRelic
126
126
  end
127
127
  end
128
128
 
129
- def register_enabled_callback
130
- unless self.class.enabled_key || self.class.enabled_fn
131
- ::NewRelic::Agent.logger.warn "#{self.class.named} needs an enabled_key or an enabled_fn."
132
- end
133
-
134
- return if self.class.enabled_fn
135
-
136
- NewRelic::Agent.config.register_callback(self.class.enabled_key) do |enabled|
137
- # intentionally unsynchronized for liveness
138
- @enabled = enabled
139
- ::NewRelic::Agent.logger.debug "#{self.class.named} will #{enabled ? '' : 'not '}be sent to the New Relic service."
140
- end
129
+ def register_enabled_callback events
130
+ events.subscribe(:server_source_configuration_added) {
131
+ @enabled = self.class.enabled_fn.call
132
+ reset! if @enabled == false
133
+ ::NewRelic::Agent.logger.debug "#{self.class.named} will #{@enabled ? '' : 'not '}be sent to the New Relic service."
134
+ }
141
135
  end
142
136
 
143
137
  def notify_if_full
@@ -3,8 +3,8 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require 'new_relic/agent/transaction/tracing'
6
- require 'new_relic/agent/cross_app_tracing'
7
- require 'new_relic/agent/cross_app_payload'
6
+ require 'new_relic/agent/distributed_tracing/cross_app_tracing'
7
+ require 'new_relic/agent/distributed_tracing/cross_app_payload'
8
8
 
9
9
  module NewRelic
10
10
  module Agent
@@ -78,7 +78,7 @@ module NewRelic
78
78
  #
79
79
  if txn_info = rmd[NON_HTTP_CAT_TXN_HEADER]
80
80
  payload = CrossAppPayload.new(id, transaction, txn_info)
81
- transaction.cross_app_payload = payload
81
+ transaction.distributed_tracer.cross_app_payload = payload
82
82
 
83
83
  CrossAppTracing.assign_intrinsic_transaction_attributes state
84
84
  end
@@ -112,16 +112,16 @@ module NewRelic
112
112
  NewRelic::Agent.record_api_supportability_metric(:get_response_metadata)
113
113
  return unless CrossAppTracing.cross_app_enabled?
114
114
 
115
- return unless (transaction = Tracer.current_transaction)
116
- return unless (cross_app_payload = transaction.cross_app_payload)
115
+ return unless (txn = Tracer.current_transaction)
116
+ return unless (payload = txn.distributed_tracer.cross_app_payload)
117
117
 
118
118
  # must freeze the name since we're responding with it
119
119
  #
120
- transaction.freeze_name_and_execute_if_not_ignored do
120
+ txn.freeze_name_and_execute_if_not_ignored do
121
121
  # build response payload
122
122
  #
123
123
  rmd = {
124
- NewRelicAppData: cross_app_payload.as_json_array(NON_HTTP_CAT_CONTENT_LENGTH)
124
+ NewRelicAppData: payload.as_json_array(NON_HTTP_CAT_CONTENT_LENGTH)
125
125
  }
126
126
 
127
127
  # obfuscate the generated response metadata JSON
@@ -0,0 +1,28 @@
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 GuidGenerator
8
+
9
+ HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
10
+
11
+ module_function
12
+
13
+ # This method intentionally does not use SecureRandom, because it relies
14
+ # on urandom, which raises an exception in MRI when the interpreter runs
15
+ # out of allocated file descriptors.
16
+ # The guids generated by this method may not be _secure_, but they are
17
+ # random enough for our purposes.
18
+ def generate_guid length = 16
19
+ guid = ''
20
+ length.times do |a|
21
+ guid << HEX_DIGITS[rand(16)]
22
+ end
23
+ guid
24
+ end
25
+
26
+ end
27
+ end
28
+ end