newrelic_rpm 8.11.0 → 8.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -3
  3. data/.rubocop_todo.yml +14 -7
  4. data/Brewfile +1 -0
  5. data/CHANGELOG.md +78 -16
  6. data/README.md +1 -1
  7. data/bin/nrdebug +2 -0
  8. data/docker-compose.yml +22 -0
  9. data/lib/new_relic/agent/agent/shutdown.rb +1 -0
  10. data/lib/new_relic/agent/agent/special_startup.rb +2 -0
  11. data/lib/new_relic/agent/agent/startup.rb +1 -0
  12. data/lib/new_relic/agent/agent_logger.rb +1 -1
  13. data/lib/new_relic/agent/attributes.rb +1 -0
  14. data/lib/new_relic/agent/audit_logger.rb +2 -1
  15. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -0
  16. data/lib/new_relic/agent/configuration/default_source.rb +1415 -1359
  17. data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -0
  18. data/lib/new_relic/agent/configuration/environment_source.rb +3 -2
  19. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  20. data/lib/new_relic/agent/configuration/manager.rb +3 -0
  21. data/lib/new_relic/agent/configuration/security_policy_source.rb +10 -0
  22. data/lib/new_relic/agent/configuration/yaml_source.rb +1 -0
  23. data/lib/new_relic/agent/connect/request_builder.rb +1 -0
  24. data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -0
  25. data/lib/new_relic/agent/database.rb +7 -0
  26. data/lib/new_relic/agent/database_adapter.rb +2 -0
  27. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +3 -2
  28. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
  29. data/lib/new_relic/agent/datastores/nosql_obfuscator.rb +41 -0
  30. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +3 -0
  31. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +3 -0
  32. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +1 -0
  33. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +1 -0
  34. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +1 -0
  35. data/lib/new_relic/agent/encoding_normalizer.rb +2 -0
  36. data/lib/new_relic/agent/error_collector.rb +3 -0
  37. data/lib/new_relic/agent/error_filter.rb +1 -0
  38. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -0
  39. data/lib/new_relic/agent/event_aggregator.rb +1 -0
  40. data/lib/new_relic/agent/event_loop.rb +2 -0
  41. data/lib/new_relic/agent/http_clients/abstract.rb +2 -0
  42. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +1 -1
  43. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +1 -1
  44. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -0
  45. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -2
  46. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +2 -0
  47. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -2
  48. data/lib/new_relic/agent/instrumentation/authlogic.rb +0 -2
  49. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -0
  50. data/lib/new_relic/agent/instrumentation/data_mapper.rb +0 -1
  51. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -2
  52. data/lib/new_relic/agent/instrumentation/elasticsearch/chain.rb +29 -0
  53. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +66 -0
  54. data/lib/new_relic/agent/instrumentation/elasticsearch/prepend.rb +13 -0
  55. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +31 -0
  56. data/lib/new_relic/agent/instrumentation/excon.rb +17 -0
  57. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +1 -0
  58. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +4 -0
  59. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +2 -0
  60. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +2 -0
  61. data/lib/new_relic/agent/instrumentation/rack/chain.rb +10 -2
  62. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +3 -0
  63. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +9 -2
  64. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +0 -1
  65. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +1 -0
  66. data/lib/new_relic/agent/instrumentation/redis/chain.rb +18 -6
  67. data/lib/new_relic/agent/instrumentation/redis/constants.rb +17 -0
  68. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +28 -18
  69. data/lib/new_relic/agent/instrumentation/redis/middleware.rb +16 -0
  70. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +6 -0
  71. data/lib/new_relic/agent/instrumentation/redis.rb +6 -0
  72. data/lib/new_relic/agent/instrumentation/sidekiq/client.rb +20 -0
  73. data/lib/new_relic/agent/instrumentation/sidekiq/extensions/delayed_class.rb +30 -0
  74. data/lib/new_relic/agent/instrumentation/sidekiq/server.rb +37 -0
  75. data/lib/new_relic/agent/instrumentation/sidekiq.rb +7 -70
  76. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -2
  77. data/lib/new_relic/agent/instrumentation/sunspot.rb +0 -2
  78. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -0
  79. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +1 -0
  80. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -0
  81. data/lib/new_relic/agent/local_log_decorator.rb +1 -0
  82. data/lib/new_relic/agent/log_event_aggregator.rb +1 -0
  83. data/lib/new_relic/agent/messaging.rb +1 -0
  84. data/lib/new_relic/agent/method_tracer.rb +4 -0
  85. data/lib/new_relic/agent/method_tracer_helpers.rb +1 -1
  86. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +1 -0
  87. data/lib/new_relic/agent/new_relic_service.rb +2 -0
  88. data/lib/new_relic/agent/parameter_filtering.rb +7 -1
  89. data/lib/new_relic/agent/pipe_channel_manager.rb +2 -0
  90. data/lib/new_relic/agent/rules_engine.rb +1 -0
  91. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -0
  92. data/lib/new_relic/agent/samplers/memory_sampler.rb +5 -0
  93. data/lib/new_relic/agent/span_event_primitive.rb +1 -0
  94. data/lib/new_relic/agent/stats.rb +1 -0
  95. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -0
  96. data/lib/new_relic/agent/system_info.rb +3 -0
  97. data/lib/new_relic/agent/threading/agent_thread.rb +1 -0
  98. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -0
  99. data/lib/new_relic/agent/threading/thread_profile.rb +3 -0
  100. data/lib/new_relic/agent/tracer.rb +5 -1
  101. data/lib/new_relic/agent/transaction/abstract_segment.rb +3 -0
  102. data/lib/new_relic/agent/transaction/datastore_segment.rb +3 -0
  103. data/lib/new_relic/agent/transaction/distributed_tracer.rb +4 -0
  104. data/lib/new_relic/agent/transaction/distributed_tracing.rb +1 -0
  105. data/lib/new_relic/agent/transaction/external_request_segment.rb +1 -0
  106. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -0
  107. data/lib/new_relic/agent/transaction/segment.rb +1 -0
  108. data/lib/new_relic/agent/transaction/trace.rb +4 -0
  109. data/lib/new_relic/agent/transaction/trace_node.rb +1 -0
  110. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +2 -0
  111. data/lib/new_relic/agent/transaction.rb +10 -0
  112. data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -0
  113. data/lib/new_relic/agent/transaction_time_aggregator.rb +1 -0
  114. data/lib/new_relic/agent/utilization/pcf.rb +1 -0
  115. data/lib/new_relic/agent/utilization/vendor.rb +2 -0
  116. data/lib/new_relic/agent/utilization_data.rb +3 -0
  117. data/lib/new_relic/agent.rb +4 -2
  118. data/lib/new_relic/cli/commands/install.rb +1 -0
  119. data/lib/new_relic/coerce.rb +6 -0
  120. data/lib/new_relic/collection_helper.rb +1 -0
  121. data/lib/new_relic/constants.rb +2 -0
  122. data/lib/new_relic/control/frameworks/rails.rb +5 -0
  123. data/lib/new_relic/control/instrumentation.rb +6 -8
  124. data/lib/new_relic/dependency_detection.rb +2 -0
  125. data/lib/new_relic/helper.rb +1 -0
  126. data/lib/new_relic/language_support.rb +1 -0
  127. data/lib/new_relic/latest_changes.rb +1 -0
  128. data/lib/new_relic/local_environment.rb +7 -1
  129. data/lib/new_relic/metric_spec.rb +2 -0
  130. data/lib/new_relic/rack/agent_middleware.rb +2 -0
  131. data/lib/new_relic/rack/browser_monitoring.rb +1 -0
  132. data/lib/new_relic/traced_thread.rb +1 -0
  133. data/lib/new_relic/version.rb +1 -1
  134. data/lib/tasks/helpers/format.rb +3 -0
  135. data/lib/tasks/helpers/prompt.rb +1 -1
  136. data/lib/tasks/instrumentation_generator/README.md +2 -2
  137. data/lib/tasks/instrumentation_generator/TODO.md +5 -5
  138. data/lib/tasks/instrumentation_generator/instrumentation.thor +27 -5
  139. data/lib/tasks/instrumentation_generator/templates/chain.tt +2 -1
  140. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +3 -2
  141. data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +2 -1
  142. data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +1 -1
  143. data/lib/tasks/instrumentation_generator/templates/prepend.tt +1 -1
  144. data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +1 -1
  145. data/lib/tasks/instrumentation_generator/templates/test.tt +1 -1
  146. data/newrelic.yml +13 -3
  147. data/newrelic_rpm.gemspec +7 -7
  148. data/test/agent_helper.rb +24 -0
  149. metadata +18 -79
  150. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +0 -43
@@ -29,6 +29,7 @@ module NewRelic
29
29
 
30
30
  def escape_entity_name(entity_name)
31
31
  return unless entity_name
32
+
32
33
  URI::DEFAULT_PARSER.escape(entity_name)
33
34
  end
34
35
  end
@@ -227,6 +227,7 @@ module NewRelic
227
227
 
228
228
  def truncate_message(message)
229
229
  return message if message.bytesize <= MAX_BYTES
230
+
230
231
  message.byteslice(0...MAX_BYTES)
231
232
  end
232
233
  end
@@ -121,6 +121,7 @@ module NewRelic
121
121
 
122
122
  state = Tracer.state
123
123
  return yield if state.current_transaction
124
+
124
125
  txn = nil
125
126
 
126
127
  begin
@@ -86,6 +86,7 @@ module NewRelic
86
86
  def trace_execution_unscoped(metric_names, options = NewRelic::EMPTY_HASH) # THREAD_LOCAL_ACCESS
87
87
  NewRelic::Agent.record_api_supportability_metric(:trace_execution_unscoped) unless options[:internal]
88
88
  return yield unless NewRelic::Agent.tl_is_execution_traced?
89
+
89
90
  t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
90
91
  begin
91
92
  yield
@@ -251,6 +252,7 @@ module NewRelic
251
252
  # may get removed as well.
252
253
  def remove_method_tracer(method_name) # :nodoc:
253
254
  return unless Agent.config[:agent_enabled]
255
+
254
256
  if _nr_traced_method_module.method_defined?(method_name)
255
257
  _nr_traced_method_module.send(:remove_method, method_name)
256
258
  ::NewRelic::Agent.logger.debug("removed method tracer #{method_name}\n")
@@ -264,6 +266,7 @@ module NewRelic
264
266
  def _nr_add_method_tracer_now(method_name, metric_name, options)
265
267
  NewRelic::Agent.record_api_supportability_metric(:add_method_tracer)
266
268
  return unless newrelic_method_exists?(method_name)
269
+
267
270
  remove_method_tracer(method_name) if method_traced?(method_name)
268
271
 
269
272
  options = _nr_validate_method_tracer_options(method_name, options)
@@ -304,6 +307,7 @@ module NewRelic
304
307
  _nr_traced_method_module.module_eval do
305
308
  define_method(method_name) do |*args, &block|
306
309
  return super(*args, &block) unless NewRelic::Agent.tl_is_execution_traced?
310
+
307
311
  scoped_metric_eval, unscoped_metrics_eval = nil, []
308
312
 
309
313
  scoped_metric_eval = case scoped_metric
@@ -106,7 +106,7 @@ module NewRelic
106
106
  klass = object.singleton_class? ? klassify_singleton(object) : object
107
107
  name = klass.name || '(Anonymous)'
108
108
  is_class_method = false
109
- method = if klass.instance_methods.include?(method_name)
109
+ method = if (klass.instance_methods + klass.private_instance_methods).include?(method_name)
110
110
  klass.instance_method(method_name)
111
111
  else
112
112
  is_class_method = true
@@ -8,6 +8,7 @@ module NewRelic
8
8
  class Monitor < InboundRequestMonitor
9
9
  def on_finished_configuring(events)
10
10
  return unless NewRelic::Agent.config[:'distributed_tracing.enabled']
11
+
11
12
  events.subscribe(:before_call, &method(:on_before_call))
12
13
  end
13
14
 
@@ -524,6 +524,7 @@ module NewRelic
524
524
  uri = String.new('/agent_listener/invoke_raw_method?')
525
525
  uri << params.map do |k, v|
526
526
  next unless v
527
+
527
528
  "#{k}=#{v}"
528
529
  end.compact.join('&')
529
530
  uri
@@ -592,6 +593,7 @@ module NewRelic
592
593
  # than the limit configured in the control object
593
594
  def check_post_size(post_string, endpoint)
594
595
  return if post_string.size < Agent.config[:max_payload_size_in_bytes]
596
+
595
597
  ::NewRelic::Agent.logger.debug("Tried to send too much data: #{post_string.size} bytes")
596
598
  NewRelic::Agent.increment_metric("Supportability/Agent/Collector/#{endpoint}/MaxPayloadSizeLimit")
597
599
  raise UnrecoverableServerException.new('413 Request Entity Too Large')
@@ -34,7 +34,7 @@ module NewRelic
34
34
  end
35
35
 
36
36
  def filter_using_rails(params, filters)
37
- return params if RAILS_FILTER_CLASS.nil?
37
+ return params unless rails_filter_class?
38
38
 
39
39
  pre_filtered_params = filter_rails_request_parameters(params)
40
40
  RAILS_FILTER_CLASS.new(filters).filter(pre_filtered_params)
@@ -60,6 +60,12 @@ module NewRelic
60
60
  result.delete("action")
61
61
  result
62
62
  end
63
+
64
+ private
65
+
66
+ def rails_filter_class?
67
+ defined?(RAILS_FILTER_CLASS) && !RAILS_FILTER_CLASS.nil?
68
+ end
63
69
  end
64
70
  end
65
71
  end
@@ -160,6 +160,7 @@ module NewRelic
160
160
 
161
161
  def start
162
162
  return if @started == true
163
+
163
164
  @started = true
164
165
  @thread = NewRelic::Agent::Threading::AgentThread.create('Pipe Channel Manager') do
165
166
  now = nil
@@ -207,6 +208,7 @@ module NewRelic
207
208
 
208
209
  def stop
209
210
  return unless @started == true
211
+
210
212
  stop_listener_thread
211
213
  close_all_pipes
212
214
  @wake.close
@@ -72,6 +72,7 @@ module NewRelic
72
72
  def rename(original_string)
73
73
  renamed = apply_rules(@rules, original_string)
74
74
  return nil unless renamed
75
+
75
76
  renamed = apply_rules(@segment_term_rules, renamed)
76
77
  renamed
77
78
  end
@@ -44,6 +44,7 @@ module NewRelic
44
44
  if defined?(JRuby)
45
45
  return JRUBY_VERSION >= '1.7.0'
46
46
  end
47
+
47
48
  true
48
49
  end
49
50
 
@@ -75,12 +75,14 @@ module NewRelic
75
75
 
76
76
  def can_run?
77
77
  return false if @broken
78
+
78
79
  m = get_memory rescue nil
79
80
  m && m > 0
80
81
  end
81
82
 
82
83
  def get_sample
83
84
  return nil if @broken
85
+
84
86
  begin
85
87
  m = get_memory
86
88
  if m.nil?
@@ -99,6 +101,7 @@ module NewRelic
99
101
  class JavaHeapSampler < Base
100
102
  def get_memory
101
103
  raise "Can't sample Java heap unless running in JRuby" unless defined? JRuby
104
+
102
105
  java.lang.Runtime.getRuntime.totalMemory / (1024 * 1024).to_f rescue nil
103
106
  end
104
107
 
@@ -121,6 +124,7 @@ module NewRelic
121
124
  # if for some reason the ps command doesn't work on the resident os,
122
125
  # then don't execute it any more.
123
126
  raise "Faulty command: `#{@command} #{process}`" if memory.nil? || memory <= 0
127
+
124
128
  memory
125
129
  end
126
130
 
@@ -140,6 +144,7 @@ module NewRelic
140
144
  if proc_status =~ /RSS:\s*(\d+) kB/i
141
145
  return $1.to_f / 1024.0
142
146
  end
147
+
143
148
  raise "Unable to find RSS in #{proc_status_file}"
144
149
  end
145
150
 
@@ -52,6 +52,7 @@ module NewRelic
52
52
  # an error is present. Otherwise, returns nil when no error present.
53
53
  def error_attributes(segment)
54
54
  return if Agent.config[:high_security] || !segment.noticed_error
55
+
55
56
  segment.noticed_error.build_error_attributes
56
57
  segment.noticed_error_attributes
57
58
  end
@@ -159,6 +159,7 @@ module NewRelic
159
159
  def marshal_dump
160
160
  instance_variables.each_with_object({}) do |name, instance_copy|
161
161
  next if SKIP_MARSHALLING.include?(name)
162
+
162
163
  instance_copy[name] = instance_variable_get(name)
163
164
  end
164
165
  end
@@ -11,6 +11,7 @@ module NewRelic
11
11
  def self.init
12
12
  @initialized ||= nil
13
13
  return @profiler if @initialized
14
+
14
15
  @profiler = if RailsBenchProfiler.enabled?
15
16
  RailsBenchProfiler.new
16
17
  elsif CoreGCProfiler.enabled?
@@ -224,6 +224,7 @@ module NewRelic
224
224
  cgroup_info.split("\n").each do |line|
225
225
  parts = line.split(':')
226
226
  next unless parts.size == 3
227
+
227
228
  _, subsystems, cgroup_id = parts
228
229
  subsystems = subsystems.split(',')
229
230
  subsystems.each do |subsystem|
@@ -240,6 +241,7 @@ module NewRelic
240
241
  # for details on why we do it this way.
241
242
  def self.proc_try_read(path)
242
243
  return nil unless File.exist?(path)
244
+
243
245
  content = String.new('')
244
246
  File.open(path) do |f|
245
247
  loop do
@@ -281,6 +283,7 @@ module NewRelic
281
283
 
282
284
  def self.boot_id
283
285
  return nil unless linux?
286
+
284
287
  if bid = proc_try_read('/proc/sys/kernel/random/boot_id')
285
288
  bid.chomp!
286
289
 
@@ -60,6 +60,7 @@ module NewRelic
60
60
  ::NewRelic::Agent.logger.debug("Failed to backtrace #{thread.inspect}: #{e.class.name}: #{e.to_s}")
61
61
  end
62
62
  return nil unless bt
63
+
63
64
  bt.reject! { |t| t.include?('/newrelic_rpm-') } unless profile_agent_code
64
65
  bt
65
66
  end
@@ -151,6 +151,7 @@ module NewRelic
151
151
  # This method is expected to be called with @lock held
152
152
  def stop
153
153
  return unless @running
154
+
154
155
  @running = false
155
156
  self.worker_loop.stop
156
157
 
@@ -54,6 +54,7 @@ module NewRelic
54
54
 
55
55
  def unique_thread_count
56
56
  return 0 if @unique_threads.nil?
57
+
57
58
  @unique_threads.length
58
59
  end
59
60
 
@@ -84,10 +85,12 @@ module NewRelic
84
85
 
85
86
  all_nodes.each_with_index do |n, i|
86
87
  break if i >= count_to_keep
88
+
87
89
  n.mark_for_array_conversion
88
90
  end
89
91
  all_nodes.each_with_index do |n, i|
90
92
  break if i >= count_to_keep
93
+
91
94
  n.complete_array_conversion
92
95
  end
93
96
  end
@@ -87,7 +87,7 @@ module NewRelic
87
87
  # @api public
88
88
  def in_transaction(name: nil,
89
89
  partial_name: nil,
90
- category: nil,
90
+ category:,
91
91
  options: {})
92
92
 
93
93
  finishable = start_transaction_or_segment(
@@ -187,11 +187,13 @@ module NewRelic
187
187
 
188
188
  def create_distributed_trace_payload
189
189
  return unless txn = current_transaction
190
+
190
191
  txn.distributed_tracer.create_distributed_trace_payload
191
192
  end
192
193
 
193
194
  def accept_distributed_trace_payload(payload)
194
195
  return unless txn = current_transaction
196
+
195
197
  txn.distributed_tracer.accept_distributed_trace_payload(payload)
196
198
  end
197
199
 
@@ -202,6 +204,7 @@ module NewRelic
202
204
  # @api public
203
205
  def current_segment
204
206
  return unless txn = current_transaction
207
+
205
208
  txn.current_segment
206
209
  end
207
210
 
@@ -348,6 +351,7 @@ module NewRelic
348
351
  # is effectively just a yield to the given &block
349
352
  def capture_segment_error(segment)
350
353
  return unless block_given?
354
+
351
355
  yield
352
356
  rescue => exception
353
357
  if segment && segment.is_a?(Transaction::AbstractSegment)
@@ -55,6 +55,7 @@ module NewRelic
55
55
  def start
56
56
  @start_time ||= Process.clock_gettime(Process::CLOCK_REALTIME)
57
57
  return unless transaction
58
+
58
59
  parent.child_start(self) if parent
59
60
  end
60
61
 
@@ -63,6 +64,7 @@ module NewRelic
63
64
  @duration = end_time - start_time
64
65
 
65
66
  return unless transaction
67
+
66
68
  run_complete_callbacks
67
69
  finalize if record_on_finish?
68
70
  rescue => e
@@ -201,6 +203,7 @@ module NewRelic
201
203
 
202
204
  def noticed_error_attributes
203
205
  return unless @noticed_error
206
+
204
207
  @noticed_error.attributes_from_notice_error
205
208
  end
206
209
 
@@ -63,6 +63,7 @@ module NewRelic
63
63
  # @api private
64
64
  def _notice_sql(sql, config = nil, explainer = nil, binds = nil, name = nil)
65
65
  return unless record_sql?
66
+
66
67
  @sql_statement = Database::Statement.new(sql, config, explainer, binds, name, host, port_path_or_id, database_name)
67
68
  end
68
69
 
@@ -85,6 +86,7 @@ module NewRelic
85
86
 
86
87
  def notice_nosql_statement(nosql_statement)
87
88
  return unless record_sql?
89
+
88
90
  @nosql_statement = Database.truncate_query(nosql_statement)
89
91
  nil
90
92
  end
@@ -119,6 +121,7 @@ module NewRelic
119
121
 
120
122
  def add_backtrace_parameter
121
123
  return unless duration >= Agent.config[:'transaction_tracer.stack_trace_threshold']
124
+
122
125
  params[:backtrace] = caller.join(NEWLINE)
123
126
  end
124
127
 
@@ -74,6 +74,7 @@ module NewRelic
74
74
 
75
75
  def insert_headers(headers)
76
76
  return unless NewRelic::Agent.agent.connected?
77
+
77
78
  insert_trace_context_header(headers)
78
79
  insert_distributed_trace_header(headers)
79
80
  insert_cross_app_header(headers)
@@ -100,12 +101,14 @@ module NewRelic
100
101
  def insert_distributed_trace_header(headers)
101
102
  return unless dt_enabled?
102
103
  return if Agent.config[:'exclude_newrelic_header']
104
+
103
105
  payload = create_distributed_trace_payload
104
106
  headers[NewRelic::NEWRELIC_KEY] = payload.http_safe if payload
105
107
  end
106
108
 
107
109
  def insert_cat_headers(headers)
108
110
  return unless CrossAppTracing.cross_app_enabled?
111
+
109
112
  @is_cross_app_caller = true
110
113
  insert_message_headers(headers,
111
114
  transaction.guid,
@@ -161,6 +164,7 @@ module NewRelic
161
164
  decoded_id = encoded_id.nil? ? EMPTY_STRING : deobfuscate(encoded_id)
162
165
 
163
166
  return unless CrossAppTracing.trusted_valid_cross_app_id?(decoded_id)
167
+
164
168
  txn_header = headers[CrossAppTracing::NR_MESSAGE_BROKER_TXN_HEADER]
165
169
  txn_info = ::JSON.load(deobfuscate(txn_header))
166
170
  payload = CrossAppPayload.new(decoded_id, transaction, txn_info)
@@ -156,6 +156,7 @@ module NewRelic
156
156
  def assign_payload_and_sampling_params(payload)
157
157
  @distributed_trace_payload = payload
158
158
  return if transaction.distributed_tracer.trace_context_header_data
159
+
159
160
  transaction.trace_id = payload.trace_id
160
161
  transaction.distributed_tracer.parent_transaction_id = payload.transaction_id
161
162
  transaction.parent_span_id = payload.id
@@ -82,6 +82,7 @@ module NewRelic
82
82
  def read_response_headers(response)
83
83
  return unless record_metrics? && CrossAppTracing.cross_app_enabled?
84
84
  return unless CrossAppTracing.response_has_crossapp_header?(response)
85
+
85
86
  unless data = CrossAppTracing.extract_appdata(response)
86
87
  NewRelic::Agent.logger.debug("Couldn't extract_appdata from external segment response")
87
88
  return
@@ -71,6 +71,7 @@ module NewRelic
71
71
 
72
72
  def name
73
73
  return @name if @name
74
+
74
75
  @name = METRIC_PREFIX + library
75
76
  @name << SLASH << TYPES[destination_type] << SLASH << ACTIONS[action] << SLASH
76
77
 
@@ -38,6 +38,7 @@ module NewRelic
38
38
 
39
39
  def merge_untrusted_agent_attributes(agent_attributes, prefix, default_destinations)
40
40
  return if agent_attributes.nil?
41
+
41
42
  attributes.merge_untrusted_agent_attributes(agent_attributes, prefix, default_destinations)
42
43
  end
43
44
 
@@ -31,6 +31,7 @@ module NewRelic
31
31
  node_count = 0
32
32
  each_node do |node|
33
33
  next if node == root_node
34
+
34
35
  node_count += 1
35
36
  end
36
37
  node_count
@@ -51,6 +52,7 @@ module NewRelic
51
52
 
52
53
  def create_node(time_since_start, metric_name = nil)
53
54
  raise FinishedTraceError.new("Can't create additional node for finished trace.") if self.finished
55
+
54
56
  self.node_count += 1
55
57
  NewRelic::Agent::Transaction::TraceNode.new(metric_name, time_since_start)
56
58
  end
@@ -75,6 +77,7 @@ module NewRelic
75
77
 
76
78
  def collect_explain_plans!
77
79
  return unless NewRelic::Agent::Database.should_collect_explain_plans?
80
+
78
81
  threshold = NewRelic::Agent.config[:'transaction_tracer.explain_threshold']
79
82
 
80
83
  each_node do |node|
@@ -87,6 +90,7 @@ module NewRelic
87
90
  def prepare_sql_for_transmission!
88
91
  each_node do |node|
89
92
  next unless node[:sql]
93
+
90
94
  node[:sql] = node[:sql].safe_sql
91
95
  end
92
96
  end
@@ -28,6 +28,7 @@ module NewRelic
28
28
 
29
29
  def select_allowed_params(params)
30
30
  return unless params
31
+
31
32
  params.select do |p|
32
33
  NewRelic::Agent.instance.attribute_filter.allows_key?(p, AttributeFilter::DST_TRANSACTION_SEGMENTS)
33
34
  end
@@ -34,6 +34,7 @@ module NewRelic
34
34
 
35
35
  def store(sample)
36
36
  return unless enabled?
37
+
37
38
  if allow_sample?(sample)
38
39
  add_sample(sample)
39
40
  truncate_samples_if_needed
@@ -42,6 +43,7 @@ module NewRelic
42
43
 
43
44
  def store_previous(previous_samples)
44
45
  return unless enabled?
46
+
45
47
  previous_samples.each do |sample|
46
48
  add_sample(sample) if allow_sample?(sample)
47
49
  end
@@ -268,6 +268,7 @@ module NewRelic
268
268
  current_thread_id = ::Thread.current.object_id
269
269
  return current_segment_by_thread[current_thread_id] if current_segment_by_thread[current_thread_id]
270
270
  return current_segment_by_thread[parent_thread_id] if current_segment_by_thread[parent_thread_id]
271
+
271
272
  current_segment_by_thread[@starting_thread_id]
272
273
  end
273
274
 
@@ -285,6 +286,7 @@ module NewRelic
285
286
 
286
287
  def sampled?
287
288
  return unless Agent.config[:'distributed_tracing.enabled']
289
+
288
290
  if @sampled.nil?
289
291
  @sampled = NewRelic::Agent.instance.adaptive_sampler.sampled?
290
292
  end
@@ -347,6 +349,7 @@ module NewRelic
347
349
 
348
350
  def set_default_transaction_name(name, category)
349
351
  return log_frozen_name(name) if name_frozen?
352
+
350
353
  if influences_transaction_name?(category)
351
354
  self.default_name = name
352
355
  @category = category if category
@@ -355,6 +358,7 @@ module NewRelic
355
358
 
356
359
  def set_overriding_transaction_name(name, category)
357
360
  return log_frozen_name(name) if name_frozen?
361
+
358
362
  if influences_transaction_name?(category)
359
363
  self.overridden_name = name
360
364
  @category = category if category
@@ -510,6 +514,7 @@ module NewRelic
510
514
 
511
515
  def finish
512
516
  return unless state.is_execution_traced?
517
+
513
518
  @end_time = Process.clock_gettime(Process::CLOCK_REALTIME)
514
519
  @duration = @end_time - @start_time
515
520
  freeze_name_and_execute_if_not_ignored
@@ -879,11 +884,13 @@ module NewRelic
879
884
 
880
885
  def normal_cpu_burn
881
886
  return unless @process_cpu_start
887
+
882
888
  process_cpu - @process_cpu_start
883
889
  end
884
890
 
885
891
  def jruby_cpu_burn
886
892
  return unless @jruby_cpu_start
893
+
887
894
  jruby_cpu_time - @jruby_cpu_start
888
895
  end
889
896
 
@@ -919,15 +926,18 @@ module NewRelic
919
926
 
920
927
  def process_cpu
921
928
  return nil if defined? JRuby
929
+
922
930
  p = Process.times
923
931
  p.stime + p.utime
924
932
  end
925
933
 
926
934
  def jruby_cpu_time
927
935
  return nil unless @@java_classes_loaded
936
+
928
937
  threadMBean = Java::JavaLangManagement::ManagementFactory.getThreadMXBean()
929
938
 
930
939
  return nil unless threadMBean.isCurrentThreadCpuTimeSupported
940
+
931
941
  java_utime = threadMBean.getCurrentThreadUserTime() # ns
932
942
 
933
943
  -1 == java_utime ? 0.0 : java_utime / 1e9
@@ -33,6 +33,7 @@ module NewRelic
33
33
 
34
34
  def after_harvest(metadata)
35
35
  return unless enabled?
36
+
36
37
  record_sampling_rate(metadata)
37
38
  end
38
39
 
@@ -127,6 +127,7 @@ module NewRelic
127
127
 
128
128
  def split_transaction_at_harvest(timestamp, thread_id = nil)
129
129
  raise ArgumentError, 'thread_id required' unless thread_id
130
+
130
131
  @stats[thread_id].transaction_started_at = timestamp
131
132
  @stats[thread_id].elapsed_transaction_time = 0.0
132
133
  end
@@ -15,6 +15,7 @@ module NewRelic
15
15
  def detect
16
16
  begin
17
17
  return false unless pcf_keys_present?
18
+
18
19
  process_response(ENV)
19
20
  rescue
20
21
  NewRelic::Agent.logger.error("Error occurred detecting: #{vendor_name}", e)
@@ -134,6 +134,7 @@ module NewRelic
134
134
  def valid_chars?(value)
135
135
  value.each_char do |ch|
136
136
  next if ch =~ VALID_CHARS
137
+
137
138
  code_point = ch[0].ord # this works in Ruby 1.8.7 - 2.1.2
138
139
  next if code_point >= 0x80
139
140
 
@@ -145,6 +146,7 @@ module NewRelic
145
146
 
146
147
  def transform_key(key)
147
148
  return key unless key_transforms
149
+
148
150
  key_transforms.inject(key) { |memo, transform| memo.send(transform) }
149
151
  end
150
152
 
@@ -87,6 +87,7 @@ module NewRelic
87
87
  def append_vendor_info(collector_hash)
88
88
  VENDORS.each_pair do |klass, config_option|
89
89
  next unless Agent.config[config_option]
90
+
90
91
  vendor = klass.new
91
92
 
92
93
  if vendor.detect
@@ -125,6 +126,7 @@ module NewRelic
125
126
 
126
127
  def append_kubernetes_info(collector_hash)
127
128
  return unless Agent.config[:'utilization.detect_kubernetes']
129
+
128
130
  if host = ENV[KUBERNETES_SERVICE_HOST]
129
131
  collector_hash[:vendors] ||= {}
130
132
  collector_hash[:vendors][:kubernetes] = {
@@ -136,6 +138,7 @@ module NewRelic
136
138
  def append_full_hostname(collector_hash)
137
139
  full_hostname = fqdn
138
140
  return if full_hostname.nil? || full_hostname.empty?
141
+
139
142
  collector_hash[:full_hostname] = full_hostname
140
143
  end
141
144