newrelic_rpm 7.0.0 → 8.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/CHANGELOG.md +187 -0
  4. data/CONTRIBUTING.md +13 -2
  5. data/README.md +5 -1
  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/commands/thread_profiler_session.rb +7 -3
  9. data/lib/new_relic/agent/configuration/default_source.rb +223 -158
  10. data/lib/new_relic/agent/configuration/event_harvest_config.rb +28 -12
  11. data/lib/new_relic/agent/configuration/manager.rb +1 -2
  12. data/lib/new_relic/agent/configuration/server_source.rb +3 -2
  13. data/lib/new_relic/agent/configuration/yaml_source.rb +22 -1
  14. data/lib/new_relic/agent/connect/request_builder.rb +4 -2
  15. data/lib/new_relic/agent/custom_event_aggregator.rb +2 -1
  16. data/lib/new_relic/agent/database.rb +5 -2
  17. data/lib/new_relic/agent/datastores/mongo.rb +5 -10
  18. data/lib/new_relic/agent/datastores.rb +7 -7
  19. data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +5 -5
  20. data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +10 -6
  21. data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +0 -1
  22. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +1 -1
  23. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +1 -1
  24. data/lib/new_relic/agent/error_collector.rb +52 -37
  25. data/lib/new_relic/agent/error_filter.rb +175 -0
  26. data/lib/new_relic/agent/event_loop.rb +6 -6
  27. data/lib/new_relic/agent/external.rb +0 -32
  28. data/lib/new_relic/agent/http_clients/abstract.rb +2 -2
  29. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +7 -1
  30. data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -3
  32. data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -3
  33. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +2 -1
  35. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +4 -4
  36. data/lib/new_relic/agent/instrumentation/excon.rb +4 -23
  37. data/lib/new_relic/agent/instrumentation/logger/chain.rb +21 -0
  38. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +59 -0
  39. data/lib/new_relic/agent/instrumentation/logger/prepend.rb +13 -0
  40. data/lib/new_relic/agent/instrumentation/logger.rb +25 -0
  41. data/lib/new_relic/agent/instrumentation/mongo.rb +3 -141
  42. data/lib/new_relic/agent/instrumentation/net_http.rb +6 -1
  43. data/lib/new_relic/agent/instrumentation/padrino/chain.rb +23 -19
  44. data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -1
  45. data/lib/new_relic/agent/instrumentation/padrino.rb +4 -2
  46. data/lib/new_relic/agent/instrumentation/queue_time.rb +4 -4
  47. data/lib/new_relic/agent/instrumentation/rack/chain.rb +3 -2
  48. data/lib/new_relic/agent/instrumentation/rack/prepend.rb +2 -1
  49. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +5 -5
  50. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +1 -1
  51. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -41
  52. data/lib/new_relic/agent/instrumentation/redis.rb +4 -0
  53. data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
  54. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +5 -3
  55. data/lib/new_relic/agent/instrumentation/resque.rb +13 -4
  56. data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -1
  57. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +8 -2
  58. data/lib/new_relic/agent/javascript_instrumentor.rb +15 -10
  59. data/lib/new_relic/agent/messaging.rb +10 -24
  60. data/lib/new_relic/agent/method_tracer.rb +137 -138
  61. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +6 -1
  62. data/lib/new_relic/agent/new_relic_service.rb +16 -12
  63. data/lib/new_relic/agent/pipe_channel_manager.rb +10 -6
  64. data/lib/new_relic/agent/pipe_service.rb +1 -1
  65. data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
  66. data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +9 -6
  67. data/lib/new_relic/agent/span_event_aggregator.rb +2 -2
  68. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  69. data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
  70. data/lib/new_relic/agent/stats_engine.rb +1 -1
  71. data/lib/new_relic/agent/threading/backtrace_service.rb +4 -5
  72. data/lib/new_relic/agent/threading/thread_profile.rb +1 -1
  73. data/lib/new_relic/agent/tracer.rb +15 -37
  74. data/lib/new_relic/agent/transaction/abstract_segment.rb +3 -3
  75. data/lib/new_relic/agent/transaction/message_broker_segment.rb +5 -11
  76. data/lib/new_relic/agent/transaction.rb +7 -28
  77. data/lib/new_relic/agent/transaction_time_aggregator.rb +5 -5
  78. data/lib/new_relic/agent/vm/snapshot.rb +1 -1
  79. data/lib/new_relic/agent/worker_loop.rb +5 -5
  80. data/lib/new_relic/agent.rb +10 -7
  81. data/lib/new_relic/cli/commands/deployments.rb +2 -2
  82. data/lib/new_relic/constants.rb +0 -4
  83. data/lib/new_relic/noticed_error.rb +4 -4
  84. data/lib/new_relic/version.rb +2 -2
  85. data/lib/newrelic_rpm.rb +10 -34
  86. data/lib/tasks/all.rb +1 -1
  87. data/lib/tasks/config.html.erb +14 -25
  88. data/lib/tasks/config.rake +8 -7
  89. data/newrelic.yml +594 -3
  90. data/newrelic_rpm.gemspec +1 -1
  91. data/test/agent_helper.rb +27 -2
  92. metadata +9 -9
  93. data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +0 -53
  94. data/lib/new_relic/agent/instrumentation/excon/connection.rb +0 -49
  95. data/lib/new_relic/agent/instrumentation/merb/controller.rb +0 -44
  96. data/lib/new_relic/agent/instrumentation/merb/errors.rb +0 -33
  97. data/lib/new_relic/agent/supported_versions.rb +0 -275
  98. data/lib/new_relic/control/frameworks/merb.rb +0 -29
@@ -15,7 +15,7 @@ module NewRelic
15
15
  ALL_QUEUE_METRIC = 'WebFrontend/QueueTime'.freeze
16
16
  # any timestamps before this are thrown out and the parser
17
17
  # will try again with a larger unit (2000/1/1 UTC)
18
- EARLIEST_ACCEPTABLE_TIME = Time.at(946684800)
18
+ EARLIEST_ACCEPTABLE_TIME = Time.at(946684800).to_f
19
19
 
20
20
  CANDIDATE_HEADERS = [
21
21
  REQUEST_START_HEADER,
@@ -27,7 +27,7 @@ module NewRelic
27
27
 
28
28
  module_function
29
29
 
30
- def parse_frontend_timestamp(headers, now=Time.now)
30
+ def parse_frontend_timestamp(headers, now=Process.clock_gettime(Process::CLOCK_REALTIME))
31
31
  earliest = nil
32
32
 
33
33
  CANDIDATE_HEADERS.each do |header|
@@ -40,7 +40,7 @@ module NewRelic
40
40
  end
41
41
 
42
42
  if earliest && earliest > now
43
- NewRelic::Agent.logger.debug("Negative queue time detected, treating as zero: start=#{earliest.to_f} > now=#{now.to_f}")
43
+ NewRelic::Agent.logger.debug("Negative queue time detected, treating as zero: start=#{earliest.to_f} > now=#{now}")
44
44
  earliest = now
45
45
  end
46
46
 
@@ -59,7 +59,7 @@ module NewRelic
59
59
  def parse_timestamp(string)
60
60
  DIVISORS.each do |divisor|
61
61
  begin
62
- t = Time.at(string.to_f / divisor)
62
+ t = (string.to_f / divisor)
63
63
  return t if t > EARLIEST_ACCEPTABLE_TIME
64
64
  rescue RangeError
65
65
  # On Ruby versions built with a 32-bit time_t, attempting to
@@ -31,7 +31,8 @@ module NewRelic::Agent::Instrumentation
31
31
  def use_with_newrelic(middleware_class, *args, &block)
32
32
  use_with_tracing(middleware_class) { |wrapped_class| use_without_newrelic(wrapped_class, *args, &block) }
33
33
  end
34
-
34
+ ruby2_keywords(:use_with_newrelic) if respond_to?(:ruby2_keywords, true)
35
+
35
36
  alias_method :use_without_newrelic, :use
36
37
  alias_method :use, :use_with_newrelic
37
38
  end
@@ -54,4 +55,4 @@ module NewRelic::Agent::Instrumentation
54
55
  end
55
56
  end
56
57
  end
57
- end
58
+ end
@@ -31,6 +31,7 @@ module NewRelic::Agent::Instrumentation
31
31
  def use(middleware_class, *args, &blk)
32
32
  use_with_tracing(middleware_class) { |wrapped_class| super(wrapped_class, *args, &blk) }
33
33
  end
34
+ ruby2_keywords(:use) if respond_to?(:ruby2_keywords, true)
34
35
  end
35
36
  end
36
- end
37
+ end
@@ -20,13 +20,13 @@ DependencyDetection.defer do
20
20
  executes do
21
21
  ActionView::PartialTemplate.class_eval do
22
22
  include NewRelic::Agent::MethodTracer
23
- add_method_tracer :render, 'View/#{path_without_extension[%r{^(/.*/)?(.*)$},2]}.#{@view.template_format}.#{extension}/Partial'
23
+ add_method_tracer :render, -> (*) { "View/#{path_without_extension[%r{^(/.*/)?(.*)$},2]}.#{@view.template_format}.#{extension}/Partial" }
24
24
  end
25
25
 
26
26
  # this is for template rendering, as opposed to partial rendering.
27
27
  ActionView::Template.class_eval do
28
28
  include NewRelic::Agent::MethodTracer
29
- add_method_tracer :render, 'View/#{(path_without_extension || @view.controller.newrelic_metric_path)[%r{^(/.*/)?(.*)$},2]}.#{@view.template_format}.#{extension}/Rendering'
29
+ add_method_tracer :render, -> (*) { "View/#{(path_without_extension || @view.controller.newrelic_metric_path)[%r{^(/.*/)?(.*)$},2]}.#{@view.template_format}.#{extension}/Rendering" }
30
30
  end
31
31
  end
32
32
  end
@@ -47,7 +47,7 @@ DependencyDetection.defer do
47
47
  executes do
48
48
  ActionController::Base.class_eval do
49
49
  include NewRelic::Agent::MethodTracer
50
- add_method_tracer :render, 'View/#{newrelic_metric_path}/Rendering'
50
+ add_method_tracer :render, -> (*) { "View/#{newrelic_metric_path}/Rendering" }
51
51
  end
52
52
  end
53
53
  end
@@ -68,12 +68,12 @@ DependencyDetection.defer do
68
68
  executes do
69
69
  ActionView::RenderablePartial.module_eval do
70
70
  include NewRelic::Agent::MethodTracer
71
- add_method_tracer :render_partial, 'View/#{path[%r{^(/.*/)?(.*)$},2]}/Partial'
71
+ add_method_tracer :render_partial, -> (*) { "View/#{path[%r{^(/.*/)?(.*)$},2]}/Partial" }
72
72
  end
73
73
 
74
74
  ActionView::Template.class_eval do
75
75
  include NewRelic::Agent::MethodTracer
76
- add_method_tracer :render, 'View/#{path[%r{^(/.*/)?(.*)$},2]}/Rendering'
76
+ add_method_tracer :render, -> (*) { "View/#{path[%r{^(/.*/)?(.*)$},2]}/Rendering" }
77
77
  end
78
78
  end
79
79
  end
@@ -38,7 +38,7 @@ DependencyDetection.defer do
38
38
  if defined?(ActionController) && defined?(ActionController::Base)
39
39
  ActionController::Base.class_eval do
40
40
  if method_defined? :perform_invocation
41
- add_method_tracer :perform_invocation, 'WebService/#{controller_name}/#{args.first}'
41
+ add_method_tracer :perform_invocation, -> (*args) { "WebService/#{controller_name}/#{args.first}" }
42
42
  end
43
43
  end
44
44
  end
@@ -84,52 +84,16 @@ DependencyDetection.defer do
84
84
  end
85
85
  end
86
86
  end
87
- DependencyDetection.defer do
88
- @name = :rails30_view
89
-
90
- depends_on do
91
- defined?(::Rails::VERSION::MAJOR) && defined?(::Rails::VERSION::MINOR) &&
92
- ::Rails::VERSION::MAJOR.to_i == 3 && ::Rails::VERSION::MINOR.to_i == 0
93
- end
94
-
95
- depends_on do
96
- !NewRelic::Agent.config[:disable_view_instrumentation]
97
- end
98
-
99
- executes do
100
- ::NewRelic::Agent.logger.info 'Installing Rails 3.0 view instrumentation'
101
- end
102
-
103
- executes do
104
- ActionView::Template.class_eval do
105
- include NewRelic::Agent::MethodTracer
106
- def render_with_newrelic(*args, &block)
107
- options = if @virtual_path && @virtual_path.starts_with?('/') # file render
108
- {:file => true }
109
- else
110
- {}
111
- end
112
- str = "View/#{NewRelic::Agent::Instrumentation::Rails3::ActionView::NewRelic.template_metric(@identifier, options)}/#{NewRelic::Agent::Instrumentation::Rails3::ActionView::NewRelic.render_type(@identifier)}"
113
- trace_execution_scoped str do
114
- render_without_newrelic(*args, &block)
115
- end
116
- end
117
-
118
- alias_method :render_without_newrelic, :render
119
- alias_method :render, :render_with_newrelic
120
-
121
- end
122
- end
123
- end
124
87
 
88
+ # Though this uses the name :rails31_view, it is used only for rails 3.2 now
89
+ # Rails 3.1 is no longer supported by the agent.
125
90
  DependencyDetection.defer do
126
91
  @name = :rails31_view
127
92
 
128
- # We can't be sure that this will work with future versions of Rails 3.
129
- # Currently enabled for Rails 3.1 and 3.2
93
+ # Enabled for Rails 3.2
130
94
  depends_on do
131
95
  defined?(::Rails::VERSION::MAJOR) && defined?(::Rails::VERSION::MINOR) &&
132
- ::Rails::VERSION::MAJOR.to_i == 3 && ([1,2].member?(::Rails::VERSION::MINOR.to_i))
96
+ ::Rails::VERSION::MAJOR.to_i == 3 && ::Rails::VERSION::MINOR.to_i == 2
133
97
  end
134
98
 
135
99
  depends_on do
@@ -137,7 +101,7 @@ DependencyDetection.defer do
137
101
  end
138
102
 
139
103
  executes do
140
- ::NewRelic::Agent.logger.info 'Installing Rails 3.1/3.2 view instrumentation'
104
+ ::NewRelic::Agent.logger.info 'Installing Rails 3.2 view instrumentation'
141
105
  end
142
106
 
143
107
  executes do
@@ -18,6 +18,10 @@ DependencyDetection.defer do
18
18
  defined?(::Redis) && defined?(::Redis::VERSION)
19
19
  end
20
20
 
21
+ conflicts_with_prepend do
22
+ defined?(::PrometheusExporter)
23
+ end
24
+
21
25
  depends_on do
22
26
  NewRelic::Agent::Datastores::Redis.is_supported_version? &&
23
27
  NewRelic::Agent::Datastores::Redis.safe_from_third_party_gem?
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
4
+
5
+ module NewRelic
6
+ module Agent
7
+ module Instrumentation
8
+ module Resque
9
+ module Helper
10
+ extend self
11
+
12
+ def resque_fork_per_job?
13
+ ENV["FORK_PER_JOB"] != 'false' && NewRelic::LanguageSupport.can_fork?
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -6,7 +6,7 @@
6
6
  module NewRelic::Agent::Instrumentation
7
7
  module Resque
8
8
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
9
-
9
+
10
10
  def with_tracing
11
11
  begin
12
12
  perform_action_with_newrelic_trace(
@@ -24,8 +24,10 @@ module NewRelic::Agent::Instrumentation
24
24
  ensure
25
25
  # Stopping the event loop before flushing the pipe.
26
26
  # The goal is to avoid conflict during write.
27
- NewRelic::Agent.agent.stop_event_loop
28
- NewRelic::Agent.agent.flush_pipe_data
27
+ if NewRelic::Agent::Instrumentation::Resque::Helper.resque_fork_per_job?
28
+ NewRelic::Agent.agent.stop_event_loop
29
+ NewRelic::Agent.agent.flush_pipe_data
30
+ end
29
31
  end
30
32
  end
31
33
 
@@ -13,6 +13,11 @@ DependencyDetection.defer do
13
13
  defined?(::Resque::Job) && !NewRelic::Agent.config[:disable_resque]
14
14
  end
15
15
 
16
+ # Airbrake uses method chaining on Resque::Job on versions < 11.0.3
17
+ conflicts_with_prepend do
18
+ defined?(::Airbrake) && defined?(::Airbrake::AIRBRAKE_VERSION) && ::Gem::Version.create(::Airbrake::AIRBRAKE_VERSION) < ::Gem::Version.create('11.0.3')
19
+ end
20
+
16
21
  executes do
17
22
  ::NewRelic::Agent.logger.info 'Installing Resque instrumentation'
18
23
  end
@@ -32,7 +37,7 @@ DependencyDetection.defer do
32
37
  chain_instrument NewRelic::Agent::Instrumentation::Resque::Chain
33
38
  end
34
39
 
35
- if NewRelic::LanguageSupport.can_fork?
40
+ if NewRelic::Agent::Instrumentation::Resque::Helper.resque_fork_per_job?
36
41
  ::Resque.before_first_fork do
37
42
  NewRelic::Agent.manual_start(:dispatcher => :resque,
38
43
  :sync_startup => true,
@@ -40,9 +45,7 @@ DependencyDetection.defer do
40
45
  end
41
46
 
42
47
  ::Resque.before_fork do |job|
43
- if ENV['FORK_PER_JOB'] != 'false'
44
- NewRelic::Agent.register_report_channel(job.object_id)
45
- end
48
+ NewRelic::Agent.register_report_channel(job.object_id)
46
49
  end
47
50
 
48
51
  ::Resque.after_fork do |job|
@@ -51,6 +54,12 @@ DependencyDetection.defer do
51
54
  NewRelic::Agent.after_fork(:report_to_channel => job.object_id,
52
55
  :report_instance_busy => false)
53
56
  end
57
+ else
58
+ ::Resque.before_first_fork do
59
+ NewRelic::Agent.manual_start(:dispatcher => :resque,
60
+ :sync_startup => true,
61
+ :start_channel_listener => false)
62
+ end
54
63
  end
55
64
  end
56
65
  end
@@ -60,7 +60,12 @@ DependencyDetection.defer do
60
60
 
61
61
  class Sidekiq::Extensions::DelayedClass
62
62
  def newrelic_trace_args(msg, queue)
63
- (target, method_name, _args) = YAML.load(msg['args'][0])
63
+ (target, method_name, _args) = if YAML.respond_to?(:unsafe_load)
64
+ YAML.unsafe_load(msg['args'][0])
65
+ else
66
+ YAML.load(msg['args'][0])
67
+ end
68
+
64
69
  {
65
70
  :name => method_name,
66
71
  :class_name => target.name,
@@ -39,9 +39,15 @@ module NewRelic::Agent::Instrumentation
39
39
  yield
40
40
  end
41
41
 
42
+ def install_lock
43
+ @install_lock ||= Mutex.new
44
+ end
45
+
42
46
  def try_to_use(app, clazz)
43
- has_middleware = app.middleware.any? { |info| info[0] == clazz }
44
- app.use(clazz) unless has_middleware
47
+ install_lock.synchronize do
48
+ has_middleware = app.middleware && app.middleware.any? { |info| info && info[0] == clazz }
49
+ app.use(clazz) unless has_middleware
50
+ end
45
51
  end
46
52
 
47
53
  # Capture last route we've seen. Will set for transaction on route_eval
@@ -83,39 +83,44 @@ module NewRelic
83
83
  value.nil? || value.empty?
84
84
  end
85
85
 
86
- def browser_timing_header #THREAD_LOCAL_ACCESS
86
+ def browser_timing_header(nonce=nil) #THREAD_LOCAL_ACCESS
87
87
  return '' unless js_enabled_and_ready? # fast exit
88
88
 
89
89
  state = NewRelic::Agent::Tracer.state
90
90
 
91
91
  return '' unless insert_js?(state) # slower exit
92
92
 
93
- bt_config = browser_timing_config(state)
93
+ bt_config = browser_timing_config(state, nonce)
94
94
  return '' if bt_config.empty?
95
95
 
96
- bt_config + browser_timing_loader
96
+ bt_config + browser_timing_loader(nonce)
97
97
  rescue => e
98
98
  ::NewRelic::Agent.logger.debug "Failure during RUM browser_timing_header construction", e
99
99
  ''
100
100
  end
101
101
 
102
- def browser_timing_loader
103
- html_safe_if_needed("\n<script>#{Agent.config[:js_agent_loader]}</script>")
102
+ def browser_timing_loader(nonce=nil)
103
+ html_safe_if_needed("\n<script type=\"text/javascript\"#{create_nonce(nonce)}>#{Agent.config[:js_agent_loader]}</script>")
104
104
  end
105
105
 
106
- def browser_timing_config(state)
106
+ def browser_timing_config(state, nonce=nil)
107
107
  txn = state.current_transaction
108
108
  return '' if txn.nil?
109
109
 
110
110
  txn.freeze_name_and_execute_if_not_ignored do
111
111
  data = data_for_js_agent(txn)
112
112
  json = ::JSON.dump(data)
113
- return html_safe_if_needed("\n<script>window.NREUM||(NREUM={});NREUM.info=#{json}</script>")
113
+ return html_safe_if_needed("\n<script type=\"text/javascript\"#{create_nonce(nonce)}>window.NREUM||(NREUM={});NREUM.info=#{json}</script>")
114
114
  end
115
115
 
116
116
  ''
117
117
  end
118
118
 
119
+ def create_nonce(nonce=nil)
120
+ return '' unless nonce
121
+ " nonce=\"#{nonce.to_s}\""
122
+ end
123
+
119
124
  BEACON_KEY = "beacon".freeze
120
125
  ERROR_BEACON_KEY = "errorBeacon".freeze
121
126
  LICENSE_KEY_KEY = "licenseKey".freeze
@@ -131,9 +136,9 @@ module NewRelic
131
136
 
132
137
  # NOTE: Internal prototyping may override this, so leave name stable!
133
138
  def data_for_js_agent(transaction)
134
- queue_time_in_seconds = [transaction.queue_time.to_f, 0.0].max
135
- start_time_in_seconds = [transaction.start_time.to_f, 0.0].max
136
- app_time_in_seconds = Time.now.to_f - start_time_in_seconds
139
+ queue_time_in_seconds = [transaction.queue_time, 0.0].max
140
+ start_time_in_seconds = [transaction.start_time, 0.0].max
141
+ app_time_in_seconds = Process.clock_gettime(Process::CLOCK_REALTIME) - start_time_in_seconds
137
142
 
138
143
  queue_time_in_millis = (1000.0 * queue_time_in_seconds).round
139
144
  app_time_in_millis = (1000.0 * app_time_in_seconds).round
@@ -110,20 +110,15 @@ module NewRelic
110
110
  #
111
111
  # @api public
112
112
  #
113
- def wrap_message_broker_consume_transaction library: nil,
114
- destination_type: nil,
115
- destination_name: nil,
113
+ def wrap_message_broker_consume_transaction(library:,
114
+ destination_type:,
115
+ destination_name:,
116
116
  headers: nil,
117
117
  routing_key: nil,
118
118
  queue_name: nil,
119
119
  exchange_type: nil,
120
120
  reply_to: nil,
121
- correlation_id: nil
122
-
123
- # ruby 2.0.0 does not support required kwargs
124
- raise ArgumentError, 'missing required argument: library' if library.nil?
125
- raise ArgumentError, 'missing required argument: destination_type' if destination_type.nil?
126
- raise ArgumentError, 'missing required argument: destination_name' if destination_name.nil?
121
+ correlation_id: nil)
127
122
 
128
123
  state = Tracer.state
129
124
  return yield if state.current_transaction
@@ -185,17 +180,14 @@ module NewRelic
185
180
  #
186
181
  # @api public
187
182
  #
188
- def start_amqp_publish_segment(library: nil,
189
- destination_name: nil,
183
+ def start_amqp_publish_segment(library:,
184
+ destination_name:,
190
185
  headers: nil,
191
186
  routing_key: nil,
192
187
  reply_to: nil,
193
188
  correlation_id: nil,
194
189
  exchange_type: nil)
195
190
 
196
- # ruby 2.0.0 does not support required kwargs
197
- raise ArgumentError, 'missing required argument: library' if library.nil?
198
- raise ArgumentError, 'missing required argument: destination_name' if destination_name.nil?
199
191
  raise ArgumentError, 'missing required argument: headers' if headers.nil? && CrossAppTracing.cross_app_enabled?
200
192
 
201
193
  original_headers = headers.nil? ? nil : headers.dup
@@ -247,20 +239,14 @@ module NewRelic
247
239
  #
248
240
  # @api public
249
241
  #
250
- def start_amqp_consume_segment(library: nil,
251
- destination_name: nil,
252
- delivery_info: nil,
253
- message_properties: nil,
242
+ def start_amqp_consume_segment(library:,
243
+ destination_name:,
244
+ delivery_info:,
245
+ message_properties:,
254
246
  exchange_type: nil,
255
247
  queue_name: nil,
256
248
  start_time: nil)
257
249
 
258
- # ruby 2.0.0 does not support required kwargs
259
- raise ArgumentError, 'missing required argument: library' if library.nil?
260
- raise ArgumentError, 'missing required argument: destination_name' if destination_name.nil?
261
- raise ArgumentError, 'missing required argument: delivery_info' if delivery_info.nil?
262
- raise ArgumentError, 'missing required argument: message_properties' if message_properties.nil?
263
-
264
250
  segment = Tracer.start_message_broker_segment(
265
251
  action: :consume,
266
252
  library: library,