newrelic_rpm 8.11.0 → 8.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +0 -3
  3. data/Brewfile +1 -0
  4. data/CHANGELOG.md +45 -16
  5. data/bin/nrdebug +2 -0
  6. data/docker-compose.yml +22 -0
  7. data/lib/new_relic/agent/agent/shutdown.rb +1 -0
  8. data/lib/new_relic/agent/agent/special_startup.rb +2 -0
  9. data/lib/new_relic/agent/agent/startup.rb +1 -0
  10. data/lib/new_relic/agent/attributes.rb +1 -0
  11. data/lib/new_relic/agent/audit_logger.rb +1 -0
  12. data/lib/new_relic/agent/commands/thread_profiler_session.rb +1 -0
  13. data/lib/new_relic/agent/configuration/default_source.rb +26 -4
  14. data/lib/new_relic/agent/configuration/dotted_hash.rb +1 -0
  15. data/lib/new_relic/agent/configuration/environment_source.rb +1 -0
  16. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  17. data/lib/new_relic/agent/configuration/manager.rb +3 -0
  18. data/lib/new_relic/agent/configuration/security_policy_source.rb +10 -0
  19. data/lib/new_relic/agent/configuration/yaml_source.rb +1 -0
  20. data/lib/new_relic/agent/connect/request_builder.rb +1 -0
  21. data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -0
  22. data/lib/new_relic/agent/database.rb +7 -0
  23. data/lib/new_relic/agent/database_adapter.rb +2 -0
  24. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +3 -2
  25. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
  26. data/lib/new_relic/agent/datastores/nosql_obfuscator.rb +41 -0
  27. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +3 -0
  28. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +3 -0
  29. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +1 -0
  30. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +1 -0
  31. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +1 -0
  32. data/lib/new_relic/agent/encoding_normalizer.rb +2 -0
  33. data/lib/new_relic/agent/error_collector.rb +3 -0
  34. data/lib/new_relic/agent/error_filter.rb +1 -0
  35. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -0
  36. data/lib/new_relic/agent/event_aggregator.rb +1 -0
  37. data/lib/new_relic/agent/event_loop.rb +2 -0
  38. data/lib/new_relic/agent/http_clients/abstract.rb +2 -0
  39. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +1 -0
  40. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -0
  41. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +2 -0
  42. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +1 -0
  43. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +1 -0
  44. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +1 -0
  45. data/lib/new_relic/agent/instrumentation/elasticsearch/chain.rb +29 -0
  46. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +66 -0
  47. data/lib/new_relic/agent/instrumentation/elasticsearch/prepend.rb +13 -0
  48. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +31 -0
  49. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +1 -0
  50. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +4 -0
  51. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +2 -0
  52. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +2 -0
  53. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +3 -0
  54. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +1 -0
  55. data/lib/new_relic/agent/instrumentation/sidekiq.rb +1 -0
  56. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -0
  57. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -0
  58. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +1 -0
  59. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -0
  60. data/lib/new_relic/agent/local_log_decorator.rb +1 -0
  61. data/lib/new_relic/agent/log_event_aggregator.rb +1 -0
  62. data/lib/new_relic/agent/messaging.rb +1 -0
  63. data/lib/new_relic/agent/method_tracer.rb +4 -0
  64. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +1 -0
  65. data/lib/new_relic/agent/new_relic_service.rb +2 -0
  66. data/lib/new_relic/agent/pipe_channel_manager.rb +2 -0
  67. data/lib/new_relic/agent/rules_engine.rb +1 -0
  68. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -0
  69. data/lib/new_relic/agent/samplers/memory_sampler.rb +5 -0
  70. data/lib/new_relic/agent/span_event_primitive.rb +1 -0
  71. data/lib/new_relic/agent/stats.rb +1 -0
  72. data/lib/new_relic/agent/stats_engine/gc_profiler.rb +1 -0
  73. data/lib/new_relic/agent/system_info.rb +3 -0
  74. data/lib/new_relic/agent/threading/agent_thread.rb +1 -0
  75. data/lib/new_relic/agent/threading/backtrace_service.rb +1 -0
  76. data/lib/new_relic/agent/threading/thread_profile.rb +3 -0
  77. data/lib/new_relic/agent/tracer.rb +4 -0
  78. data/lib/new_relic/agent/transaction/abstract_segment.rb +3 -0
  79. data/lib/new_relic/agent/transaction/datastore_segment.rb +3 -0
  80. data/lib/new_relic/agent/transaction/distributed_tracer.rb +4 -0
  81. data/lib/new_relic/agent/transaction/distributed_tracing.rb +1 -0
  82. data/lib/new_relic/agent/transaction/external_request_segment.rb +1 -0
  83. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -0
  84. data/lib/new_relic/agent/transaction/segment.rb +1 -0
  85. data/lib/new_relic/agent/transaction/trace.rb +4 -0
  86. data/lib/new_relic/agent/transaction/trace_node.rb +1 -0
  87. data/lib/new_relic/agent/transaction/transaction_sample_buffer.rb +2 -0
  88. data/lib/new_relic/agent/transaction.rb +10 -0
  89. data/lib/new_relic/agent/transaction_event_aggregator.rb +1 -0
  90. data/lib/new_relic/agent/transaction_time_aggregator.rb +1 -0
  91. data/lib/new_relic/agent/utilization/pcf.rb +1 -0
  92. data/lib/new_relic/agent/utilization/vendor.rb +2 -0
  93. data/lib/new_relic/agent/utilization_data.rb +3 -0
  94. data/lib/new_relic/agent.rb +4 -2
  95. data/lib/new_relic/cli/commands/install.rb +1 -0
  96. data/lib/new_relic/coerce.rb +6 -0
  97. data/lib/new_relic/collection_helper.rb +1 -0
  98. data/lib/new_relic/control/frameworks/rails.rb +5 -0
  99. data/lib/new_relic/control/instrumentation.rb +2 -0
  100. data/lib/new_relic/dependency_detection.rb +2 -0
  101. data/lib/new_relic/helper.rb +1 -0
  102. data/lib/new_relic/language_support.rb +1 -0
  103. data/lib/new_relic/latest_changes.rb +1 -0
  104. data/lib/new_relic/local_environment.rb +6 -0
  105. data/lib/new_relic/metric_spec.rb +2 -0
  106. data/lib/new_relic/rack/agent_middleware.rb +2 -0
  107. data/lib/new_relic/traced_thread.rb +1 -0
  108. data/lib/new_relic/version.rb +1 -1
  109. data/lib/tasks/helpers/format.rb +3 -0
  110. data/lib/tasks/instrumentation_generator/instrumentation.thor +27 -5
  111. data/lib/tasks/instrumentation_generator/templates/chain.tt +2 -1
  112. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +3 -2
  113. data/lib/tasks/instrumentation_generator/templates/instrumentation.tt +2 -1
  114. data/lib/tasks/instrumentation_generator/templates/instrumentation_method.tt +1 -1
  115. data/lib/tasks/instrumentation_generator/templates/prepend.tt +1 -1
  116. data/lib/tasks/instrumentation_generator/templates/prepend_method.tt +1 -1
  117. data/lib/tasks/instrumentation_generator/templates/test.tt +1 -1
  118. data/newrelic.yml +13 -3
  119. data/newrelic_rpm.gemspec +6 -6
  120. data/test/agent_helper.rb +6 -0
  121. metadata +11 -77
  122. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +0 -43
@@ -123,11 +123,13 @@ module NewRelic
123
123
 
124
124
  def exception_tagged_with?(ivar, exception)
125
125
  return false if exception_is_java_object?(exception)
126
+
126
127
  exception.instance_variable_defined?(ivar)
127
128
  end
128
129
 
129
130
  def tag_exception_using(ivar, exception)
130
131
  return if exception_is_java_object?(exception) || exception.frozen?
132
+
131
133
  begin
132
134
  exception.instance_variable_set(ivar, true)
133
135
  rescue => e
@@ -137,6 +139,7 @@ module NewRelic
137
139
 
138
140
  def tag_exception(exception)
139
141
  return if exception_is_java_object?(exception) || exception.frozen?
142
+
140
143
  begin
141
144
  exception.instance_variable_set(EXCEPTION_TAG_IVAR, true)
142
145
  rescue => e
@@ -155,6 +155,7 @@ module NewRelic
155
155
  result = []
156
156
  code_list.each do |code|
157
157
  result << code && next if code.is_a?(Integer)
158
+
158
159
  m = code.match(/(\d{3})(-\d{3})?/)
159
160
  if m.nil? || m[1].nil?
160
161
  ::NewRelic::Agent.logger.warn("Invalid HTTP status code: '#{code}'; ignoring config")
@@ -44,6 +44,7 @@ module NewRelic
44
44
  # floor after logging a warning.
45
45
  def add_to_error_queue(noticed_error)
46
46
  return unless enabled?
47
+
47
48
  @lock.synchronize do
48
49
  if !over_queue_limit?(noticed_error.message) && !@errors.include?(noticed_error)
49
50
  @errors << noticed_error
@@ -136,6 +136,7 @@ module NewRelic
136
136
 
137
137
  def notify_if_full
138
138
  return unless !@notified_full && @buffer.full?
139
+
139
140
  NewRelic::Agent.logger.debug("#{self.class.named} capacity of #{@buffer.capacity} reached, beginning sampling")
140
141
  @notified_full = true
141
142
  end
@@ -34,6 +34,7 @@ module NewRelic
34
34
  def calculate_next_fire_time
35
35
  now = Process.clock_gettime(Process::CLOCK_REALTIME)
36
36
  return now if @interval == 0
37
+
37
38
  fire_time = @last_fired_at || now
38
39
  while fire_time <= now
39
40
  fire_time += @interval
@@ -80,6 +81,7 @@ module NewRelic
80
81
 
81
82
  def next_timeout
82
83
  return nil if @timers.empty?
84
+
83
85
  timeout = @timers.values.map(&:next_fire_time).min - Process.clock_gettime(Process::CLOCK_REALTIME)
84
86
  timeout < 0 ? 0 : timeout
85
87
  end
@@ -47,6 +47,7 @@ module NewRelic
47
47
  if wrapped_response.nil?
48
48
  raise ArgumentError, WHINY_NIL_ERROR % self.class
49
49
  end
50
+
50
51
  @wrapped_response = wrapped_response
51
52
  end
52
53
 
@@ -64,6 +65,7 @@ module NewRelic
64
65
 
65
66
  def get_status_code_using(method_name)
66
67
  return unless @wrapped_response.respond_to?(method_name)
68
+
67
69
  code = @wrapped_response.send(method_name).to_i
68
70
  code == 0 ? nil : code
69
71
  end
@@ -67,6 +67,7 @@ module NewRelic
67
67
 
68
68
  def [](key)
69
69
  return nil unless @request.options && @request.options[:headers]
70
+
70
71
  @request.options[:headers][key]
71
72
  end
72
73
 
@@ -38,6 +38,7 @@ DependencyDetection.defer do
38
38
 
39
39
  executes do
40
40
  next unless Gem::Version.new(ActiveMerchant::VERSION) < Gem::Version.new('1.65.0')
41
+
41
42
  deprecation_msg = 'The Ruby Agent is dropping support for ActiveMerchant versions below 1.65.0 ' \
42
43
  'in version 9.0.0. Please upgrade your ActiveMerchant version to continue receiving full support. ' \
43
44
 
@@ -10,6 +10,7 @@ module NewRelic
10
10
  class ActiveStorageSubscriber < NotificationsSubscriber
11
11
  def start(name, id, payload)
12
12
  return unless state.is_execution_traced?
13
+
13
14
  start_segment(name, id, payload)
14
15
  rescue => e
15
16
  log_notification_error(e, name, 'start')
@@ -17,6 +18,7 @@ module NewRelic
17
18
 
18
19
  def finish(name, id, payload)
19
20
  return unless state.is_execution_traced?
21
+
20
22
  finish_segment(id, payload)
21
23
  rescue => e
22
24
  log_notification_error(e, name, 'finish')
@@ -14,6 +14,7 @@ module NewRelic
14
14
  parse_query_without_newrelic(*args)
15
15
  ensure
16
16
  return unless txn = ::NewRelic::Agent::Tracer.current_transaction
17
+
17
18
  txn.current_segment.params[:statement] = ::NewRelic::Agent::Database.truncate_query(args.first.inspect) rescue nil
18
19
  end
19
20
  end
@@ -273,6 +273,7 @@ module NewRelic
273
273
 
274
274
  def self.class_name(traced_obj, options = {})
275
275
  return options[:class_name] if options[:class_name]
276
+
276
277
  if traced_obj.is_a?(Class) || traced_obj.is_a?(Module)
277
278
  traced_obj.name
278
279
  else
@@ -96,6 +96,7 @@ DependencyDetection.defer do
96
96
 
97
97
  executes do
98
98
  next unless delayed_job_version < Gem::Version.new('4.1.0')
99
+
99
100
  deprecation_msg = 'Instrumentation for DelayedJob versions below 4.1.0 is deprecated.' \
100
101
  'It will stop being monitored in version 9.0.0. ' \
101
102
  'Please upgrade your DelayedJob version to continue receiving full support. ' \
@@ -0,0 +1,29 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module Elasticsearch
7
+ def self.instrument!
8
+ to_instrument = if ::Gem::Version.create(::Elasticsearch::VERSION) <
9
+ ::Gem::Version.create("8.0.0")
10
+ ::Elasticsearch::Transport::Client
11
+ else
12
+ ::Elastic::Transport::Client
13
+ end
14
+
15
+ to_instrument.class_eval do
16
+ include NewRelic::Agent::Instrumentation::Elasticsearch
17
+
18
+ alias_method(:perform_request_without_tracing, :perform_request)
19
+ alias_method(:perform_request, :perform_request_with_tracing)
20
+
21
+ def perform_request(*args)
22
+ perform_request_with_tracing(*args) do
23
+ perform_request_without_tracing(*args)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,66 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+ require_relative '../../datastores/nosql_obfuscator'
5
+
6
+ module NewRelic::Agent::Instrumentation
7
+ module Elasticsearch
8
+ PRODUCT_NAME = 'Elasticsearch'
9
+ OPERATION = 'perform_request'
10
+
11
+ def perform_request_with_tracing(method, path, params = {}, body = nil, headers = nil)
12
+ return yield unless NewRelic::Agent::Tracer.tracing_enabled?
13
+
14
+ segment = NewRelic::Agent::Tracer.start_datastore_segment(
15
+ product: PRODUCT_NAME,
16
+ operation: nr_operation || OPERATION,
17
+ host: nr_hosts[:host],
18
+ port_path_or_id: path,
19
+ database_name: nr_cluster_name
20
+ )
21
+ begin
22
+ NewRelic::Agent::Tracer.capture_segment_error(segment) { yield }
23
+ ensure
24
+ if segment
25
+ segment.notice_nosql_statement(nr_reported_query(body || params))
26
+ segment.finish
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def nr_operation
34
+ operation_index = caller_locations.index do |line|
35
+ string = line.to_s
36
+ string.include?('lib/elasticsearch/api') && !string.include?(OPERATION)
37
+ end
38
+ return nil unless operation_index
39
+
40
+ caller_locations[operation_index].to_s.split('`')[-1].gsub(/\W/, "")
41
+ end
42
+
43
+ def nr_reported_query(query)
44
+ return unless NewRelic::Agent.config[:'elasticsearch.capture_queries']
45
+ return query unless NewRelic::Agent.config[:'elasticsearch.obfuscate_queries']
46
+
47
+ NewRelic::Agent::Datastores::NosqlObfuscator.obfuscate_statement(query)
48
+ end
49
+
50
+ def nr_cluster_name
51
+ return @nr_cluster_name if @nr_cluster_name
52
+ return if nr_hosts.empty?
53
+
54
+ NewRelic::Agent.disable_all_tracing do
55
+ @nr_cluster_name ||= perform_request('GET', '_cluster/health').body["cluster_name"]
56
+ end
57
+ rescue StandardError => e
58
+ NewRelic::Agent.logger.error("Failed to get cluster name for elasticsearch", e)
59
+ nil
60
+ end
61
+
62
+ def nr_hosts
63
+ @nr_hosts ||= (transport.hosts.first || NewRelic::EMPTY_HASH)
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,13 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ module NewRelic::Agent::Instrumentation
6
+ module Elasticsearch::Prepend
7
+ include NewRelic::Agent::Instrumentation::Elasticsearch
8
+
9
+ def perform_request(*args)
10
+ perform_request_with_tracing(*args) { super }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ # This file is distributed under New Relic's license terms.
2
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
3
+ # frozen_string_literal: true
4
+
5
+ require_relative 'elasticsearch/instrumentation'
6
+ require_relative 'elasticsearch/chain'
7
+ require_relative 'elasticsearch/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :elasticsearch
11
+
12
+ depends_on do
13
+ defined?(::Elasticsearch)
14
+ end
15
+
16
+ executes do
17
+ ::NewRelic::Agent.logger.info('Installing Elasticsearch instrumentation')
18
+
19
+ to_instrument = if ::Gem::Version.create(::Elasticsearch::VERSION) < ::Gem::Version.create("8.0.0")
20
+ ::Elasticsearch::Transport::Client
21
+ else
22
+ ::Elastic::Transport::Client
23
+ end
24
+
25
+ if use_prepend?
26
+ prepend_instrument to_instrument, NewRelic::Agent::Instrumentation::Elasticsearch::Prepend
27
+ else
28
+ chain_instrument NewRelic::Agent::Instrumentation::Elasticsearch
29
+ end
30
+ end
31
+ end
@@ -45,6 +45,7 @@ module NewRelic::Agent::Instrumentation
45
45
 
46
46
  def handle_transaction(endpoint, class_name, version)
47
47
  return unless endpoint && route = endpoint.route
48
+
48
49
  name_transaction(route, class_name, version)
49
50
  capture_params(endpoint)
50
51
  end
@@ -15,21 +15,25 @@ module NewRelic
15
15
  # and AuditLogger without them having to know the inner details.
16
16
  def self.mark_skip_instrumenting(logger)
17
17
  return if logger.frozen?
18
+
18
19
  logger.instance_variable_set(:@skip_instrumenting, true)
19
20
  end
20
21
 
21
22
  def self.clear_skip_instrumenting(logger)
22
23
  return if logger.frozen?
24
+
23
25
  logger.instance_variable_set(:@skip_instrumenting, false)
24
26
  end
25
27
 
26
28
  def mark_skip_instrumenting
27
29
  return if frozen?
30
+
28
31
  @skip_instrumenting = true
29
32
  end
30
33
 
31
34
  def clear_skip_instrumenting
32
35
  return if frozen?
36
+
33
37
  @skip_instrumenting = false
34
38
  end
35
39
 
@@ -14,6 +14,7 @@ module NewRelic
14
14
  def started(event)
15
15
  begin
16
16
  return unless NewRelic::Agent::Tracer.tracing_enabled?
17
+
17
18
  segments[event.operation_id] = start_segment(event)
18
19
  rescue Exception => e
19
20
  log_notification_error('started', e)
@@ -33,6 +34,7 @@ module NewRelic
33
34
  def completed(event)
34
35
  begin
35
36
  return unless NewRelic::Agent::Tracer.tracing_enabled?
37
+
36
38
  segment = segments.delete(event.operation_id)
37
39
  return unless segment
38
40
 
@@ -76,6 +76,7 @@ module NewRelic
76
76
  # defensive.
77
77
  return if defined?(exception_object)
78
78
  return unless defined?(::ActiveSupport::VERSION)
79
+
79
80
  if ::ActiveSupport::VERSION::STRING < "5.0.0"
80
81
  # Earlier versions of Rails did not add the exception itself to the
81
82
  # payload accessible via :exception_object, so we create a stand-in
@@ -85,6 +86,7 @@ module NewRelic
85
86
  def exception_object(payload)
86
87
  exception_class, message = payload[:exception]
87
88
  return nil unless exception_class
89
+
88
90
  NewRelic::Agent::NoticeableError.new(exception_class, message)
89
91
  end
90
92
  else
@@ -23,6 +23,7 @@ module NewRelic
23
23
 
24
24
  def check_for_late_instrumentation(app)
25
25
  return if defined?(@checked_for_late_instrumentation) && @checked_for_late_instrumentation
26
+
26
27
  @checked_for_late_instrumentation = true
27
28
  if middleware_instrumentation_enabled?
28
29
  if ::NewRelic::Agent::Instrumentation::MiddlewareProxy.needs_wrapping?(app)
@@ -49,12 +50,14 @@ module NewRelic
49
50
 
50
51
  def run_with_tracing(app)
51
52
  return yield(app) unless middleware_instrumentation_enabled?
53
+
52
54
  yield(::NewRelic::Agent::Instrumentation::MiddlewareProxy.wrap(app, true))
53
55
  end
54
56
 
55
57
  def use_with_tracing(middleware_class)
56
58
  return if middleware_class.nil?
57
59
  return yield(middleware_class) unless middleware_instrumentation_enabled?
60
+
58
61
  yield(::NewRelic::Agent::Instrumentation::MiddlewareProxy.for_class(middleware_class))
59
62
  end
60
63
  end
@@ -37,6 +37,7 @@ module NewRelic
37
37
 
38
38
  def safe_from_third_party_gem?
39
39
  return true unless NewRelic::LanguageSupport.bundled_gem?("newrelic-rake")
40
+
40
41
  ::NewRelic::Agent.logger.info("Not installing New Relic supported Rake instrumentation because the third party newrelic-rake gem is present")
41
42
  false
42
43
  end
@@ -103,6 +103,7 @@ DependencyDetection.defer do
103
103
 
104
104
  executes do
105
105
  next unless Gem::Version.new(Sidekiq::VERSION) < Gem::Version.new('5.0.0')
106
+
106
107
  deprecation_msg = 'Instrumentation for Sidekiq versions below 5.0.0 is deprecated.' \
107
108
  'They will stop being monitored in version 9.0.0. ' \
108
109
  'Please upgrade your Sidekiq version to continue receiving full support. '
@@ -45,6 +45,7 @@ DependencyDetection.defer do
45
45
 
46
46
  executes do
47
47
  next unless Gem::Version.new(Sinatra::VERSION) < Gem::Version.new('2.0.0')
48
+
48
49
  deprecation_msg = 'The Ruby Agent is dropping support for Sinatra versions below 2.0.0 ' \
49
50
  'in version 9.0.0. Please upgrade your Sinatra version to continue receiving full compatibility. ' \
50
51
 
@@ -15,6 +15,7 @@ module NewRelic
15
15
 
16
16
  def add_thread_tracing(*args, &block)
17
17
  return block if skip_tracing?
18
+
18
19
  NewRelic::Agent::Tracer.thread_block_with_current_transaction(*args, &block)
19
20
  end
20
21
 
@@ -14,6 +14,7 @@ module NewRelic
14
14
  # So here we are only grabbing the file name and name of directory it is in
15
15
  def create_filename_for_metric(file)
16
16
  return file unless defined?(::Sinatra) && defined?(::Sinatra::Base)
17
+
17
18
  file.split('/')[-2..-1].join('/')
18
19
  rescue NoMethodError
19
20
  file
@@ -118,6 +118,7 @@ module NewRelic
118
118
 
119
119
  def create_nonce(nonce = nil)
120
120
  return '' unless nonce
121
+
121
122
  " nonce=\"#{nonce.to_s}\""
122
123
  end
123
124
 
@@ -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
@@ -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')
@@ -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