newrelic_rpm 6.15.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +260 -22
  4. data/CONTRIBUTING.md +13 -2
  5. data/README.md +4 -2
  6. data/lib/new_relic/agent/adaptive_sampler.rb +2 -2
  7. data/lib/new_relic/agent/agent.rb +8 -7
  8. data/lib/new_relic/agent/autostart.rb +1 -2
  9. data/lib/new_relic/agent/commands/thread_profiler_session.rb +7 -3
  10. data/lib/new_relic/agent/configuration/default_source.rb +456 -233
  11. data/lib/new_relic/agent/configuration/event_harvest_config.rb +28 -12
  12. data/lib/new_relic/agent/configuration/manager.rb +3 -4
  13. data/lib/new_relic/agent/configuration/server_source.rb +3 -2
  14. data/lib/new_relic/agent/configuration/yaml_source.rb +22 -1
  15. data/lib/new_relic/agent/connect/request_builder.rb +4 -2
  16. data/lib/new_relic/agent/custom_event_aggregator.rb +2 -1
  17. data/lib/new_relic/agent/database.rb +5 -2
  18. data/lib/new_relic/agent/datastores/mongo.rb +5 -10
  19. data/lib/new_relic/agent/datastores/redis.rb +0 -4
  20. data/lib/new_relic/agent/datastores.rb +7 -7
  21. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +5 -5
  22. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +10 -6
  23. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +0 -1
  24. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +1 -1
  25. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +1 -1
  26. data/lib/new_relic/agent/distributed_tracing.rb +0 -66
  27. data/lib/new_relic/agent/error_collector.rb +52 -37
  28. data/lib/new_relic/agent/error_filter.rb +167 -0
  29. data/lib/new_relic/agent/event_loop.rb +6 -6
  30. data/lib/new_relic/agent/external.rb +0 -32
  31. data/lib/new_relic/agent/http_clients/abstract.rb +2 -2
  32. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -1
  33. data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -3
  34. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +0 -16
  35. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -3
  36. data/lib/new_relic/agent/instrumentation/bunny/chain.rb +45 -0
  37. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +152 -0
  38. data/lib/new_relic/agent/instrumentation/bunny/prepend.rb +35 -0
  39. data/lib/new_relic/agent/instrumentation/bunny.rb +10 -152
  40. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +2 -1
  41. data/lib/new_relic/agent/instrumentation/curb/chain.rb +93 -0
  42. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +222 -0
  43. data/lib/new_relic/agent/instrumentation/curb/prepend.rb +63 -0
  44. data/lib/new_relic/agent/instrumentation/curb.rb +9 -241
  45. data/lib/new_relic/agent/instrumentation/delayed_job/chain.rb +38 -0
  46. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +53 -0
  47. data/lib/new_relic/agent/instrumentation/delayed_job/prepend.rb +34 -0
  48. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +8 -50
  49. data/lib/new_relic/agent/instrumentation/excon.rb +4 -22
  50. data/lib/new_relic/agent/instrumentation/grape/chain.rb +25 -0
  51. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +100 -0
  52. data/lib/new_relic/agent/instrumentation/grape/prepend.rb +17 -0
  53. data/lib/new_relic/agent/instrumentation/grape.rb +13 -113
  54. data/lib/new_relic/agent/instrumentation/httpclient/chain.rb +25 -0
  55. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +38 -0
  56. data/lib/new_relic/agent/instrumentation/httpclient/prepend.rb +17 -0
  57. data/lib/new_relic/agent/instrumentation/httpclient.rb +8 -30
  58. data/lib/new_relic/agent/instrumentation/httprb/chain.rb +22 -0
  59. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +30 -0
  60. data/lib/new_relic/agent/instrumentation/httprb/prepend.rb +15 -0
  61. data/lib/new_relic/agent/instrumentation/httprb.rb +29 -0
  62. data/lib/new_relic/agent/instrumentation/memcache/chain.rb +16 -0
  63. data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +38 -121
  64. data/lib/new_relic/agent/instrumentation/memcache/helper.rb +56 -0
  65. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +88 -0
  66. data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +88 -0
  67. data/lib/new_relic/agent/instrumentation/memcache.rb +54 -69
  68. data/lib/new_relic/agent/instrumentation/middleware_proxy.rb +2 -0
  69. data/lib/new_relic/agent/instrumentation/mongo.rb +3 -134
  70. data/lib/new_relic/agent/instrumentation/net_http/chain.rb +25 -0
  71. data/lib/new_relic/agent/instrumentation/{net_prepend.rb → net_http/instrumentation.rb} +3 -3
  72. data/lib/new_relic/agent/instrumentation/net_http/prepend.rb +21 -0
  73. data/lib/new_relic/agent/instrumentation/net_http.rb +44 -0
  74. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +34 -0
  75. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +27 -0
  76. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +20 -0
  77. data/lib/new_relic/agent/instrumentation/padrino.rb +18 -53
  78. data/lib/new_relic/agent/instrumentation/queue_time.rb +4 -4
  79. data/lib/new_relic/agent/instrumentation/rack/chain.rb +58 -0
  80. data/lib/new_relic/agent/instrumentation/rack/helpers.rb +32 -0
  81. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +73 -0
  82. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +37 -0
  83. data/lib/new_relic/agent/instrumentation/rack.rb +29 -139
  84. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +5 -5
  85. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  86. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -41
  87. data/lib/new_relic/agent/instrumentation/rake/chain.rb +25 -0
  88. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +144 -0
  89. data/lib/new_relic/agent/instrumentation/rake/prepend.rb +14 -0
  90. data/lib/new_relic/agent/instrumentation/rake.rb +13 -154
  91. data/lib/new_relic/agent/instrumentation/redis/chain.rb +34 -0
  92. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +65 -0
  93. data/lib/new_relic/agent/instrumentation/redis/prepend.rb +24 -0
  94. data/lib/new_relic/agent/instrumentation/redis.rb +12 -107
  95. data/lib/new_relic/agent/instrumentation/resque/chain.rb +22 -0
  96. data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
  97. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +35 -0
  98. data/lib/new_relic/agent/instrumentation/resque/prepend.rb +16 -0
  99. data/lib/new_relic/agent/instrumentation/resque.rb +21 -32
  100. data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -1
  101. data/lib/new_relic/agent/instrumentation/sinatra/chain.rb +55 -0
  102. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +29 -34
  103. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +124 -0
  104. data/lib/new_relic/agent/instrumentation/sinatra/prepend.rb +33 -0
  105. data/lib/new_relic/agent/instrumentation/sinatra.rb +20 -158
  106. data/lib/new_relic/agent/instrumentation/typhoeus/chain.rb +22 -0
  107. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +82 -0
  108. data/lib/new_relic/agent/instrumentation/typhoeus/prepend.rb +14 -0
  109. data/lib/new_relic/agent/instrumentation/typhoeus.rb +10 -89
  110. data/lib/new_relic/agent/javascript_instrumentor.rb +15 -10
  111. data/lib/new_relic/agent/messaging.rb +10 -24
  112. data/lib/new_relic/agent/method_tracer.rb +132 -138
  113. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +6 -1
  114. data/lib/new_relic/agent/new_relic_service.rb +24 -22
  115. data/lib/new_relic/agent/pipe_channel_manager.rb +10 -6
  116. data/lib/new_relic/agent/pipe_service.rb +1 -1
  117. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  118. data/lib/new_relic/agent/span_event_aggregator.rb +2 -2
  119. data/lib/new_relic/agent/sql_sampler.rb +4 -4
  120. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  121. data/lib/new_relic/agent/stats_engine.rb +1 -1
  122. data/lib/new_relic/agent/supported_versions.rb +1 -1
  123. data/lib/new_relic/agent/threading/backtrace_service.rb +4 -5
  124. data/lib/new_relic/agent/threading/thread_profile.rb +1 -1
  125. data/lib/new_relic/agent/tracer.rb +15 -37
  126. data/lib/new_relic/agent/transaction/abstract_segment.rb +3 -3
  127. data/lib/new_relic/agent/transaction/message_broker_segment.rb +5 -11
  128. data/lib/new_relic/agent/transaction.rb +8 -32
  129. data/lib/new_relic/agent/transaction_time_aggregator.rb +5 -5
  130. data/lib/new_relic/agent/vm/snapshot.rb +1 -1
  131. data/lib/new_relic/agent/worker_loop.rb +5 -5
  132. data/lib/new_relic/agent.rb +10 -13
  133. data/lib/new_relic/cli/commands/deployments.rb +2 -2
  134. data/lib/new_relic/constants.rb +0 -4
  135. data/lib/new_relic/control/frameworks/rails.rb +11 -9
  136. data/lib/new_relic/control/instance_methods.rb +1 -0
  137. data/lib/new_relic/dependency_detection.rb +116 -10
  138. data/lib/new_relic/noticed_error.rb +5 -9
  139. data/lib/new_relic/supportability_helper.rb +1 -2
  140. data/lib/new_relic/version.rb +2 -2
  141. data/lib/newrelic_rpm.rb +10 -34
  142. data/lib/tasks/all.rb +1 -1
  143. data/lib/tasks/config.html.erb +14 -25
  144. data/lib/tasks/config.rake +8 -7
  145. data/newrelic.yml +593 -3
  146. data/newrelic_rpm.gemspec +1 -1
  147. data/test/agent_helper.rb +27 -2
  148. metadata +56 -14
  149. data/cert/cacert.pem +0 -1177
  150. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +0 -53
  151. data/lib/new_relic/agent/instrumentation/excon/connection.rb +0 -49
  152. data/lib/new_relic/agent/instrumentation/http.rb +0 -49
  153. data/lib/new_relic/agent/instrumentation/merb/controller.rb +0 -44
  154. data/lib/new_relic/agent/instrumentation/merb/errors.rb +0 -33
  155. data/lib/new_relic/agent/instrumentation/net.rb +0 -70
  156. data/lib/new_relic/control/frameworks/merb.rb +0 -29
@@ -13,12 +13,13 @@ module NewRelic
13
13
  :analytic_event_data => :'analytics_events.max_samples_stored',
14
14
  :custom_event_data => :'custom_insights_events.max_samples_stored',
15
15
  :error_event_data => :'error_collector.max_event_samples_stored',
16
- :span_event_data => :'span_events.max_samples_stored'
17
16
  }
18
17
 
19
18
  def from_config(config)
20
- {:harvest_limits => EVENT_HARVEST_CONFIG_KEY_MAPPING.inject({}) do
21
- |connect_payload, (connect_payload_key, config_key)|
19
+ {:harvest_limits =>
20
+ EVENT_HARVEST_CONFIG_KEY_MAPPING.merge(
21
+ :span_event_data => :'span_events.max_samples_stored'
22
+ ).inject({}) do |connect_payload, (connect_payload_key, config_key)|
22
23
  connect_payload[connect_payload_key] = config[config_key]
23
24
  connect_payload
24
25
  end
@@ -27,16 +28,31 @@ module NewRelic
27
28
 
28
29
  def to_config_hash(connect_reply)
29
30
  event_harvest_interval = connect_reply['event_harvest_config']['report_period_ms'] / 1000
30
- config_hash = EVENT_HARVEST_CONFIG_KEY_MAPPING.inject({}) do
31
- |event_harvest_config, (connect_payload_key, config_key)|
32
- if harvest_limit = connect_reply['event_harvest_config']['harvest_limits'][connect_payload_key.to_s]
33
- event_harvest_config[config_key] = harvest_limit
34
- report_period_key = :"event_report_period.#{connect_payload_key}"
35
- event_harvest_config[report_period_key] = event_harvest_interval
36
- end
37
- event_harvest_config
38
- end
31
+ config_hash = transform_event_harvest_config_keys(connect_reply, event_harvest_interval)
39
32
  config_hash[:event_report_period] = event_harvest_interval
33
+ config_hash = transform_span_event_harvest_config(config_hash, connect_reply)
34
+ config_hash
35
+ end
36
+
37
+ private
38
+
39
+ def transform_event_harvest_config_keys(connect_reply, event_harvest_interval)
40
+ EVENT_HARVEST_CONFIG_KEY_MAPPING.inject({}) do |event_harvest_config, (connect_payload_key, config_key)|
41
+ if harvest_limit = connect_reply['event_harvest_config']['harvest_limits'][connect_payload_key.to_s]
42
+ event_harvest_config[config_key] = harvest_limit
43
+ report_period_key = :"event_report_period.#{connect_payload_key}"
44
+ event_harvest_config[report_period_key] = event_harvest_interval
45
+ end
46
+ event_harvest_config
47
+ end
48
+ end
49
+
50
+ def transform_span_event_harvest_config(config_hash, connect_reply)
51
+ if span_harvest = connect_reply['span_event_harvest_config']
52
+ config_hash[:'span_events.max_samples_stored'] = span_harvest['harvest_limit'] if span_harvest['harvest_limit']
53
+ config_hash[:'event_report_period.span_event_data'] = span_harvest['report_period_ms'] if span_harvest['report_period_ms']
54
+ end
55
+
40
56
  config_hash
41
57
  end
42
58
  end
@@ -15,7 +15,6 @@ module NewRelic
15
15
  module Agent
16
16
  module Configuration
17
17
  class Manager
18
-
19
18
  # Defining these explicitly saves object allocations that we incur
20
19
  # if we use Forwardable and def_delegators.
21
20
  def [](key)
@@ -23,7 +22,7 @@ module NewRelic
23
22
  end
24
23
 
25
24
  def has_key?(key)
26
- @cache.has_key?[key]
25
+ @cache.has_key? key
27
26
  end
28
27
 
29
28
  def keys
@@ -80,6 +79,7 @@ module NewRelic
80
79
  was_finished = finished_configuring?
81
80
 
82
81
  invoke_callbacks(:add, source)
82
+
83
83
  case source
84
84
  when SecurityPolicySource then @security_policy_source = source
85
85
  when HighSecuritySource then @high_security_source = source
@@ -159,7 +159,6 @@ module NewRelic
159
159
  def invoke_callbacks(direction, source)
160
160
  return unless source
161
161
  source.keys.each do |key|
162
-
163
162
  if @cache[key] != source[key]
164
163
  @callbacks[key].each do |proc|
165
164
  if direction == :add
@@ -345,7 +344,7 @@ module NewRelic
345
344
  end
346
345
 
347
346
  def reset_cache
348
- @cache = Hash.new {|hash,key| hash[key] = self.fetch(key) }
347
+ @cache = Hash.new { |hash,key| hash[key] = self.fetch(key) }
349
348
  end
350
349
 
351
350
  def log_config(direction, source)
@@ -79,8 +79,9 @@ module NewRelic
79
79
  :'analytics_events.max_samples_stored' => 'Supportability/EventHarvest/AnalyticEventData/HarvestLimit',
80
80
  :'custom_insights_events.max_samples_stored' => 'Supportability/EventHarvest/CustomEventData/HarvestLimit',
81
81
  :'error_collector.max_event_samples_stored'=> 'Supportability/EventHarvest/ErrorEventData/HarvestLimit',
82
- :'span_events.max_samples_stored'=> 'Supportability/EventHarvest/SpanEventData/HarvestLimit',
83
- :event_report_period => 'Supportability/EventHarvest/ReportPeriod'
82
+ :'span_events.max_samples_stored' => 'Supportability/SpanEvent/Limit',
83
+ :event_report_period => 'Supportability/EventHarvest/ReportPeriod',
84
+ :'event_report_period.span_event_data' => 'Supportability/SpanEvent/ReportPeriod',
84
85
  }
85
86
 
86
87
  def add_event_harvest_config(merged_settings, connect_reply)
@@ -11,6 +11,10 @@ module NewRelic
11
11
  attr_accessor :file_path, :failures
12
12
  attr_reader :generated_for_user, :license_key
13
13
 
14
+ # These are configuration options that have a value of a Hash
15
+ # This is used in YamlSource#dot_flattened prevent flattening these values
16
+ CONFIG_WITH_HASH_VALUE = ['expected_messages', 'ignore_messages']
17
+
14
18
  def initialize(path, env)
15
19
  @path = path
16
20
  config = {}
@@ -99,7 +103,12 @@ module NewRelic
99
103
 
100
104
  def process_yaml(file, env, config, path)
101
105
  if file
102
- confighash = YAML.load(file)
106
+ confighash = if YAML.respond_to?(:unsafe_load)
107
+ YAML.unsafe_load(file)
108
+ else
109
+ YAML.load(file)
110
+ end
111
+
103
112
  unless confighash.key?(env)
104
113
  log_failure("Config file at #{path} doesn't include a '#{env}' section!")
105
114
  end
@@ -141,6 +150,18 @@ module NewRelic
141
150
  ::NewRelic::Agent.logger.error(*messages)
142
151
  messages.each { |message| @failures << message }
143
152
  end
153
+
154
+ def dot_flattened(nested_hash, names=[], result={})
155
+ nested_hash.each do |key, val|
156
+ next if val == nil
157
+ if val.respond_to?(:has_key?) && !CONFIG_WITH_HASH_VALUE.include?(key)
158
+ dot_flattened(val, names + [key], result)
159
+ else
160
+ result[(names + [key]).join('.')] = val
161
+ end
162
+ end
163
+ result
164
+ end
144
165
  end
145
166
  end
146
167
  end
@@ -48,8 +48,10 @@ module NewRelic
48
48
  environment_report
49
49
  end
50
50
 
51
- def environment_metadata
52
- ENV.select {|k, v| k =~ /^NEW_RELIC_METADATA_/}
51
+ def environment_metadata
52
+ env_copy = {}
53
+ ENV.keys.each {|k| env_copy[k] = ENV[k] if k =~ /^NEW_RELIC_METADATA_/}
54
+ env_copy
53
55
  end
54
56
 
55
57
  def local_host
@@ -46,7 +46,8 @@ module NewRelic
46
46
 
47
47
  def create_event(type, priority, attributes)
48
48
  [
49
- { TYPE => type, TIMESTAMP => Time.now.to_i,
49
+ { TYPE => type,
50
+ TIMESTAMP => Process.clock_gettime(Process::CLOCK_REALTIME).to_i,
50
51
  PRIORITY => priority
51
52
  },
52
53
  AttributeProcessing.flatten_and_coerce(attributes)
@@ -228,9 +228,12 @@ module NewRelic
228
228
  def explain
229
229
  return unless explainable?
230
230
  handle_exception_in_explain do
231
- start = Time.now
231
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
232
232
  plan = @explainer.call(self)
233
- ::NewRelic::Agent.record_metric("Supportability/Database/execute_explain_plan", Time.now - start)
233
+ ::NewRelic::Agent.record_metric(
234
+ "Supportability/Database/execute_explain_plan",
235
+ Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
236
+ )
234
237
  return process_resultset(plan, adapter) if plan
235
238
  end
236
239
  end
@@ -7,22 +7,17 @@ module NewRelic
7
7
  module Datastores
8
8
  module Mongo
9
9
  def self.is_supported_version?
10
- # No version constant in < 2.0 versions of Mongo :(
11
- defined?(::Mongo) && (defined?(::Mongo::MongoClient) || is_monitoring_enabled?)
12
- end
13
-
14
- def self.is_monitoring_enabled?
15
- defined?(::Mongo::Monitoring) # @since 2.1.0
10
+ defined?(::Mongo) && is_monitoring_enabled?
16
11
  end
17
12
 
18
13
  def self.is_unsupported_2x?
19
- defined?(::Mongo::VERSION) && Gem::Version.new(::Mongo::VERSION).segments[0] == 2 &&
14
+ defined?(::Mongo::VERSION) &&
15
+ Gem::Version.new(::Mongo::VERSION).segments[0] == 2 &&
20
16
  !self.is_monitoring_enabled?
21
17
  end
22
18
 
23
- def self.is_version_1_10_or_later?
24
- # Again, no VERSION constant in 1.x, so we have to rely on constant checks
25
- defined?(::Mongo::CollectionOperationWriter)
19
+ def self.is_monitoring_enabled?
20
+ defined?(::Mongo::Monitoring) # @since 2.1.0
26
21
  end
27
22
  end
28
23
  end
@@ -6,11 +6,7 @@ module NewRelic
6
6
  module Agent
7
7
  module Datastores
8
8
  module Redis
9
- MULTI_OPERATION = 'multi'
10
- PIPELINE_OPERATION = 'pipeline'
11
9
  BINARY_DATA_PLACEHOLDER = "<binary data>"
12
- PRODUCT_NAME = 'Redis'
13
- CONNECT = 'connect'
14
10
 
15
11
  MAXIMUM_COMMAND_LENGTH = 1000
16
12
  MAXIMUM_ARGUMENT_LENGTH = 64
@@ -21,7 +21,7 @@ module NewRelic
21
21
  # query content into Transaction Traces. Use wrap if you want to provide
22
22
  # that functionality.
23
23
  #
24
- # @param [Class] clazz the class to instrument
24
+ # @param [Class] klass the class to instrument
25
25
  #
26
26
  # @param [String, Symbol] method_name the name of instance method to
27
27
  # instrument
@@ -33,16 +33,16 @@ module NewRelic
33
33
  #
34
34
  # @api public
35
35
  #
36
- def self.trace(clazz, method_name, product, operation = method_name)
36
+ def self.trace(klass, method_name, product, operation = method_name)
37
37
  NewRelic::Agent.record_api_supportability_metric(:trace)
38
38
 
39
- clazz.class_eval do
39
+ klass.class_eval do
40
40
  method_name_without_newrelic = "#{method_name}_without_newrelic"
41
41
 
42
- if NewRelic::Helper.instance_methods_include?(clazz, method_name) &&
43
- !NewRelic::Helper.instance_methods_include?(clazz, method_name_without_newrelic)
42
+ if NewRelic::Helper.instance_methods_include?(klass, method_name) &&
43
+ !NewRelic::Helper.instance_methods_include?(klass, method_name_without_newrelic)
44
44
 
45
- visibility = NewRelic::Helper.instance_method_visibility(clazz, method_name)
45
+ visibility = NewRelic::Helper.instance_method_visibility(klass, method_name)
46
46
 
47
47
  alias_method method_name_without_newrelic, method_name
48
48
 
@@ -123,7 +123,7 @@ module NewRelic
123
123
  ensure
124
124
  begin
125
125
  if callback
126
- elapsed_time = (Time.now - segment.start_time).to_f
126
+ elapsed_time = Process.clock_gettime(Process::CLOCK_REALTIME) - segment.start_time
127
127
  callback.call(result, segment.name, elapsed_time)
128
128
  end
129
129
  ensure
@@ -19,15 +19,15 @@ module NewRelic
19
19
  end
20
20
 
21
21
  def as_json_array(content_length)
22
- queue_time_in_seconds = [transaction.queue_time.to_f, 0.0].max
23
- start_time_in_seconds = [transaction.start_time.to_f, 0.0].max
24
- app_time_in_seconds = Time.now.to_f - start_time_in_seconds
22
+ queue_time_in_seconds = [transaction.queue_time, 0.0].max
23
+ start_time_in_seconds = [transaction.start_time, 0.0].max
24
+ app_time_in_seconds = Process.clock_gettime(Process::CLOCK_REALTIME) - start_time_in_seconds
25
25
 
26
26
  [
27
27
  NewRelic::Agent.config[:cross_process_id],
28
28
  transaction.best_name,
29
- queue_time_in_seconds.to_f,
30
- app_time_in_seconds.to_f,
29
+ queue_time_in_seconds,
30
+ app_time_in_seconds,
31
31
  content_length,
32
32
  transaction.guid,
33
33
  false
@@ -54,6 +54,7 @@ module NewRelic
54
54
 
55
55
  def insert_cross_app_header headers
56
56
  return unless CrossAppTracing.cross_app_enabled?
57
+
57
58
  @is_cross_app_caller = true
58
59
  txn_guid = transaction.guid
59
60
  trip_id = cat_trip_id
@@ -65,17 +66,20 @@ module NewRelic
65
66
  def add_message_cat_headers headers
66
67
  return unless CrossAppTracing.cross_app_enabled?
67
68
  @is_cross_app_caller = true
68
- insert_message_headers headers,
69
- transaction.guid,
70
- cat_trip_id,
71
- cat_path_hash,
69
+ insert_message_headers headers,
70
+ transaction.guid,
71
+ cat_trip_id,
72
+ cat_path_hash,
72
73
  transaction.raw_synthetics_header
73
74
  end
74
75
 
75
76
  def record_cross_app_metrics
76
77
  if (id = cross_app_payload && cross_app_payload.id)
77
- app_time_in_seconds = [Time.now.to_f - transaction.start_time.to_f, 0.0].max
78
- NewRelic::Agent.record_metric "ClientApplication/#{id}/all", app_time_in_seconds
78
+ app_time_in_seconds = [
79
+ Process.clock_gettime(Process::CLOCK_REALTIME) - transaction.start_time,
80
+ 0.0
81
+ ].max
82
+ NewRelic::Agent.record_metric("ClientApplication/#{id}/all", app_time_in_seconds)
79
83
  end
80
84
  end
81
85
 
@@ -64,7 +64,6 @@ module NewRelic
64
64
  destination[PARENT_TYPE_KEY] = trace_payload.parent_type
65
65
  destination[PARENT_APP_KEY] = trace_payload.parent_app_id
66
66
  destination[PARENT_ACCOUNT_ID_KEY] = trace_payload.parent_account_id
67
-
68
67
  destination[PARENT_TRANSPORT_DURATION_KEY] = transaction.calculate_transport_duration trace_payload
69
68
 
70
69
  if parent_transaction_id = transaction.distributed_tracer.parent_transaction_id
@@ -50,7 +50,7 @@ module NewRelic
50
50
 
51
51
  payload.id = current_segment_id(transaction)
52
52
  payload.transaction_id = transaction.guid
53
- payload.timestamp = (Time.now.to_f * 1000).round
53
+ payload.timestamp = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
54
54
  payload.trace_id = transaction.trace_id
55
55
  payload.sampled = transaction.sampled?
56
56
  payload.priority = transaction.priority
@@ -57,7 +57,7 @@ module NewRelic
57
57
  private
58
58
 
59
59
  def now_ms
60
- (Time.now.to_f * 1000).round
60
+ Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
61
61
  end
62
62
 
63
63
  def handle_invalid_payload error: nil, message: nil
@@ -24,72 +24,6 @@ module NewRelic
24
24
  extend NewRelic::SupportabilityHelper
25
25
  extend self
26
26
 
27
- # Create a payload object containing the current transaction's
28
- # tracing properties (e.g., duration, priority). You can use
29
- # this object to generate headers to inject into a network
30
- # request, so that the downstream service can participate in a
31
- # distributed trace.
32
- #
33
- # @return [DistributedTracePayload] Payload for the current
34
- # transaction, or +nil+ if we
35
- # could not create the payload
36
- #
37
- # @api public
38
- #
39
- # @deprecated See {#create_distributed_trace_headers} instead.
40
- #
41
- def create_distributed_trace_payload
42
- Deprecator.deprecate :create_distributed_trace_payload, :create_distributed_trace_headers
43
-
44
- unless Agent.config[:'distributed_tracing.enabled']
45
- NewRelic::Agent.logger.warn "Not configured to create New Relic distributed trace payload"
46
- return nil
47
- end
48
-
49
- return unless transaction = Transaction.tl_current
50
- transaction.distributed_tracer.create_distributed_trace_payload
51
- rescue => e
52
- NewRelic::Agent.logger.error 'error during create_distributed_trace_payload', e
53
- nil
54
- end
55
-
56
- # Decode a JSON string containing distributed trace properties
57
- # (e.g., calling application, priority) and apply them to the
58
- # current transaction. You can use it to receive distributed
59
- # tracing information protocols the agent does not already
60
- # support.
61
- #
62
- # This method will fail if you call it after calling
63
- # {#create_distributed_trace_payload}.
64
- #
65
- # @param payload [String] Incoming distributed trace payload,
66
- # either as a JSON string or as a
67
- # header-friendly string returned from
68
- # {DistributedTracePayload#http_safe}
69
- #
70
- # @return nil
71
- #
72
- # @api public
73
- #
74
- # @deprecated See {#accept_distributed_trace_headers} instead
75
- #
76
- def accept_distributed_trace_payload payload
77
- Deprecator.deprecate :accept_distributed_trace_payload, :accept_distributed_trace_headers
78
-
79
- unless Agent.config[:'distributed_tracing.enabled']
80
- NewRelic::Agent.logger.warn "Not configured to accept New Relic distributed trace payload"
81
- return nil
82
- end
83
-
84
- return unless transaction = Transaction.tl_current
85
- transaction.distributed_tracer.accept_distributed_trace_payload(payload)
86
- nil
87
- rescue => e
88
- NewRelic::Agent.logger.error 'error during accept_distributed_trace_payload', e
89
- nil
90
- end
91
-
92
-
93
27
  # Adds the Distributed Trace headers so that the downstream service can participate in a
94
28
  # distributed trace. This method should be called every time an outbound call is made
95
29
  # since the header payload contains a timestamp.
@@ -22,23 +22,18 @@ module NewRelic
22
22
  @error_trace_aggregator = ErrorTraceAggregator.new(MAX_ERROR_QUEUE_LENGTH)
23
23
  @error_event_aggregator = ErrorEventAggregator.new events
24
24
 
25
- # lookup of exception class names to ignore. Hash for fast access
26
- @ignore = {}
27
-
28
- initialize_ignored_errors(Agent.config[:'error_collector.ignore_errors'])
29
-
30
- Agent.config.register_callback(:'error_collector.ignore_errors') do |ignore_errors|
31
- initialize_ignored_errors(ignore_errors)
25
+ @error_filter = NewRelic::Agent::ErrorFilter.new
26
+
27
+ %w(
28
+ ignore_errors ignore_classes ignore_messages ignore_status_codes
29
+ expected_classes expected_messages expected_status_codes
30
+ ).each do |w|
31
+ Agent.config.register_callback(:"error_collector.#{w}") do |value|
32
+ @error_filter.load_from_config(w, value)
33
+ end
32
34
  end
33
35
  end
34
36
 
35
- def initialize_ignored_errors(ignore_errors)
36
- @ignore.clear
37
- ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String
38
- ignore_errors.each { |error| error.strip! }
39
- ignore(ignore_errors)
40
- end
41
-
42
37
  def enabled?
43
38
  error_trace_aggregator.enabled? || error_event_aggregator.enabled?
44
39
  end
@@ -76,30 +71,39 @@ module NewRelic
76
71
  defined?(@ignore_filter) ? @ignore_filter : nil
77
72
  end
78
73
 
79
- # errors is an array of Exception Class Names
80
- #
81
74
  def ignore(errors)
82
- errors.each do |error|
83
- @ignore[error] = true
84
- ::NewRelic::Agent.logger.debug("Ignoring errors of type '#{error}'")
85
- end
75
+ @error_filter.ignore(errors)
76
+ end
77
+
78
+ def ignore?(ex, status_code = nil)
79
+ @error_filter.ignore?(ex, status_code)
80
+ end
81
+
82
+ def expect(errors)
83
+ @error_filter.expect(errors)
84
+ end
85
+
86
+ def expected?(ex, status_code = nil)
87
+ @error_filter.expected?(ex, status_code)
88
+ end
89
+
90
+ def load_error_filters
91
+ @error_filter.load_all
92
+ end
93
+
94
+ def reset_error_filters
95
+ @error_filter.reset
86
96
  end
87
97
 
88
98
  # Checks the provided error against the error filter, if there
89
99
  # is an error filter
90
- def filtered_by_error_filter?(error)
100
+ def ignored_by_filter_proc?(error)
91
101
  respond_to?(:ignore_filter_proc) && !ignore_filter_proc(error)
92
102
  end
93
103
 
94
- # Checks the array of error names and the error filter against
95
- # the provided error
96
- def filtered_error?(error)
97
- @ignore[error.class.name] || filtered_by_error_filter?(error)
98
- end
99
-
100
104
  # an error is ignored if it is nil or if it is filtered
101
- def error_is_ignored?(error)
102
- error && filtered_error?(error)
105
+ def error_is_ignored?(error, status_code = nil)
106
+ error && (@error_filter.ignore?(error, status_code) || ignored_by_filter_proc?(error))
103
107
  rescue => e
104
108
  NewRelic::Agent.logger.error("Error '#{error}' will NOT be ignored. Exception '#{e}' while determining whether to ignore or not.", e)
105
109
  false
@@ -174,11 +178,18 @@ module NewRelic
174
178
  end
175
179
  end
176
180
 
177
- def skip_notice_error?(exception)
181
+ def increment_expected_error_count!(state, exception)
182
+ stats_engine = NewRelic::Agent.agent.stats_engine
183
+ stats_engine.record_unscoped_metrics(state, ['ErrorsExpected/all']) do |stats|
184
+ stats.increment_count
185
+ end
186
+ end
187
+
188
+ def skip_notice_error?(exception, status_code = nil)
178
189
  disabled? ||
179
- error_is_ignored?(exception) ||
180
190
  exception.nil? ||
181
- exception_tagged_with?(EXCEPTION_TAG_IVAR, exception)
191
+ exception_tagged_with?(EXCEPTION_TAG_IVAR, exception) ||
192
+ error_is_ignored?(exception, status_code)
182
193
  end
183
194
 
184
195
  # calls a method on an object, if it responds to it - used for
@@ -210,13 +221,17 @@ module NewRelic
210
221
 
211
222
  # See NewRelic::Agent.notice_error for options and commentary
212
223
  def notice_error(exception, options={}, span_id=nil)
213
- return if skip_notice_error?(exception)
224
+ state = ::NewRelic::Agent::Tracer.state
225
+ transaction = state.current_transaction
226
+ status_code = transaction ? transaction.http_response_code : nil
214
227
 
215
- tag_exception(exception)
228
+ return if skip_notice_error?(exception, status_code)
216
229
 
217
- state = ::NewRelic::Agent::Tracer.state
230
+ tag_exception(exception)
218
231
 
219
- unless options[:expected]
232
+ if options[:expected] || @error_filter.expected?(exception, status_code)
233
+ increment_expected_error_count!(state, exception)
234
+ else
220
235
  increment_error_count!(state, exception, options)
221
236
  end
222
237
 
@@ -258,7 +273,7 @@ module NewRelic
258
273
  noticed_error.line_number = sense_method(exception, :line_number)
259
274
  noticed_error.stack_trace = truncate_trace(extract_stack_trace(exception))
260
275
 
261
- noticed_error.expected = !! options.delete(:expected)
276
+ noticed_error.expected = !!options.delete(:expected) || expected?(exception)
262
277
 
263
278
  noticed_error.attributes_from_notice_error = options.delete(:custom_params) || {}
264
279