newrelic_rpm 6.4.0.356 → 6.9.0.363

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +50 -5
  4. data/CHANGELOG.md +218 -0
  5. data/Guardfile +16 -1
  6. data/lib/new_relic/agent.rb +86 -5
  7. data/lib/new_relic/agent/agent.rb +124 -56
  8. data/lib/new_relic/agent/agent_logger.rb +4 -0
  9. data/lib/new_relic/agent/attribute_filter.rb +7 -7
  10. data/lib/new_relic/agent/attributes.rb +150 -0
  11. data/lib/new_relic/agent/autostart.rb +19 -14
  12. data/lib/new_relic/agent/configuration/default_source.rb +133 -14
  13. data/lib/new_relic/agent/configuration/event_harvest_config.rb +45 -0
  14. data/lib/new_relic/agent/configuration/manager.rb +13 -9
  15. data/lib/new_relic/agent/configuration/server_source.rb +34 -10
  16. data/lib/new_relic/agent/configuration/yaml_source.rb +11 -6
  17. data/lib/new_relic/agent/connect/request_builder.rb +8 -15
  18. data/lib/new_relic/agent/connect/response_handler.rb +1 -1
  19. data/lib/new_relic/agent/database.rb +1 -2
  20. data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -2
  21. data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +8 -8
  22. data/lib/new_relic/agent/distributed_tracing.rb +155 -6
  23. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +0 -0
  24. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +60 -45
  25. data/lib/new_relic/agent/distributed_tracing/distributed_trace_intrinsics.rb +80 -0
  26. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  27. data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +23 -99
  28. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  29. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  30. data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
  31. data/lib/new_relic/agent/error_collector.rb +5 -7
  32. data/lib/new_relic/agent/error_event_aggregator.rb +5 -2
  33. data/lib/new_relic/agent/error_trace_aggregator.rb +1 -0
  34. data/lib/new_relic/agent/event_aggregator.rb +26 -32
  35. data/lib/new_relic/agent/external.rb +7 -7
  36. data/lib/new_relic/agent/guid_generator.rb +28 -0
  37. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +1 -2
  38. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +24 -38
  39. data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +2 -2
  40. data/lib/new_relic/agent/instrumentation/bunny.rb +1 -1
  41. data/lib/new_relic/agent/instrumentation/curb.rb +1 -1
  42. data/lib/new_relic/agent/instrumentation/excon.rb +1 -1
  43. data/lib/new_relic/agent/instrumentation/grape.rb +5 -10
  44. data/lib/new_relic/agent/instrumentation/http.rb +1 -1
  45. data/lib/new_relic/agent/instrumentation/httpclient.rb +1 -1
  46. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  47. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +2 -3
  48. data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
  49. data/lib/new_relic/agent/instrumentation/typhoeus.rb +1 -1
  50. data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
  51. data/lib/new_relic/agent/logging.rb +139 -0
  52. data/lib/new_relic/agent/messaging.rb +5 -73
  53. data/lib/new_relic/agent/method_tracer.rb +3 -2
  54. data/lib/new_relic/agent/method_tracer_helpers.rb +1 -1
  55. data/lib/new_relic/agent/monitors.rb +27 -0
  56. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  57. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  58. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +3 -3
  59. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
  60. data/lib/new_relic/agent/new_relic_service.rb +7 -5
  61. data/lib/new_relic/agent/priority_sampled_buffer.rb +2 -0
  62. data/lib/new_relic/agent/span_event_aggregator.rb +2 -4
  63. data/lib/new_relic/agent/span_event_primitive.rb +43 -25
  64. data/lib/new_relic/agent/sql_sampler.rb +3 -3
  65. data/lib/new_relic/agent/supported_versions.rb +2 -2
  66. data/lib/new_relic/agent/tracer.rb +35 -3
  67. data/lib/new_relic/agent/transaction.rb +37 -36
  68. data/lib/new_relic/agent/transaction/abstract_segment.rb +2 -2
  69. data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
  70. data/lib/new_relic/agent/transaction/distributed_tracing.rb +57 -146
  71. data/lib/new_relic/agent/transaction/external_request_segment.rb +8 -31
  72. data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -11
  73. data/lib/new_relic/agent/transaction/segment.rb +7 -1
  74. data/lib/new_relic/agent/transaction/trace.rb +2 -4
  75. data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
  76. data/lib/new_relic/agent/transaction/trace_node.rb +10 -8
  77. data/lib/new_relic/agent/transaction_error_primitive.rb +5 -12
  78. data/lib/new_relic/agent/transaction_event_primitive.rb +28 -39
  79. data/lib/new_relic/agent/transaction_event_recorder.rb +3 -3
  80. data/lib/new_relic/cli/commands/deployments.rb +1 -1
  81. data/lib/new_relic/coerce.rb +31 -6
  82. data/lib/new_relic/constants.rb +34 -0
  83. data/lib/new_relic/control/instance_methods.rb +10 -1
  84. data/lib/new_relic/dependency_detection.rb +4 -4
  85. data/lib/new_relic/noticed_error.rb +10 -8
  86. data/lib/new_relic/rack/browser_monitoring.rb +4 -0
  87. data/lib/new_relic/supportability_helper.rb +14 -0
  88. data/lib/new_relic/version.rb +1 -1
  89. data/lib/tasks/tests.rake +6 -1
  90. data/newrelic_rpm.gemspec +16 -5
  91. data/test/agent_helper.rb +115 -9
  92. data/true +0 -0
  93. metadata +97 -30
  94. data/lib/new_relic/agent/configuration/event_data.rb +0 -39
  95. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  96. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
  97. data/lib/new_relic/agent/transaction/attributes.rb +0 -154
  98. data/lib/tasks/versions.html.erb +0 -28
  99. data/lib/tasks/versions.postface.html +0 -8
  100. data/lib/tasks/versions.preface.html +0 -9
  101. data/lib/tasks/versions.rake +0 -65
  102. data/lib/tasks/versions.txt.erb +0 -14
@@ -0,0 +1,126 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ require 'new_relic/coerce'
6
+
7
+ module NewRelic
8
+ module Agent
9
+ class TraceContextPayload
10
+ VERSION = 0
11
+ PARENT_TYPE = 0
12
+ DELIMITER = "-".freeze
13
+ SUPPORTABILITY_PARSE_EXCEPTION = "Supportability/TraceContext/Parse/Exception".freeze
14
+
15
+ TRUE_CHAR = '1'.freeze
16
+ FALSE_CHAR = '0'.freeze
17
+
18
+ PARENT_TYPES = %w(App Browser Mobile).map(&:freeze).freeze
19
+
20
+ class << self
21
+ def create version: VERSION,
22
+ parent_type: PARENT_TYPE,
23
+ parent_account_id: nil,
24
+ parent_app_id: nil,
25
+ id: nil,
26
+ transaction_id: nil,
27
+ sampled: nil,
28
+ priority: nil,
29
+ timestamp: now_ms
30
+
31
+ new version, parent_type, parent_account_id, parent_app_id, id,
32
+ transaction_id, sampled, priority, timestamp
33
+ end
34
+
35
+ include NewRelic::Coerce
36
+
37
+ def from_s payload_string
38
+ attrs = payload_string.split(DELIMITER)
39
+
40
+ payload = create \
41
+ version: int!(attrs[0]),
42
+ parent_type: int!(attrs[1]),
43
+ parent_account_id: attrs[2],
44
+ parent_app_id: attrs[3],
45
+ id: value_or_nil(attrs[4]),
46
+ transaction_id: value_or_nil(attrs[5]),
47
+ sampled: value_or_nil(attrs[6]) ? boolean_int!(attrs[6]) == 1 : nil,
48
+ priority: float!(attrs[7]),
49
+ timestamp: int!(attrs[8])
50
+ handle_invalid_payload message: 'payload missing attributes' unless payload.valid?
51
+ payload
52
+ rescue => e
53
+ handle_invalid_payload error: e
54
+ raise
55
+ end
56
+
57
+ private
58
+
59
+ def now_ms
60
+ (Time.now.to_f * 1000).round
61
+ end
62
+
63
+ def handle_invalid_payload error: nil, message: nil
64
+ NewRelic::Agent.increment_metric SUPPORTABILITY_PARSE_EXCEPTION
65
+ if error
66
+ NewRelic::Agent.logger.warn "Error parsing trace context payload", error
67
+ elsif message
68
+ NewRelic::Agent.logger.warn "Error parsing trace context payload: #{message}"
69
+ end
70
+ end
71
+ end
72
+
73
+ attr_accessor :version,
74
+ :parent_type_id,
75
+ :parent_account_id,
76
+ :parent_app_id,
77
+ :id,
78
+ :transaction_id,
79
+ :sampled,
80
+ :priority,
81
+ :timestamp
82
+
83
+ alias_method :sampled?, :sampled
84
+
85
+ def initialize version, parent_type_id, parent_account_id, parent_app_id,
86
+ id, transaction_id, sampled, priority, timestamp
87
+ @version = version
88
+ @parent_type_id = parent_type_id
89
+ @parent_account_id = parent_account_id
90
+ @parent_app_id = parent_app_id
91
+ @id = id
92
+ @transaction_id = transaction_id
93
+ @sampled = sampled
94
+ @priority = priority
95
+ @timestamp = timestamp
96
+ end
97
+
98
+ def parent_type
99
+ @parent_type_string ||= PARENT_TYPES[@parent_type_id]
100
+ end
101
+
102
+ def valid?
103
+ version \
104
+ && parent_type_id \
105
+ && !parent_account_id.empty? \
106
+ && !parent_app_id.empty? \
107
+ && timestamp
108
+ rescue
109
+ false
110
+ end
111
+
112
+ def to_s
113
+ result = version.to_s
114
+ result << DELIMITER << parent_type_id.to_s
115
+ result << DELIMITER << parent_account_id
116
+ result << DELIMITER << parent_app_id
117
+ result << DELIMITER << (id || NewRelic::EMPTY_STR)
118
+ result << DELIMITER << (transaction_id || NewRelic::EMPTY_STR)
119
+ result << DELIMITER << (sampled ? TRUE_CHAR : FALSE_CHAR)
120
+ result << DELIMITER << priority.to_s
121
+ result << DELIMITER << timestamp.to_s
122
+ result
123
+ end
124
+ end
125
+ end
126
+ end
@@ -18,9 +18,9 @@ module NewRelic
18
18
  attr_reader :error_trace_aggregator, :error_event_aggregator
19
19
 
20
20
  # Returns a new error collector
21
- def initialize
21
+ def initialize events
22
22
  @error_trace_aggregator = ErrorTraceAggregator.new(MAX_ERROR_QUEUE_LENGTH)
23
- @error_event_aggregator = ErrorEventAggregator.new
23
+ @error_event_aggregator = ErrorEventAggregator.new events
24
24
 
25
25
  # lookup of exception class names to ignore. Hash for fast access
26
26
  @ignore = {}
@@ -74,7 +74,7 @@ module NewRelic
74
74
  end
75
75
 
76
76
  def self.ignore_error_filter
77
- @ignore_filter
77
+ defined?(@ignore_filter) ? @ignore_filter : nil
78
78
  end
79
79
 
80
80
  # errors is an array of Exception Class Names
@@ -227,13 +227,11 @@ module NewRelic
227
227
  truncated_trace
228
228
  end
229
229
 
230
- EMPTY_STRING = ''.freeze
231
-
232
230
  def create_noticed_error(exception, options)
233
- error_metric = options.delete(:metric) || EMPTY_STRING
231
+ error_metric = options.delete(:metric) || NewRelic::EMPTY_STR
234
232
 
235
233
  noticed_error = NewRelic::NoticedError.new(error_metric, exception)
236
- noticed_error.request_uri = options.delete(:uri) || EMPTY_STRING
234
+ noticed_error.request_uri = options.delete(:uri) || NewRelic::EMPTY_STR
237
235
  noticed_error.request_port = options.delete(:port)
238
236
  noticed_error.attributes = options.delete(:attributes)
239
237
 
@@ -2,6 +2,7 @@
2
2
  # encoding: utf-8
3
3
  # This file is distributed under New Relic's license terms.
4
4
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
5
+ # frozen_string_literal: true
5
6
 
6
7
  require 'new_relic/agent/event_aggregator'
7
8
  require 'new_relic/agent/transaction_error_primitive'
@@ -10,16 +11,18 @@ require 'new_relic/agent/priority_sampled_buffer'
10
11
  module NewRelic
11
12
  module Agent
12
13
  class ErrorEventAggregator < EventAggregator
14
+ include NewRelic::Coerce
13
15
 
14
16
  named :ErrorEventAggregator
15
17
  capacity_key :'error_collector.max_event_samples_stored'
16
- enabled_key :'error_collector.capture_events'
18
+ enabled_keys :'error_collector.enabled',
19
+ :'error_collector.capture_events'
17
20
  buffer_class PrioritySampledBuffer
18
21
 
19
22
  def record noticed_error, transaction_payload = nil
20
23
  return unless enabled?
21
24
 
22
- priority = (transaction_payload && transaction_payload[:priority]) || rand.round(6)
25
+ priority = float!((transaction_payload && transaction_payload[:priority]) || rand)
23
26
 
24
27
  @lock.synchronize do
25
28
  @buffer.append(priority: priority) do
@@ -91,6 +91,7 @@ module NewRelic
91
91
 
92
92
  def register_config_callbacks
93
93
  Agent.config.register_callback(:'error_collector.enabled') do |enabled|
94
+ reset! if enabled == false
94
95
  ::NewRelic::Agent.logger.debug "Error traces will #{enabled ? '' : 'not '}be sent to the New Relic service."
95
96
  end
96
97
  end
@@ -8,20 +8,6 @@ module NewRelic
8
8
  module Agent
9
9
  class EventAggregator
10
10
  class << self
11
- # This architecture requires that every aggregator
12
- # implementation provide its own `named`, `capacity_key`, and
13
- # `enabled_...` settings. In particular, we do not allow
14
- # subclasses to share these values from an intermediate
15
- # superclass.
16
-
17
- def inherited(subclass)
18
- # Prevent uninitialized variable warnings; we have to do
19
- # this as soon as the subclass is defined, before its
20
- # implementor calls enabled_key() or enabled_fn().
21
- subclass.instance_variable_set(:@enabled_key, nil)
22
- subclass.instance_variable_set(:@enabled_fn, nil)
23
- end
24
-
25
11
  def named named = nil
26
12
  named ? @named = named.to_s.freeze : @named
27
13
  end
@@ -30,10 +16,25 @@ module NewRelic
30
16
  key ? @capacity_key = key : @capacity_key
31
17
  end
32
18
 
33
- def enabled_key key = nil
34
- key ? @enabled_key = key : @enabled_key
19
+ # An aggregator can specify one or more keys to check to see if it is
20
+ # enabled. Multiple keys will be &&'d and the enabled status of the
21
+ # aggregator will be reset when agent configuration changes.
22
+
23
+ def enabled_keys *keys
24
+ if keys.empty?
25
+ @enabled_keys ||= []
26
+ else
27
+ @enabled_keys = Array(keys)
28
+ @enabled_fn = ->(){ @enabled_keys.all? { |k| Agent.config[k] } }
29
+ end
35
30
  end
36
31
 
32
+ alias_method :enabled_key, :enabled_keys
33
+
34
+ # This can be used instead of `enabled_key(s)` for more fine grained
35
+ # control over whether an aggregator should be enabled. The enabled fn
36
+ # will be reevaluated after configuration changes
37
+
37
38
  def enabled_fn fn = nil
38
39
  fn ? @enabled_fn = fn : @enabled_fn
39
40
  end
@@ -47,13 +48,13 @@ module NewRelic
47
48
  end
48
49
  end
49
50
 
50
- def initialize
51
+ def initialize events
51
52
  @lock = Mutex.new
52
53
  @buffer = self.class.buffer_class.new NewRelic::Agent.config[self.class.capacity_key]
53
- @enabled = false
54
+ @enabled = self.class.enabled_fn ? self.class.enabled_fn.call : false
54
55
  @notified_full = false
55
56
  register_capacity_callback
56
- register_enabled_callback
57
+ register_enabled_callback events
57
58
  after_initialize
58
59
  end
59
60
 
@@ -66,7 +67,6 @@ module NewRelic
66
67
  end
67
68
 
68
69
  def enabled?
69
- return self.class.enabled_fn.call if self.class.enabled_fn
70
70
  @enabled
71
71
  end
72
72
 
@@ -126,18 +126,12 @@ module NewRelic
126
126
  end
127
127
  end
128
128
 
129
- def register_enabled_callback
130
- unless self.class.enabled_key || self.class.enabled_fn
131
- ::NewRelic::Agent.logger.warn "#{self.class.named} needs an enabled_key or an enabled_fn."
132
- end
133
-
134
- return if self.class.enabled_fn
135
-
136
- NewRelic::Agent.config.register_callback(self.class.enabled_key) do |enabled|
137
- # intentionally unsynchronized for liveness
138
- @enabled = enabled
139
- ::NewRelic::Agent.logger.debug "#{self.class.named} will #{enabled ? '' : 'not '}be sent to the New Relic service."
140
- end
129
+ def register_enabled_callback events
130
+ events.subscribe(:server_source_configuration_added) {
131
+ @enabled = self.class.enabled_fn.call
132
+ reset! if @enabled == false
133
+ ::NewRelic::Agent.logger.debug "#{self.class.named} will #{@enabled ? '' : 'not '}be sent to the New Relic service."
134
+ }
141
135
  end
142
136
 
143
137
  def notify_if_full
@@ -3,8 +3,8 @@
3
3
  # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
4
 
5
5
  require 'new_relic/agent/transaction/tracing'
6
- require 'new_relic/agent/cross_app_tracing'
7
- require 'new_relic/agent/cross_app_payload'
6
+ require 'new_relic/agent/distributed_tracing/cross_app_tracing'
7
+ require 'new_relic/agent/distributed_tracing/cross_app_payload'
8
8
 
9
9
  module NewRelic
10
10
  module Agent
@@ -78,7 +78,7 @@ module NewRelic
78
78
  #
79
79
  if txn_info = rmd[NON_HTTP_CAT_TXN_HEADER]
80
80
  payload = CrossAppPayload.new(id, transaction, txn_info)
81
- transaction.cross_app_payload = payload
81
+ transaction.distributed_tracer.cross_app_payload = payload
82
82
 
83
83
  CrossAppTracing.assign_intrinsic_transaction_attributes state
84
84
  end
@@ -112,16 +112,16 @@ module NewRelic
112
112
  NewRelic::Agent.record_api_supportability_metric(:get_response_metadata)
113
113
  return unless CrossAppTracing.cross_app_enabled?
114
114
 
115
- return unless (transaction = Tracer.current_transaction)
116
- return unless (cross_app_payload = transaction.cross_app_payload)
115
+ return unless (txn = Tracer.current_transaction)
116
+ return unless (payload = txn.distributed_tracer.cross_app_payload)
117
117
 
118
118
  # must freeze the name since we're responding with it
119
119
  #
120
- transaction.freeze_name_and_execute_if_not_ignored do
120
+ txn.freeze_name_and_execute_if_not_ignored do
121
121
  # build response payload
122
122
  #
123
123
  rmd = {
124
- NewRelicAppData: cross_app_payload.as_json_array(NON_HTTP_CAT_CONTENT_LENGTH)
124
+ NewRelicAppData: payload.as_json_array(NON_HTTP_CAT_CONTENT_LENGTH)
125
125
  }
126
126
 
127
127
  # obfuscate the generated response metadata JSON
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ # This file is distributed under New Relic's license terms.
3
+ # See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
4
+
5
+ module NewRelic
6
+ module Agent
7
+ module GuidGenerator
8
+
9
+ HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
10
+
11
+ module_function
12
+
13
+ # This method intentionally does not use SecureRandom, because it relies
14
+ # on urandom, which raises an exception in MRI when the interpreter runs
15
+ # out of allocated file descriptors.
16
+ # The guids generated by this method may not be _secure_, but they are
17
+ # random enough for our purposes.
18
+ def generate_guid length = 16
19
+ guid = ''
20
+ length.times do |a|
21
+ guid << HEX_DIGITS[rand(16)]
22
+ end
23
+ guid
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -47,10 +47,9 @@ module NewRelic
47
47
  end
48
48
 
49
49
  DOT_ACTION_CABLE = '.action_cable'.freeze
50
- EMPTY_STRING = ''.freeze
51
50
 
52
51
  def action_name(name)
53
- name.gsub DOT_ACTION_CABLE, EMPTY_STRING
52
+ name.gsub DOT_ACTION_CABLE, NewRelic::EMPTY_STR
54
53
  end
55
54
 
56
55
  def notice_error(payload)
@@ -13,18 +13,13 @@ module NewRelic
13
13
  module Agent
14
14
  module Instrumentation
15
15
  module ActiveRecordNotifications
16
- module BaseExtensions41
17
- def self.included(base)
18
- base.class_eval do
19
- alias_method :log_without_performance_improvement, :log
20
- alias_method :log, :log_with_performance_improvement
21
- end
22
- end
16
+ SQL_ACTIVE_RECORD = 'sql.active_record'.freeze
23
17
 
18
+ module BaseExtensions4x
24
19
  # https://github.com/rails/rails/blob/4-1-stable/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb#L371
25
- def log_with_performance_improvement(sql, name = "SQL", binds = [], statement_name = nil)
20
+ def log(sql, name = "SQL", binds = [], statement_name = nil)
26
21
  @instrumenter.instrument(
27
- "sql.active_record",
22
+ SQL_ACTIVE_RECORD,
28
23
  :sql => sql,
29
24
  :name => name,
30
25
  :connection_id => object_id,
@@ -32,22 +27,20 @@ module NewRelic
32
27
  :statement_name => statement_name,
33
28
  :binds => binds) { yield }
34
29
  rescue => e
35
- raise translate_exception(e, sql)
30
+ # The translate_exception_class method got introduced in 4.1
31
+ if ::ActiveRecord::VERSION::MINOR == 0
32
+ raise translate_exception(e, sql)
33
+ else
34
+ raise translate_exception_class(e, sql)
35
+ end
36
36
  end
37
37
  end
38
38
 
39
39
  module BaseExtensions50
40
- def self.included(base)
41
- base.class_eval do
42
- alias_method :log_without_performance_improvement, :log
43
- alias_method :log, :log_with_performance_improvement
44
- end
45
- end
46
-
47
40
  # https://github.com/rails/rails/blob/5-0-stable/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb#L582
48
- def log_with_performance_improvement(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
41
+ def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
49
42
  @instrumenter.instrument(
50
- "sql.active_record",
43
+ SQL_ACTIVE_RECORD,
51
44
  sql: sql,
52
45
  name: name,
53
46
  binds: binds,
@@ -61,17 +54,10 @@ module NewRelic
61
54
  end
62
55
 
63
56
  module BaseExtensions51
64
- def self.included(base)
65
- base.class_eval do
66
- alias_method :log_without_performance_improvement, :log
67
- alias_method :log, :log_with_performance_improvement
68
- end
69
- end
70
-
71
57
  # https://github.com/rails/rails/blob/5-1-stable/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb#L603
72
- def log_with_performance_improvement(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) # :doc:
58
+ def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) # :doc:
73
59
  @instrumenter.instrument(
74
- "sql.active_record",
60
+ SQL_ACTIVE_RECORD,
75
61
  sql: sql,
76
62
  name: name,
77
63
  binds: binds,
@@ -154,19 +140,19 @@ DependencyDetection.defer do
154
140
 
155
141
  executes do
156
142
  if NewRelic::Agent.config[:backport_fast_active_record_connection_lookup]
157
-
158
- activerecord_extension = if ::ActiveRecord::VERSION::MAJOR.to_i == 4
159
- ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions41
160
- elsif ::ActiveRecord::VERSION::MAJOR.to_i == 5
161
- if ::ActiveRecord::VERSION::MINOR.to_i == 0
162
- ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions50
163
- elsif ::ActiveRecord::VERSION::MINOR.to_i >= 1
164
- ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions51
165
- end
143
+ major_version = ::ActiveRecord::VERSION::MAJOR.to_i
144
+ minor_version = ::ActiveRecord::VERSION::MINOR.to_i
145
+
146
+ activerecord_extension = if major_version == 4
147
+ ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions4x
148
+ elsif major_version == 5 && minor_version == 0
149
+ ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions50
150
+ elsif major_version == 5 && minor_version == 1
151
+ ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions51
166
152
  end
167
153
 
168
154
  unless activerecord_extension.nil?
169
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, activerecord_extension)
155
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:prepend, activerecord_extension)
170
156
  end
171
157
  end
172
158
  end