newrelic_rpm 8.13.0 → 8.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.rubocop.yml +3 -0
  4. data/CHANGELOG.md +3258 -3144
  5. data/CONTRIBUTING.md +1 -2
  6. data/README.md +1 -2
  7. data/init.rb +1 -1
  8. data/lib/new_relic/agent/agent.rb +14 -466
  9. data/lib/new_relic/agent/agent_helpers/connect.rb +227 -0
  10. data/lib/new_relic/agent/agent_helpers/harvest.rb +153 -0
  11. data/lib/new_relic/agent/agent_helpers/shutdown.rb +72 -0
  12. data/lib/new_relic/agent/agent_helpers/special_startup.rb +75 -0
  13. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +167 -0
  14. data/lib/new_relic/agent/agent_helpers/startup.rb +202 -0
  15. data/lib/new_relic/agent/agent_helpers/transmit.rb +76 -0
  16. data/lib/new_relic/agent/configuration/default_source.rb +22 -0
  17. data/lib/new_relic/agent/datastores.rb +2 -2
  18. data/lib/new_relic/agent/guid_generator.rb +11 -2
  19. data/lib/new_relic/agent/instrumentation/active_job.rb +7 -7
  20. data/lib/new_relic/agent/instrumentation/active_merchant.rb +2 -2
  21. data/lib/new_relic/agent/instrumentation/active_record.rb +9 -9
  22. data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +24 -24
  23. data/lib/new_relic/agent/instrumentation/active_storage.rb +2 -2
  24. data/lib/new_relic/agent/instrumentation/active_support.rb +12 -0
  25. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +3 -3
  26. data/lib/new_relic/agent/instrumentation/acts_as_solr.rb +2 -2
  27. data/lib/new_relic/agent/instrumentation/authlogic.rb +2 -2
  28. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +3 -3
  29. data/lib/new_relic/agent/instrumentation/bunny.rb +4 -4
  30. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/curb.rb +6 -6
  32. data/lib/new_relic/agent/instrumentation/custom_events_subscriber.rb +37 -0
  33. data/lib/new_relic/agent/instrumentation/data_mapper.rb +50 -50
  34. data/lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb +5 -5
  35. data/lib/new_relic/agent/instrumentation/elasticsearch.rb +5 -5
  36. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +1 -1
  37. data/lib/new_relic/agent/instrumentation/excon.rb +9 -9
  38. data/lib/new_relic/agent/instrumentation/grape.rb +8 -8
  39. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +1 -1
  40. data/lib/new_relic/agent/instrumentation/grpc_client.rb +3 -3
  41. data/lib/new_relic/agent/instrumentation/grpc_server.rb +4 -4
  42. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +1 -1
  43. data/lib/new_relic/agent/instrumentation/httpclient.rb +2 -2
  44. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +1 -1
  45. data/lib/new_relic/agent/instrumentation/httprb.rb +3 -3
  46. data/lib/new_relic/agent/instrumentation/logger.rb +3 -3
  47. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +3 -3
  48. data/lib/new_relic/agent/instrumentation/memcache.rb +16 -16
  49. data/lib/new_relic/agent/instrumentation/mongo.rb +1 -1
  50. data/lib/new_relic/agent/instrumentation/net_http.rb +6 -6
  51. data/lib/new_relic/agent/instrumentation/padrino.rb +3 -3
  52. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +5 -5
  53. data/lib/new_relic/agent/instrumentation/rack.rb +14 -14
  54. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -5
  55. data/lib/new_relic/agent/instrumentation/rails_middleware.rb +3 -3
  56. data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +6 -6
  57. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +2 -2
  58. data/lib/new_relic/agent/instrumentation/rails_notifications/action_view.rb +5 -3
  59. data/lib/new_relic/agent/instrumentation/rails_notifications/custom_events.rb +30 -0
  60. data/lib/new_relic/agent/instrumentation/rainbows_instrumentation.rb +4 -4
  61. data/lib/new_relic/agent/instrumentation/rake.rb +7 -7
  62. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +29 -10
  63. data/lib/new_relic/agent/instrumentation/redis.rb +4 -4
  64. data/lib/new_relic/agent/instrumentation/resque.rb +9 -9
  65. data/lib/new_relic/agent/instrumentation/sequel.rb +2 -2
  66. data/lib/new_relic/agent/instrumentation/sidekiq.rb +3 -3
  67. data/lib/new_relic/agent/instrumentation/sinatra.rb +7 -7
  68. data/lib/new_relic/agent/instrumentation/sunspot.rb +4 -4
  69. data/lib/new_relic/agent/instrumentation/thread.rb +3 -3
  70. data/lib/new_relic/agent/instrumentation/tilt.rb +3 -3
  71. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +2 -2
  72. data/lib/new_relic/agent/instrumentation/typhoeus.rb +1 -1
  73. data/lib/new_relic/agent/method_tracer_helpers.rb +6 -11
  74. data/lib/new_relic/agent/tracer.rb +1 -1
  75. data/lib/new_relic/agent/transaction/segment.rb +6 -0
  76. data/lib/new_relic/control/instance_methods.rb +6 -2
  77. data/lib/new_relic/recipes/helpers/send_deployment.rb +2 -1
  78. data/lib/new_relic/version.rb +1 -1
  79. data/lib/newrelic_rpm.rb +13 -2
  80. data/lib/sequel/extensions/newrelic_instrumentation.rb +1 -1
  81. data/lib/sequel/plugins/newrelic_instrumentation.rb +1 -1
  82. data/newrelic.yml +10 -0
  83. data/test/agent_helper.rb +5 -5
  84. metadata +12 -6
  85. data/lib/new_relic/agent/agent/shutdown.rb +0 -35
  86. data/lib/new_relic/agent/agent/special_startup.rb +0 -72
  87. data/lib/new_relic/agent/agent/start_worker_thread.rb +0 -163
  88. data/lib/new_relic/agent/agent/startup.rb +0 -197
@@ -0,0 +1,202 @@
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
6
+ module Agent
7
+ module AgentHelpers
8
+ module Startup
9
+ # True if we have initialized and completed 'start'
10
+ def started?
11
+ @started
12
+ end
13
+
14
+ # Check whether we have already started, which is an error condition
15
+ def already_started?
16
+ if started?
17
+ ::NewRelic::Agent.logger.error("Agent Started Already!")
18
+ true
19
+ end
20
+ end
21
+
22
+ # Logs a bunch of data and starts the agent, if needed
23
+ def start
24
+ return unless agent_should_start?
25
+
26
+ log_startup
27
+ check_config_and_start_agent
28
+ log_version_and_pid
29
+
30
+ events.subscribe(:initial_configuration_complete) do
31
+ log_ignore_url_regexes
32
+ end
33
+ end
34
+
35
+ # Sanity-check the agent configuration and start the agent,
36
+ # setting up the worker thread and the exit handler to shut
37
+ # down the agent
38
+ def check_config_and_start_agent
39
+ return unless monitoring? && has_correct_license_key?
40
+ return if using_forking_dispatcher?
41
+
42
+ setup_and_start_agent
43
+ end
44
+
45
+ # This is the shared method between the main agent startup and the
46
+ # after_fork call restarting the thread in deferred dispatchers.
47
+ #
48
+ # Treatment of @started and env report is important to get right.
49
+ def setup_and_start_agent(options = {})
50
+ @started = true
51
+ @harvester.mark_started
52
+
53
+ unless in_resque_child_process?
54
+ install_exit_handler
55
+ environment_for_connect
56
+ @harvest_samplers.load_samplers unless Agent.config[:disable_samplers]
57
+ end
58
+
59
+ connect_in_foreground if Agent.config[:sync_startup]
60
+ start_worker_thread(options)
61
+ end
62
+
63
+ # Log startup information that we almost always want to know
64
+ def log_startup
65
+ log_environment
66
+ log_dispatcher
67
+ log_app_name
68
+ end
69
+
70
+ # Log the environment the app thinks it's running in.
71
+ # Useful in debugging, as this is the key for config YAML lookups.
72
+ def log_environment
73
+ ::NewRelic::Agent.logger.info("Environment: #{NewRelic::Control.instance.env}")
74
+ end
75
+
76
+ # Logs the dispatcher to the log file to assist with
77
+ # debugging. When no debugger is present, logs this fact to
78
+ # assist with proper dispatcher detection
79
+ def log_dispatcher
80
+ dispatcher_name = Agent.config[:dispatcher].to_s
81
+
82
+ if dispatcher_name.empty?
83
+ ::NewRelic::Agent.logger.info('No known dispatcher detected.')
84
+ else
85
+ ::NewRelic::Agent.logger.info("Dispatcher: #{dispatcher_name}")
86
+ end
87
+ end
88
+
89
+ def log_app_name
90
+ ::NewRelic::Agent.logger.info("Application: #{Agent.config[:app_name].join(", ")}")
91
+ end
92
+
93
+ def log_ignore_url_regexes
94
+ regexes = NewRelic::Agent.config[:'rules.ignore_url_regexes']
95
+
96
+ unless regexes.empty?
97
+ ::NewRelic::Agent.logger.info("Ignoring URLs that match the following regexes: " \
98
+ "#{regexes.map(&:inspect).join(", ")}.")
99
+ end
100
+ end
101
+
102
+ # Classy logging of the agent version and the current pid,
103
+ # so we can disambiguate processes in the log file and make
104
+ # sure they're running a reasonable version
105
+ def log_version_and_pid
106
+ ::NewRelic::Agent.logger.debug("New Relic Ruby Agent #{NewRelic::VERSION::STRING} Initialized: pid = #{$$}")
107
+ end
108
+
109
+ # Logs the configured application names
110
+ def app_name_configured?
111
+ names = Agent.config[:app_name]
112
+ return names.respond_to?(:any?) && names.any?
113
+ end
114
+
115
+ # Connecting in the foreground blocks further startup of the
116
+ # agent until we have a connection - useful in cases where
117
+ # you're trying to log a very-short-running process and want
118
+ # to get statistics from before a server connection
119
+ # (typically 20 seconds) exists
120
+ def connect_in_foreground
121
+ NewRelic::Agent.disable_all_tracing { connect(:keep_retrying => false) }
122
+ end
123
+
124
+ # Warn the user if they have configured their agent not to
125
+ # send data, that way we can see this clearly in the log file
126
+ def monitoring?
127
+ if Agent.config[:monitor_mode]
128
+ true
129
+ else
130
+ ::NewRelic::Agent.logger.warn('Agent configured not to send data in this environment.')
131
+ false
132
+ end
133
+ end
134
+
135
+ # Tell the user when the license key is missing so they can
136
+ # fix it by adding it to the file
137
+ def has_license_key?
138
+ if Agent.config[:license_key] && Agent.config[:license_key].length > 0
139
+ true
140
+ else
141
+ ::NewRelic::Agent.logger.warn("No license key found. " +
142
+ "This often means your newrelic.yml file was not found, or it lacks a section for the running " \
143
+ "environment, '#{NewRelic::Control.instance.env}'. You may also want to try linting your newrelic.yml " \
144
+ "to ensure it is valid YML.")
145
+ false
146
+ end
147
+ end
148
+
149
+ # A correct license key exists and is of the proper length
150
+ def has_correct_license_key?
151
+ has_license_key? && correct_license_length
152
+ end
153
+
154
+ # A license key is an arbitrary 40 character string,
155
+ # usually looks something like a SHA1 hash
156
+ def correct_license_length
157
+ key = Agent.config[:license_key]
158
+
159
+ if key.length == 40
160
+ true
161
+ else
162
+ ::NewRelic::Agent.logger.error("Invalid license key: #{key}")
163
+ false
164
+ end
165
+ end
166
+
167
+ # Check to see if the agent should start, returning +true+ if it should.
168
+ def agent_should_start?
169
+ return false if already_started? || disabled?
170
+
171
+ if defer_for_delayed_job?
172
+ ::NewRelic::Agent.logger.debug("Deferring startup for DelayedJob")
173
+ return false
174
+ end
175
+
176
+ if defer_for_resque?
177
+ ::NewRelic::Agent.logger.debug("Deferring startup for Resque in case it daemonizes")
178
+ return false
179
+ end
180
+
181
+ unless app_name_configured?
182
+ NewRelic::Agent.logger.error("No application name configured.",
183
+ "The Agent cannot start without at least one. Please check your ",
184
+ "newrelic.yml and ensure that it is valid and has at least one ",
185
+ "value set for app_name in the #{NewRelic::Control.instance.env} ",
186
+ "environment.")
187
+ return false
188
+ end
189
+
190
+ return true
191
+ end
192
+
193
+ # The agent is disabled when it is not force enabled by the
194
+ # 'agent_enabled' option (e.g. in a manual start), or
195
+ # enabled normally through the configuration file
196
+ def disabled?
197
+ !Agent.config[:agent_enabled]
198
+ end
199
+ end
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,76 @@
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
6
+ module Agent
7
+ module AgentHelpers
8
+ module Transmit
9
+ TRANSACTION_EVENT = "TransactionEvent".freeze
10
+ def transmit_analytic_event_data
11
+ transmit_single_data_type(:harvest_and_send_analytic_event_data, TRANSACTION_EVENT)
12
+ end
13
+
14
+ CUSTOM_EVENT = "CustomEvent".freeze
15
+ def transmit_custom_event_data
16
+ transmit_single_data_type(:harvest_and_send_custom_event_data, CUSTOM_EVENT)
17
+ end
18
+
19
+ ERROR_EVENT = "ErrorEvent".freeze
20
+ def transmit_error_event_data
21
+ transmit_single_data_type(:harvest_and_send_error_event_data, ERROR_EVENT)
22
+ end
23
+
24
+ SPAN_EVENT = "SpanEvent".freeze
25
+ def transmit_span_event_data
26
+ transmit_single_data_type(:harvest_and_send_span_event_data, SPAN_EVENT)
27
+ end
28
+
29
+ LOG_EVENT = "LogEvent".freeze
30
+ def transmit_log_event_data
31
+ transmit_single_data_type(:harvest_and_send_log_event_data, LOG_EVENT)
32
+ end
33
+
34
+ def transmit_single_data_type(harvest_method, supportability_name)
35
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
36
+
37
+ msg = "Sending #{supportability_name} data to New Relic Service"
38
+ ::NewRelic::Agent.logger.debug(msg)
39
+
40
+ @service.session do # use http keep-alive
41
+ self.send(harvest_method)
42
+ end
43
+ ensure
44
+ duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - now
45
+ NewRelic::Agent.record_metric("Supportability/#{supportability_name}Harvest", duration)
46
+ end
47
+
48
+ def transmit_data
49
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
50
+ ::NewRelic::Agent.logger.debug("Sending data to New Relic Service")
51
+
52
+ @events.notify(:before_harvest)
53
+ @service.session do # use http keep-alive
54
+ harvest_and_send_data_types
55
+
56
+ check_for_and_handle_agent_commands
57
+ harvest_and_send_for_agent_commands
58
+ end
59
+ ensure
60
+ NewRelic::Agent::Database.close_connections
61
+ duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - now
62
+ NewRelic::Agent.record_metric('Supportability/Harvest', duration)
63
+ end
64
+
65
+ def transmit_data_types
66
+ transmit_data
67
+ transmit_analytic_event_data
68
+ transmit_custom_event_data
69
+ transmit_error_event_data
70
+ transmit_span_event_data
71
+ transmit_log_event_data
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -358,6 +358,19 @@ module NewRelic
358
358
  :description => 'Sets the level of detail of log messages. Possible log levels, in increasing verbosity, are: `error`, `warn`, `info` or `debug`.'
359
359
  },
360
360
  # General
361
+ :active_support_custom_events_names => {
362
+ :default => [],
363
+ :public => true,
364
+ :type => Array,
365
+ :allowed_from_server => false,
366
+ :description => <<-DESCRIPTION
367
+ An array of ActiveSupport custom events names to subscribe to and provide
368
+ instrumentation for. For example,
369
+ - my.custom.event
370
+ - another.event
371
+ - a.third.event
372
+ DESCRIPTION
373
+ },
361
374
  :apdex_t => {
362
375
  :default => 0.5,
363
376
  :public => true,
@@ -1837,6 +1850,15 @@ If `true`, disables agent middleware for Sinatra. This middleware is responsible
1837
1850
  :allowed_from_server => false,
1838
1851
  :description => 'Specify a custom host name for [display in the New Relic UI](/docs/apm/new-relic-apm/maintenance/add-rename-remove-hosts#display_name).'
1839
1852
  },
1853
+ # Rails
1854
+ :'defer_rails_initialization' => {
1855
+ :default => false,
1856
+ :public => true,
1857
+ :type => Boolean,
1858
+ :allowed_from_server => false,
1859
+ :description => 'If `true`, when the agent is in an application using Ruby on Rails, it will start after ' \
1860
+ 'config/initializers are run.'
1861
+ },
1840
1862
  # Rake
1841
1863
  :'rake.tasks' => {
1842
1864
  :default => [],
@@ -53,7 +53,7 @@ module NewRelic
53
53
  begin
54
54
  send(method_name_without_newrelic, *args, &blk)
55
55
  ensure
56
- segment.finish if segment
56
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
57
57
  end
58
58
  end
59
59
 
@@ -126,7 +126,7 @@ module NewRelic
126
126
  callback.call(result, segment.name, elapsed_time)
127
127
  end
128
128
  ensure
129
- segment.finish if segment
129
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
130
130
  end
131
131
  end
132
132
  end
@@ -7,14 +7,23 @@ module NewRelic
7
7
  module GuidGenerator
8
8
  module_function
9
9
 
10
+ MAX_RAND_16 = 16**16
11
+ MAX_RAND_32 = 16**32
10
12
  # This method intentionally does not use SecureRandom, because it relies
11
13
  # on urandom, which raises an exception in MRI when the interpreter runs
12
14
  # out of allocated file descriptors.
13
15
  # The guids generated by this method may not be _secure_, but they are
14
16
  # random enough for our purposes.
15
17
  def generate_guid(length = 16)
16
- guid = rand(16**length).to_s(16)
17
- guid.length < length ? guid.rjust(length, "0") : guid
18
+ guid = case length
19
+ when 16
20
+ rand(MAX_RAND_16)
21
+ when 32
22
+ rand(MAX_RAND_32)
23
+ else
24
+ rand(16**length)
25
+ end.to_s(16)
26
+ guid.length < length ? guid.rjust(length, '0') : guid
18
27
  end
19
28
  end
20
29
  end
@@ -8,22 +8,22 @@ DependencyDetection.defer do
8
8
  named :activejob
9
9
 
10
10
  depends_on do
11
- defined?(::ActiveJob::Base)
11
+ defined?(ActiveJob::Base)
12
12
  end
13
13
 
14
14
  executes do
15
- ::NewRelic::Agent.logger.info('Installing ActiveJob instrumentation')
15
+ NewRelic::Agent.logger.info('Installing ActiveJob instrumentation')
16
16
 
17
17
  ActiveSupport.on_load(:active_job) do
18
- ::ActiveJob::Base.around_enqueue do |job, block|
19
- ::NewRelic::Agent::Instrumentation::ActiveJobHelper.enqueue(job, block)
18
+ ActiveJob::Base.around_enqueue do |job, block|
19
+ NewRelic::Agent::Instrumentation::ActiveJobHelper.enqueue(job, block)
20
20
  end
21
21
 
22
- ::ActiveJob::Base.around_perform do |job, block|
23
- ::NewRelic::Agent::Instrumentation::ActiveJobHelper.perform(job, block)
22
+ ActiveJob::Base.around_perform do |job, block|
23
+ NewRelic::Agent::Instrumentation::ActiveJobHelper.perform(job, block)
24
24
  end
25
25
 
26
- ::NewRelic::Agent::PrependSupportability.record_metrics_for(::ActiveJob::Base)
26
+ NewRelic::Agent::PrependSupportability.record_metrics_for(ActiveJob::Base)
27
27
  end
28
28
  end
29
29
  end
@@ -12,7 +12,7 @@ DependencyDetection.defer do
12
12
  end
13
13
 
14
14
  executes do
15
- ::NewRelic::Agent.logger.info('Installing ActiveMerchant instrumentation')
15
+ NewRelic::Agent.logger.info('Installing ActiveMerchant instrumentation')
16
16
  end
17
17
 
18
18
  executes do
@@ -42,7 +42,7 @@ DependencyDetection.defer do
42
42
  deprecation_msg = 'The Ruby Agent is dropping support for ActiveMerchant versions below 1.65.0 ' \
43
43
  'in version 9.0.0. Please upgrade your ActiveMerchant version to continue receiving full support. ' \
44
44
 
45
- ::NewRelic::Agent.logger.log_once(
45
+ NewRelic::Agent.logger.log_once(
46
46
  :warn,
47
47
  :deprecated_active_merchant_version,
48
48
  deprecation_msg
@@ -84,7 +84,7 @@ module NewRelic
84
84
  log_without_newrelic_instrumentation(*args, &block)
85
85
  end
86
86
  ensure
87
- segment.finish if segment
87
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
88
88
  end
89
89
  end
90
90
  else
@@ -128,7 +128,7 @@ module NewRelic
128
128
  log_without_newrelic_instrumentation(*args, **kwargs, &block)
129
129
  end
130
130
  ensure
131
- segment.finish if segment
131
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
132
132
  end
133
133
  end
134
134
  end
@@ -141,9 +141,9 @@ DependencyDetection.defer do
141
141
  @name = :active_record
142
142
 
143
143
  depends_on do
144
- defined?(::ActiveRecord) && defined?(::ActiveRecord::Base) &&
145
- (!defined?(::ActiveRecord::VERSION) ||
146
- ::ActiveRecord::VERSION::MAJOR.to_i <= 3)
144
+ defined?(ActiveRecord) && defined?(ActiveRecord::Base) &&
145
+ (!defined?(ActiveRecord::VERSION) ||
146
+ ActiveRecord::VERSION::MAJOR.to_i <= 3)
147
147
  end
148
148
 
149
149
  depends_on do
@@ -151,18 +151,18 @@ DependencyDetection.defer do
151
151
  end
152
152
 
153
153
  executes do
154
- ::NewRelic::Agent.logger.info('Installing ActiveRecord instrumentation')
154
+ NewRelic::Agent.logger.info('Installing ActiveRecord instrumentation')
155
155
  end
156
156
 
157
157
  executes do
158
158
  require 'new_relic/agent/instrumentation/active_record_helper'
159
159
 
160
- if defined?(::Rails::VERSION::MAJOR) && ::Rails::VERSION::MAJOR.to_i == 3
160
+ if defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR.to_i == 3
161
161
  ActiveSupport.on_load(:active_record) do
162
- ::NewRelic::Agent::Instrumentation::ActiveRecord.insert_instrumentation
162
+ NewRelic::Agent::Instrumentation::ActiveRecord.insert_instrumentation
163
163
  end
164
164
  else
165
- ::NewRelic::Agent::Instrumentation::ActiveRecord.insert_instrumentation
165
+ NewRelic::Agent::Instrumentation::ActiveRecord.insert_instrumentation
166
166
  end
167
167
  end
168
168
  end
@@ -84,9 +84,9 @@ DependencyDetection.defer do
84
84
  named :active_record_notifications
85
85
 
86
86
  depends_on do
87
- defined?(::ActiveRecord) && defined?(::ActiveRecord::Base) &&
88
- defined?(::ActiveRecord::VERSION) &&
89
- ::ActiveRecord::VERSION::MAJOR.to_i >= 4
87
+ defined?(ActiveRecord) && defined?(ActiveRecord::Base) &&
88
+ defined?(ActiveRecord::VERSION) &&
89
+ ActiveRecord::VERSION::MAJOR.to_i >= 4
90
90
  end
91
91
 
92
92
  depends_on do
@@ -95,7 +95,7 @@ DependencyDetection.defer do
95
95
  end
96
96
 
97
97
  executes do
98
- ::NewRelic::Agent.logger.info('Installing notifications based Active Record instrumentation')
98
+ NewRelic::Agent.logger.info('Installing notifications based Active Record instrumentation')
99
99
  end
100
100
 
101
101
  executes do
@@ -105,51 +105,51 @@ DependencyDetection.defer do
105
105
 
106
106
  executes do
107
107
  ActiveSupport.on_load(:active_record) do
108
- ::NewRelic::Agent::PrependSupportability.record_metrics_for(
109
- ::ActiveRecord::Base,
110
- ::ActiveRecord::Relation
108
+ NewRelic::Agent::PrependSupportability.record_metrics_for(
109
+ ActiveRecord::Base,
110
+ ActiveRecord::Relation
111
111
  )
112
112
 
113
113
  # Default to .prepending, unless the ActiveRecord version is <=4
114
114
  # **AND** the :prepend_active_record_instrumentation config is false
115
- if ::ActiveRecord::VERSION::MAJOR > 4 \
116
- || ::NewRelic::Agent.config[:prepend_active_record_instrumentation]
115
+ if ActiveRecord::VERSION::MAJOR > 4 \
116
+ || NewRelic::Agent.config[:prepend_active_record_instrumentation]
117
117
 
118
- ::ActiveRecord::Base.send(:prepend,
119
- ::NewRelic::Agent::Instrumentation::ActiveRecordPrepend::BaseExtensions)
120
- ::ActiveRecord::Relation.send(:prepend,
121
- ::NewRelic::Agent::Instrumentation::ActiveRecordPrepend::RelationExtensions)
118
+ ActiveRecord::Base.send(:prepend,
119
+ NewRelic::Agent::Instrumentation::ActiveRecordPrepend::BaseExtensions)
120
+ ActiveRecord::Relation.send(:prepend,
121
+ NewRelic::Agent::Instrumentation::ActiveRecordPrepend::RelationExtensions)
122
122
  else
123
- ::NewRelic::Agent::Instrumentation::ActiveRecordHelper.instrument_additional_methods
123
+ NewRelic::Agent::Instrumentation::ActiveRecordHelper.instrument_additional_methods
124
124
  end
125
125
  end
126
126
  end
127
127
 
128
128
  executes do
129
129
  if NewRelic::Agent.config[:backport_fast_active_record_connection_lookup]
130
- major_version = ::ActiveRecord::VERSION::MAJOR.to_i
131
- minor_version = ::ActiveRecord::VERSION::MINOR.to_i
130
+ major_version = ActiveRecord::VERSION::MAJOR.to_i
131
+ minor_version = ActiveRecord::VERSION::MINOR.to_i
132
132
 
133
133
  activerecord_extension = if major_version == 4
134
- ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions4x
134
+ NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions4x
135
135
  elsif major_version == 5 && minor_version == 0
136
- ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions50
136
+ NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions50
137
137
  elsif major_version == 5 && minor_version == 1
138
- ::NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions51
138
+ NewRelic::Agent::Instrumentation::ActiveRecordNotifications::BaseExtensions51
139
139
  end
140
140
 
141
141
  unless activerecord_extension.nil?
142
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:prepend, activerecord_extension)
142
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:prepend, activerecord_extension)
143
143
  end
144
144
  end
145
145
  end
146
146
 
147
147
  executes do
148
- if ::ActiveRecord::VERSION::MAJOR == 5 \
149
- && ::ActiveRecord::VERSION::MINOR.to_i == 1 \
150
- && ::ActiveRecord::VERSION::TINY.to_i >= 6
148
+ if ActiveRecord::VERSION::MAJOR == 5 \
149
+ && ActiveRecord::VERSION::MINOR.to_i == 1 \
150
+ && ActiveRecord::VERSION::TINY.to_i >= 6
151
151
 
152
- ::ActiveRecord::Base.prepend(::NewRelic::Agent::Instrumentation::ActiveRecordPrepend::BaseExtensions516)
152
+ ActiveRecord::Base.prepend(NewRelic::Agent::Instrumentation::ActiveRecordPrepend::BaseExtensions516)
153
153
  end
154
154
  end
155
155
  end
@@ -8,12 +8,12 @@ DependencyDetection.defer do
8
8
  named :active_storage
9
9
 
10
10
  depends_on do
11
- defined?(::ActiveStorage) &&
11
+ defined?(ActiveStorage) &&
12
12
  !NewRelic::Agent::Instrumentation::ActiveStorageSubscriber.subscribed?
13
13
  end
14
14
 
15
15
  executes do
16
- ::NewRelic::Agent.logger.info('Installing ActiveStorage instrumentation')
16
+ NewRelic::Agent.logger.info('Installing ActiveStorage instrumentation')
17
17
  end
18
18
 
19
19
  executes do
@@ -0,0 +1,12 @@
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
+ # This is a helper file that will allow apps using ActiveSupport without Rails
6
+ # to still leverage all ActiveSupport based instrumentation functionality
7
+ # offered by the agent that would otherwise be gated by the detection of Rails.
8
+
9
+ # ActiveSupport notifications custom events
10
+ if !defined?(Rails) && defined?(ActiveSupport::Notifications) && defined?(ActiveSupport::IsolatedExecutionState)
11
+ require_relative 'rails_notifications/custom_events'
12
+ end
@@ -9,14 +9,14 @@ require_relative 'active_support_logger/prepend'
9
9
  DependencyDetection.defer do
10
10
  named :active_support_logger
11
11
 
12
- depends_on { defined?(::ActiveSupport::Logger) }
12
+ depends_on { defined?(ActiveSupport::Logger) }
13
13
 
14
14
  executes do
15
- ::NewRelic::Agent.logger.info('Installing ActiveSupport::Logger instrumentation')
15
+ NewRelic::Agent.logger.info('Installing ActiveSupport::Logger instrumentation')
16
16
 
17
17
  if use_prepend?
18
18
  # the only method currently instrumented is a class method
19
- prepend_instrument ::ActiveSupport::Logger.singleton_class, NewRelic::Agent::Instrumentation::ActiveSupportLogger::Prepend
19
+ prepend_instrument ActiveSupport::Logger.singleton_class, NewRelic::Agent::Instrumentation::ActiveSupportLogger::Prepend
20
20
  else
21
21
  chain_instrument NewRelic::Agent::Instrumentation::ActiveSupportLogger::Chain
22
22
  end
@@ -44,11 +44,11 @@ DependencyDetection.defer do
44
44
  end
45
45
 
46
46
  executes do
47
- ::NewRelic::Agent.logger.info('Installing ActsAsSolr instrumentation')
47
+ NewRelic::Agent.logger.info('Installing ActsAsSolr instrumentation')
48
48
  deprecation_msg = 'The instrumentation for ActsAsSolr is deprecated. ' \
49
49
  'It will be removed in version 9.0.0.' \
50
50
 
51
- ::NewRelic::Agent.logger.log_once(
51
+ NewRelic::Agent.logger.log_once(
52
52
  :warn,
53
53
  :deprecated_acts_as_solr,
54
54
  deprecation_msg
@@ -12,11 +12,11 @@ DependencyDetection.defer do
12
12
  end
13
13
 
14
14
  executes do
15
- ::NewRelic::Agent.logger.info('Installing Authlogic instrumentation')
15
+ NewRelic::Agent.logger.info('Installing Authlogic instrumentation')
16
16
  deprecation_msg = 'The instrumentation for Authlogic is deprecated. ' \
17
17
  'It will be removed in version 9.0.0.' \
18
18
 
19
- ::NewRelic::Agent.logger.log_once(
19
+ NewRelic::Agent.logger.log_once(
20
20
  :warn,
21
21
  :deprecated_authlogic,
22
22
  deprecation_msg
@@ -53,7 +53,7 @@ module NewRelic
53
53
  yield
54
54
  end
55
55
  ensure
56
- segment.finish if segment
56
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
57
57
  end
58
58
  end
59
59
  end
@@ -97,7 +97,7 @@ module NewRelic
97
97
  raise bunny_error
98
98
  end
99
99
  ensure
100
- segment.finish if segment
100
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
101
101
  end
102
102
 
103
103
  msg
@@ -120,7 +120,7 @@ module NewRelic
120
120
  yield
121
121
  end
122
122
  ensure
123
- segment.finish if segment
123
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
124
124
  end
125
125
  end
126
126
  end