newrelic_rpm 7.0.0 → 8.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +226 -0
- data/CONTRIBUTING.md +13 -2
- data/README.md +5 -1
- data/lib/new_relic/agent/adaptive_sampler.rb +2 -2
- data/lib/new_relic/agent/agent.rb +8 -7
- data/lib/new_relic/agent/commands/thread_profiler_session.rb +7 -3
- data/lib/new_relic/agent/configuration/default_source.rb +229 -158
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +28 -12
- data/lib/new_relic/agent/configuration/manager.rb +1 -2
- data/lib/new_relic/agent/configuration/server_source.rb +3 -2
- data/lib/new_relic/agent/configuration/yaml_source.rb +22 -1
- data/lib/new_relic/agent/connect/request_builder.rb +4 -2
- data/lib/new_relic/agent/custom_event_aggregator.rb +2 -1
- data/lib/new_relic/agent/database.rb +5 -2
- data/lib/new_relic/agent/datastores/mongo.rb +5 -10
- data/lib/new_relic/agent/datastores.rb +7 -7
- data/lib/new_relic/agent/distributed_tracing/cross_app_payload.rb +5 -5
- data/lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb +10 -6
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb +0 -1
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +1 -1
- data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +6 -6
- data/lib/new_relic/agent/error_collector.rb +52 -37
- data/lib/new_relic/agent/error_filter.rb +175 -0
- data/lib/new_relic/agent/event_loop.rb +6 -6
- data/lib/new_relic/agent/external.rb +0 -32
- data/lib/new_relic/agent/http_clients/abstract.rb +2 -2
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +7 -1
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +3 -3
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +1 -3
- data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +2 -1
- data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +4 -4
- data/lib/new_relic/agent/instrumentation/excon.rb +4 -23
- data/lib/new_relic/agent/instrumentation/logger/chain.rb +21 -0
- data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +59 -0
- data/lib/new_relic/agent/instrumentation/logger/prepend.rb +13 -0
- data/lib/new_relic/agent/instrumentation/logger.rb +25 -0
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +5 -1
- data/lib/new_relic/agent/instrumentation/memcache/helper.rb +5 -0
- data/lib/new_relic/agent/instrumentation/memcache/prepend.rb +8 -2
- data/lib/new_relic/agent/instrumentation/mongo.rb +3 -141
- data/lib/new_relic/agent/instrumentation/net_http.rb +6 -1
- data/lib/new_relic/agent/instrumentation/padrino/chain.rb +23 -19
- data/lib/new_relic/agent/instrumentation/padrino/prepend.rb +1 -1
- data/lib/new_relic/agent/instrumentation/padrino.rb +4 -2
- data/lib/new_relic/agent/instrumentation/queue_time.rb +4 -4
- data/lib/new_relic/agent/instrumentation/rack/chain.rb +3 -2
- data/lib/new_relic/agent/instrumentation/rack/prepend.rb +2 -1
- data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +5 -41
- data/lib/new_relic/agent/instrumentation/redis.rb +4 -0
- data/lib/new_relic/agent/instrumentation/resque/helper.rb +19 -0
- data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +5 -3
- data/lib/new_relic/agent/instrumentation/resque.rb +13 -4
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +6 -1
- data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +8 -2
- data/lib/new_relic/agent/instrumentation/tilt/chain.rb +24 -0
- data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +41 -0
- data/lib/new_relic/agent/instrumentation/tilt/prepend.rb +13 -0
- data/lib/new_relic/agent/instrumentation/tilt.rb +25 -0
- data/lib/new_relic/agent/javascript_instrumentor.rb +15 -10
- data/lib/new_relic/agent/logging.rb +5 -6
- data/lib/new_relic/agent/messaging.rb +10 -24
- data/lib/new_relic/agent/method_tracer.rb +137 -138
- data/lib/new_relic/agent/monitors/cross_app_monitor.rb +8 -1
- data/lib/new_relic/agent/new_relic_service.rb +16 -12
- data/lib/new_relic/agent/pipe_channel_manager.rb +10 -6
- data/lib/new_relic/agent/pipe_service.rb +1 -1
- data/lib/new_relic/agent/samplers/cpu_sampler.rb +1 -1
- data/lib/new_relic/agent/samplers/delayed_job_sampler.rb +9 -6
- data/lib/new_relic/agent/span_event_aggregator.rb +2 -2
- data/lib/new_relic/agent/sql_sampler.rb +3 -3
- data/lib/new_relic/agent/stats_engine/stats_hash.rb +1 -1
- data/lib/new_relic/agent/stats_engine.rb +1 -1
- data/lib/new_relic/agent/threading/backtrace_service.rb +4 -5
- data/lib/new_relic/agent/threading/thread_profile.rb +1 -1
- data/lib/new_relic/agent/tracer.rb +15 -37
- data/lib/new_relic/agent/transaction/abstract_segment.rb +3 -3
- data/lib/new_relic/agent/transaction/datastore_segment.rb +3 -0
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +1 -0
- data/lib/new_relic/agent/transaction/external_request_segment.rb +3 -0
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +5 -11
- data/lib/new_relic/agent/transaction/segment.rb +3 -0
- data/lib/new_relic/agent/transaction.rb +7 -28
- data/lib/new_relic/agent/transaction_time_aggregator.rb +5 -5
- data/lib/new_relic/agent/vm/snapshot.rb +1 -1
- data/lib/new_relic/agent/worker_loop.rb +5 -5
- data/lib/new_relic/agent.rb +10 -7
- data/lib/new_relic/cli/commands/deployments.rb +2 -2
- data/lib/new_relic/constants.rb +0 -4
- data/lib/new_relic/noticed_error.rb +4 -4
- data/lib/new_relic/version.rb +2 -2
- data/lib/newrelic_rpm.rb +10 -34
- data/lib/tasks/all.rb +1 -1
- data/lib/tasks/config.html.erb +14 -25
- data/lib/tasks/config.rake +8 -7
- data/newrelic.yml +580 -3
- data/newrelic_rpm.gemspec +1 -1
- data/test/agent_helper.rb +27 -2
- metadata +13 -11
- data/lib/new_relic/agent/datastores/mongo/statement_formatter.rb +0 -53
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +0 -49
- data/lib/new_relic/agent/instrumentation/merb/controller.rb +0 -44
- data/lib/new_relic/agent/instrumentation/merb/errors.rb +0 -33
- data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +0 -125
- data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +0 -46
- data/lib/new_relic/agent/supported_versions.rb +0 -275
- data/lib/new_relic/control/frameworks/merb.rb +0 -29
@@ -14,7 +14,7 @@ module NewRelic
|
|
14
14
|
@interval = interval
|
15
15
|
@event = event
|
16
16
|
@repeat = repeat
|
17
|
-
@started_at =
|
17
|
+
@started_at = Process.clock_gettime(Process::CLOCK_REALTIME)
|
18
18
|
@last_fired_at = nil
|
19
19
|
reschedule
|
20
20
|
end
|
@@ -32,7 +32,7 @@ module NewRelic
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def calculate_next_fire_time
|
35
|
-
now =
|
35
|
+
now = Process.clock_gettime(Process::CLOCK_REALTIME)
|
36
36
|
return now if @interval == 0
|
37
37
|
fire_time = @last_fired_at || now
|
38
38
|
while fire_time <= now
|
@@ -42,10 +42,10 @@ module NewRelic
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def set_fired_time
|
45
|
-
@last_fired_at =
|
45
|
+
@last_fired_at = Process.clock_gettime(Process::CLOCK_REALTIME)
|
46
46
|
end
|
47
47
|
|
48
|
-
def due?(now=
|
48
|
+
def due?(now=Process.clock_gettime(Process::CLOCK_REALTIME))
|
49
49
|
now >= @next_fire_time
|
50
50
|
end
|
51
51
|
|
@@ -69,7 +69,7 @@ module NewRelic
|
|
69
69
|
existing_timer = @timers[timer.event]
|
70
70
|
|
71
71
|
if existing_timer
|
72
|
-
elapsed_interval =
|
72
|
+
elapsed_interval = Process.clock_gettime(Process::CLOCK_REALTIME) - existing_timer.last_interval_start
|
73
73
|
timer.advance(elapsed_interval)
|
74
74
|
end
|
75
75
|
|
@@ -80,7 +80,7 @@ module NewRelic
|
|
80
80
|
|
81
81
|
def next_timeout
|
82
82
|
return nil if @timers.empty?
|
83
|
-
timeout = @timers.values.map(&:next_fire_time).min -
|
83
|
+
timeout = @timers.values.map(&:next_fire_time).min - Process.clock_gettime(Process::CLOCK_REALTIME)
|
84
84
|
timeout < 0 ? 0 : timeout
|
85
85
|
end
|
86
86
|
|
@@ -18,38 +18,6 @@ module NewRelic
|
|
18
18
|
module External
|
19
19
|
extend self
|
20
20
|
|
21
|
-
# This method creates and starts an external request segment using the
|
22
|
-
# given library, URI, and procedure. This is used to time external calls
|
23
|
-
# made over HTTP.
|
24
|
-
#
|
25
|
-
# @param [String] library a string of the class name of the library used to
|
26
|
-
# make the external call, for example, 'Net::HTTP'.
|
27
|
-
#
|
28
|
-
# @param [String, URI] uri indicates the URI to which the
|
29
|
-
# external request is being made. The URI should begin with the protocol,
|
30
|
-
# for example, 'https://github.com'.
|
31
|
-
#
|
32
|
-
# @param [String] procedure the HTTP method being used for the external
|
33
|
-
# request as a string, for example, 'GET'.
|
34
|
-
#
|
35
|
-
# @api public
|
36
|
-
def start_segment(library: nil, uri: nil, procedure: nil)
|
37
|
-
Deprecator.deprecate 'External.start_segment',
|
38
|
-
'Tracer#start_external_request_segment'
|
39
|
-
|
40
|
-
raise ArgumentError, 'Argument `library` is required' if library.nil?
|
41
|
-
raise ArgumentError, 'Argument `uri` is required' if uri.nil?
|
42
|
-
raise ArgumentError, 'Argument `procedure` is required' if procedure.nil?
|
43
|
-
|
44
|
-
::NewRelic::Agent.record_api_supportability_metric(:start_segment)
|
45
|
-
|
46
|
-
::NewRelic::Agent::Tracer.start_external_request_segment(
|
47
|
-
library: library,
|
48
|
-
uri: uri,
|
49
|
-
procedure: procedure
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
21
|
NON_HTTP_CAT_ID_HEADER = 'NewRelicID'.freeze
|
54
22
|
NON_HTTP_CAT_TXN_HEADER = 'NewRelicTransaction'.freeze
|
55
23
|
NON_HTTP_CAT_SYNTHETICS_HEADER = 'NewRelicSynthetics'.freeze
|
@@ -46,7 +46,7 @@ module NewRelic
|
|
46
46
|
# NOTE: response_object should be non-nil!
|
47
47
|
class AbstractResponse # :nodoc:
|
48
48
|
|
49
|
-
def initialize
|
49
|
+
def initialize(wrapped_response)
|
50
50
|
if wrapped_response.nil?
|
51
51
|
raise ArgumentError, WHINY_NIL_ERROR % self.class
|
52
52
|
end
|
@@ -65,7 +65,7 @@ module NewRelic
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
-
def get_status_code_using
|
68
|
+
def get_status_code_using(method_name)
|
69
69
|
return unless @wrapped_response.respond_to?(method_name)
|
70
70
|
code = @wrapped_response.send(method_name).to_i
|
71
71
|
code == 0 ? nil : code
|
@@ -4,6 +4,7 @@
|
|
4
4
|
# frozen_string_literal: true
|
5
5
|
|
6
6
|
require_relative 'abstract'
|
7
|
+
require 'resolv'
|
7
8
|
|
8
9
|
module NewRelic
|
9
10
|
module Agent
|
@@ -61,9 +62,14 @@ module NewRelic
|
|
61
62
|
when /^https?:\/\//
|
62
63
|
::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(@request.path)
|
63
64
|
else
|
65
|
+
connection_address = @connection.address
|
66
|
+
if (connection_address =~ Resolv::IPv6::Regex)
|
67
|
+
connection_address = "[#{connection_address}]"
|
68
|
+
end
|
69
|
+
|
64
70
|
scheme = @connection.use_ssl? ? 'https' : 'http'
|
65
71
|
::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(
|
66
|
-
"#{scheme}://#{
|
72
|
+
"#{scheme}://#{connection_address}:#{@connection.port}#{@request.path}"
|
67
73
|
)
|
68
74
|
end
|
69
75
|
end
|
@@ -91,7 +91,7 @@ module NewRelic
|
|
91
91
|
|
92
92
|
def queue_start(request)
|
93
93
|
if request && request.respond_to?(:env)
|
94
|
-
QueueTime.parse_frontend_timestamp(request.env,
|
94
|
+
QueueTime.parse_frontend_timestamp(request.env, Process.clock_gettime(Process::CLOCK_REALTIME))
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -26,9 +26,9 @@ DependencyDetection.defer do
|
|
26
26
|
gateway_name = self.name.split('::').last
|
27
27
|
[:authorize, :purchase, :credit, :void, :capture, :recurring, :store, :unstore, :update].each do |operation|
|
28
28
|
if implemented_methods.include?(operation)
|
29
|
-
add_method_tracer operation, "ActiveMerchant/gateway/#{gateway_name}/#{operation}"
|
30
|
-
|
31
|
-
|
29
|
+
add_method_tracer operation, [-> (*) { "ActiveMerchant/gateway/#{gateway_name}/#{operation}" },
|
30
|
+
-> (*) { "ActiveMerchant/gateway/#{gateway_name}" },
|
31
|
+
-> (*) { "ActiveMerchant/operation/#{operation}" }]
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -84,8 +84,6 @@ module NewRelic
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def active_record_config(payload)
|
87
|
-
return unless payload[:connection_id]
|
88
|
-
|
89
87
|
# handle if the notification payload provides the AR connection
|
90
88
|
# available in Rails 6+ & our ActiveRecordNotifications#log extension
|
91
89
|
if payload[:connection]
|
@@ -93,8 +91,8 @@ module NewRelic
|
|
93
91
|
return connection_config if connection_config
|
94
92
|
end
|
95
93
|
|
94
|
+
return unless connection_id = payload[:connection_id]
|
96
95
|
connection = nil
|
97
|
-
connection_id = payload[:connection_id]
|
98
96
|
|
99
97
|
::ActiveRecord::Base.connection_handler.connection_pool_list.each do |handler|
|
100
98
|
connection = handler.connections.detect do |conn|
|
@@ -65,7 +65,7 @@ module NewRelic
|
|
65
65
|
def pop_with_tracing
|
66
66
|
bunny_error, delivery_info, message_properties, _payload = nil, nil, nil, nil
|
67
67
|
begin
|
68
|
-
t0 =
|
68
|
+
t0 = Process.clock_gettime(Process::CLOCK_REALTIME)
|
69
69
|
msg = yield
|
70
70
|
delivery_info, message_properties, _payload = msg
|
71
71
|
rescue StandardError => error
|
@@ -179,6 +179,7 @@ module NewRelic
|
|
179
179
|
#{without_method_name}(*args, &block)
|
180
180
|
end
|
181
181
|
end
|
182
|
+
ruby2_keywords(:#{with_method_name}) if respond_to?(:ruby2_keywords, true)
|
182
183
|
EOC
|
183
184
|
|
184
185
|
visibility = NewRelic::Helper.instance_method_visibility self, method
|
@@ -276,7 +277,7 @@ module NewRelic
|
|
276
277
|
end
|
277
278
|
|
278
279
|
# Yield to the given block with NewRelic tracing. Used by
|
279
|
-
# default instrumentation on controller actions in Rails
|
280
|
+
# default instrumentation on controller actions in Rails.
|
280
281
|
# But it can also be used in custom instrumentation of controller
|
281
282
|
# methods and background tasks.
|
282
283
|
#
|
@@ -16,10 +16,11 @@ module NewRelic
|
|
16
16
|
when self.class.respond_to?(:default_name) then self.class.default_name
|
17
17
|
end
|
18
18
|
NewRelic::DelayedJobInjection.worker_name = worker_name
|
19
|
-
|
19
|
+
|
20
|
+
# TODO: Refactor the last line of this condition so that it can be evaluated in both prepend and chain instrumentation
|
20
21
|
if defined?(::Delayed::Job) && ::Delayed::Job.method_defined?(:invoke_job) &&
|
21
|
-
!(::Delayed::Job.method_defined?(:invoke_job_without_new_relic)
|
22
|
-
|
22
|
+
!(::Delayed::Job.method_defined?(:invoke_job_without_new_relic))
|
23
|
+
|
23
24
|
::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation [part 2/2]'
|
24
25
|
install_newrelic_job_tracer
|
25
26
|
NewRelic::Control.instance.init_plugin :dispatcher => :delayed_job
|
@@ -27,7 +28,6 @@ module NewRelic
|
|
27
28
|
NewRelic::Agent.logger.warn("Did not find a Delayed::Job class responding to invoke_job, aborting DJ instrumentation")
|
28
29
|
end
|
29
30
|
end
|
30
|
-
|
31
31
|
end
|
32
32
|
|
33
33
|
module DelayedJobTracer
|
@@ -5,17 +5,9 @@
|
|
5
5
|
DependencyDetection.defer do
|
6
6
|
named :excon
|
7
7
|
|
8
|
-
# We
|
9
|
-
# - For newer versions, use the middleware mechanism Excon exposes
|
10
|
-
# - For older versions, monkey-patch Excon::Connection#request
|
8
|
+
# We instrument Excon 0.19.0 and above using the middleware mechanism
|
11
9
|
#
|
12
10
|
# EXCON_MIN_VERSION is the minimum version we attempt to instrument at all.
|
13
|
-
# EXCON_MIDDLEWARE_MIN_VERSION is the min version we use the newer
|
14
|
-
# instrumentation for.
|
15
|
-
#
|
16
|
-
# Note that middlewares were added to Excon prior to 0.19, but we don't
|
17
|
-
# use middleware-based instrumentation prior to that version because it didn't
|
18
|
-
# expose a way for middlewares to know about request failures.
|
19
11
|
#
|
20
12
|
# Why don't we use Excon.defaults[:instrumentor]?
|
21
13
|
# While this might seem a perfect fit, it unfortunately isn't suitable in
|
@@ -25,8 +17,7 @@ DependencyDetection.defer do
|
|
25
17
|
# so we could safely subscribe and not be clobbered by future subscribers,
|
26
18
|
# but alas, it does not yet.
|
27
19
|
|
28
|
-
EXCON_MIN_VERSION = Gem::Version.new("0.
|
29
|
-
EXCON_MIDDLEWARE_MIN_VERSION = Gem::Version.new("0.19.0")
|
20
|
+
EXCON_MIN_VERSION = Gem::Version.new("0.19.0")
|
30
21
|
|
31
22
|
depends_on do
|
32
23
|
defined?(::Excon) && defined?(::Excon::VERSION)
|
@@ -45,11 +36,7 @@ DependencyDetection.defer do
|
|
45
36
|
require 'new_relic/agent/distributed_tracing/cross_app_tracing'
|
46
37
|
require 'new_relic/agent/http_clients/excon_wrappers'
|
47
38
|
|
48
|
-
|
49
|
-
install_middleware_excon_instrumentation
|
50
|
-
else
|
51
|
-
install_legacy_excon_instrumentation
|
52
|
-
end
|
39
|
+
install_middleware_excon_instrumentation
|
53
40
|
end
|
54
41
|
|
55
42
|
def install_middleware_excon_instrumentation
|
@@ -63,11 +50,5 @@ DependencyDetection.defer do
|
|
63
50
|
::NewRelic::Agent.logger.warn("Did not find :middlewares key in Excon.defaults, skipping Excon instrumentation")
|
64
51
|
end
|
65
52
|
end
|
66
|
-
|
67
|
-
def install_legacy_excon_instrumentation
|
68
|
-
::NewRelic::Agent::Deprecator.deprecate :install_legacy_excon_instrumentation, :install_middleware_excon_instrumentation, "8.0.0"
|
69
|
-
::NewRelic::Agent.logger.warn 'Installing deprecated legacy Excon instrumentation. This instrumentation will be removed in a future release. Update Excon version to > 0.19.0 for updated instrumentation'
|
70
|
-
require 'new_relic/agent/instrumentation/excon/connection'
|
71
|
-
::Excon::Connection.install_newrelic_instrumentation
|
72
|
-
end
|
73
53
|
end
|
54
|
+
|
@@ -0,0 +1,21 @@
|
|
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::Agent::Instrumentation
|
6
|
+
module Logger
|
7
|
+
def self.instrument!
|
8
|
+
::Logger.class_eval do
|
9
|
+
include NewRelic::Agent::Instrumentation::Logger
|
10
|
+
|
11
|
+
alias_method :format_message_without_new_relic, :format_message
|
12
|
+
|
13
|
+
def format_message(severity, datetime, progname, msg)
|
14
|
+
format_message_with_tracing(severity, datetime, progname, msg) do
|
15
|
+
format_message_without_new_relic(severity, datetime, progname, msg)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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 Logger
|
9
|
+
def skip_instrumenting?
|
10
|
+
defined?(@skip_instrumenting) && @skip_instrumenting
|
11
|
+
end
|
12
|
+
|
13
|
+
def mark_skip_instrumenting
|
14
|
+
@skip_instrumenting = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear_skip_instrumenting
|
18
|
+
@skip_instrumenting = false
|
19
|
+
end
|
20
|
+
|
21
|
+
LINES = "Logging/lines".freeze
|
22
|
+
SIZE = "Logging/size".freeze
|
23
|
+
|
24
|
+
def line_metric_name_by_severity(severity)
|
25
|
+
@line_metrics ||= {}
|
26
|
+
@line_metrics[severity] ||= "Logging/lines/#{severity}".freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
def size_metric_name_by_severity(severity)
|
30
|
+
@size_metrics ||= {}
|
31
|
+
@size_metrics[severity] ||= "Logging/size/#{severity}".freeze
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def format_message_with_tracing(severity, datetime, progname, msg)
|
36
|
+
formatted_message = yield
|
37
|
+
return formatted_message if skip_instrumenting?
|
38
|
+
|
39
|
+
begin
|
40
|
+
# It's critical we don't instrument logging from metric recording
|
41
|
+
# methods within NewRelic::Agent, or we'll stack overflow!!
|
42
|
+
mark_skip_instrumenting
|
43
|
+
|
44
|
+
NewRelic::Agent.increment_metric(LINES)
|
45
|
+
NewRelic::Agent.increment_metric(line_metric_name_by_severity(severity))
|
46
|
+
|
47
|
+
size = formatted_message.nil? ? 0 : formatted_message.bytesize
|
48
|
+
NewRelic::Agent.record_metric(SIZE, size)
|
49
|
+
NewRelic::Agent.record_metric(size_metric_name_by_severity(severity), size)
|
50
|
+
|
51
|
+
return formatted_message
|
52
|
+
ensure
|
53
|
+
clear_skip_instrumenting
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,13 @@
|
|
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::Agent::Instrumentation
|
6
|
+
module Logger::Prepend
|
7
|
+
include NewRelic::Agent::Instrumentation::Logger
|
8
|
+
|
9
|
+
def format_message(severity, datetime, progname, msg)
|
10
|
+
format_message_with_tracing(severity, datetime, progname, msg) { super }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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
|
+
require_relative 'logger/instrumentation'
|
6
|
+
require_relative 'logger/chain'
|
7
|
+
require_relative 'logger/prepend'
|
8
|
+
|
9
|
+
DependencyDetection.defer do
|
10
|
+
named :logger
|
11
|
+
|
12
|
+
depends_on { defined?(::Logger) }
|
13
|
+
|
14
|
+
executes do
|
15
|
+
::NewRelic::Agent.logger.info "Installing Logger instrumentation"
|
16
|
+
end
|
17
|
+
|
18
|
+
executes do
|
19
|
+
if use_prepend?
|
20
|
+
prepend_instrument ::Logger, NewRelic::Agent::Instrumentation::Logger::Prepend
|
21
|
+
else
|
22
|
+
chain_instrument NewRelic::Agent::Instrumentation::Logger
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -51,7 +51,11 @@ module NewRelic
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def instrument_send_multiget
|
54
|
-
|
54
|
+
if supports_binary_protocol?
|
55
|
+
::Dalli::Protocol::Binary
|
56
|
+
else
|
57
|
+
::Dalli::Server
|
58
|
+
end.class_eval do
|
55
59
|
include NewRelic::Agent::Instrumentation::Memcache::Tracer
|
56
60
|
alias_method :send_multiget_without_newrelic_trace, :send_multiget
|
57
61
|
|
@@ -7,11 +7,16 @@ module NewRelic::Agent::Instrumentation
|
|
7
7
|
module Memcache
|
8
8
|
module Helper
|
9
9
|
DATASTORE_INSTANCES_SUPPORTED_VERSION = Gem::Version.new '2.6.4'
|
10
|
+
BINARY_PROTOCOL_SUPPORTED_VERSION = Gem::Version.new '3.0.2'
|
10
11
|
|
11
12
|
def supports_datastore_instances?
|
12
13
|
DATASTORE_INSTANCES_SUPPORTED_VERSION <= Gem::Version.new(::Dalli::VERSION)
|
13
14
|
end
|
14
15
|
|
16
|
+
def supports_binary_protocol?
|
17
|
+
BINARY_PROTOCOL_SUPPORTED_VERSION <= Gem::Version.new(::Dalli::VERSION)
|
18
|
+
end
|
19
|
+
|
15
20
|
def client_methods
|
16
21
|
[:get, :get_multi, :set, :add, :incr, :decr, :delete, :replace, :append,
|
17
22
|
:prepend, :cas, :single_get, :multi_get, :single_cas, :multi_cas]
|
@@ -31,7 +31,13 @@ module NewRelic::Agent::Instrumentation
|
|
31
31
|
if supports_datastore_instances?
|
32
32
|
yield ::Dalli::Client, dalli_client_prepender(dalli_methods)
|
33
33
|
yield ::Dalli::Client, dalli_get_multi_prepender(:get_multi)
|
34
|
-
|
34
|
+
|
35
|
+
if supports_binary_protocol?
|
36
|
+
yield ::Dalli::Protocol::Binary, dalli_server_prepender
|
37
|
+
else
|
38
|
+
yield ::Dalli::Server, dalli_server_prepender
|
39
|
+
end
|
40
|
+
|
35
41
|
yield ::Dalli::Ring, dalli_ring_prepender
|
36
42
|
else
|
37
43
|
yield ::Dalli::Client, dalli_client_prepender(client_methods)
|
@@ -85,4 +91,4 @@ module NewRelic::Agent::Instrumentation
|
|
85
91
|
end
|
86
92
|
end
|
87
93
|
end
|
88
|
-
end
|
94
|
+
end
|
@@ -11,19 +11,15 @@ DependencyDetection.defer do
|
|
11
11
|
|
12
12
|
depends_on do
|
13
13
|
require 'new_relic/agent/datastores/mongo'
|
14
|
-
|
15
|
-
NewRelic::Agent.logger.log_once(:
|
14
|
+
unless NewRelic::Agent::Datastores::Mongo.is_supported_version?
|
15
|
+
NewRelic::Agent.logger.log_once(:warn, :mongo2, 'Detected unsupported Mongo 2, upgrade your Mongo Driver to 2.1 or newer for instrumentation')
|
16
16
|
end
|
17
17
|
NewRelic::Agent::Datastores::Mongo.is_supported_version?
|
18
18
|
end
|
19
19
|
|
20
20
|
executes do
|
21
21
|
NewRelic::Agent.logger.info 'Installing Mongo instrumentation'
|
22
|
-
|
23
|
-
install_mongo_command_subscriber
|
24
|
-
else
|
25
|
-
install_mongo_instrumentation
|
26
|
-
end
|
22
|
+
install_mongo_command_subscriber
|
27
23
|
end
|
28
24
|
|
29
25
|
def install_mongo_command_subscriber
|
@@ -33,138 +29,4 @@ DependencyDetection.defer do
|
|
33
29
|
NewRelic::Agent::Instrumentation::MongodbCommandSubscriber.new
|
34
30
|
)
|
35
31
|
end
|
36
|
-
|
37
|
-
# TODO: Remove in 8.0.0 release
|
38
|
-
def install_mongo_instrumentation
|
39
|
-
::NewRelic::Agent::Deprecator.deprecate "install_mongo_instrumentation", "install_mongo_command_subscriber", "8.0.0"
|
40
|
-
::NewRelic::Agent.logger.warn("Installing deprecated Mongo instrumentation. " \
|
41
|
-
"This instrumentation will be removed in a future release. " \
|
42
|
-
"Update Mongo version to >= 2.1.0 for updated instrumentation"
|
43
|
-
)
|
44
|
-
|
45
|
-
require 'new_relic/agent/datastores/mongo/metric_translator'
|
46
|
-
require 'new_relic/agent/datastores/mongo/statement_formatter'
|
47
|
-
|
48
|
-
hook_instrument_methods
|
49
|
-
instrument_save
|
50
|
-
instrument_ensure_index
|
51
|
-
end
|
52
|
-
|
53
|
-
def hook_instrument_methods
|
54
|
-
hook_instrument_method(::Mongo::Collection)
|
55
|
-
hook_instrument_method(::Mongo::Connection)
|
56
|
-
hook_instrument_method(::Mongo::Cursor)
|
57
|
-
hook_instrument_method(::Mongo::CollectionWriter) if defined?(::Mongo::CollectionWriter)
|
58
|
-
end
|
59
|
-
|
60
|
-
def hook_instrument_method(target_class)
|
61
|
-
target_class.class_eval do
|
62
|
-
include NewRelic::Agent::MethodTracer
|
63
|
-
|
64
|
-
# It's key that this method eats all exceptions, as it rests between the
|
65
|
-
# Mongo operation the user called and us returning them the data. Be safe!
|
66
|
-
def new_relic_notice_statement(segment, payload, name)
|
67
|
-
statement = NewRelic::Agent::Datastores::Mongo::StatementFormatter.format(payload, name)
|
68
|
-
if statement
|
69
|
-
segment.notice_nosql_statement statement
|
70
|
-
end
|
71
|
-
rescue => e
|
72
|
-
NewRelic::Agent.logger.debug("Exception during Mongo statement gathering", e)
|
73
|
-
end
|
74
|
-
|
75
|
-
def new_relic_default_payload
|
76
|
-
{ :collection => self.name, :database => self.db.name }
|
77
|
-
end
|
78
|
-
|
79
|
-
def new_relic_start_segment name, payload
|
80
|
-
product = NewRelic::Agent::Datastores::Mongo::MetricTranslator::MONGO_PRODUCT_NAME
|
81
|
-
op_and_col = NewRelic::Agent::Datastores::Mongo::MetricTranslator.operation_and_collection_for name, payload
|
82
|
-
if op_and_col
|
83
|
-
operation, collection = op_and_col
|
84
|
-
NewRelic::Agent::Tracer.start_datastore_segment(
|
85
|
-
product: product,
|
86
|
-
operation: operation,
|
87
|
-
collection: collection
|
88
|
-
)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def instrument_with_new_relic_trace(name, payload = {}, &block)
|
93
|
-
segment = new_relic_start_segment name, payload
|
94
|
-
|
95
|
-
begin
|
96
|
-
result = NewRelic::Agent.disable_all_tracing do
|
97
|
-
NewRelic::Agent::Tracer.capture_segment_error segment do
|
98
|
-
instrument_without_new_relic_trace(name, payload, &block)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
new_relic_notice_statement(segment, payload, name) if segment
|
103
|
-
result
|
104
|
-
ensure
|
105
|
-
segment.finish if segment
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
alias_method :instrument_without_new_relic_trace, :instrument
|
110
|
-
alias_method :instrument, :instrument_with_new_relic_trace
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def instrument_save
|
115
|
-
::Mongo::Collection.class_eval do
|
116
|
-
def save_with_new_relic_trace(doc, opts = {}, &block)
|
117
|
-
segment = new_relic_start_segment :save, new_relic_default_payload
|
118
|
-
|
119
|
-
begin
|
120
|
-
result = NewRelic::Agent.disable_all_tracing do
|
121
|
-
NewRelic::Agent::Tracer.capture_segment_error segment do
|
122
|
-
save_without_new_relic_trace(doc, opts, &block)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
new_relic_notice_statement(segment, doc, :save) if segment
|
127
|
-
result
|
128
|
-
ensure
|
129
|
-
segment.finish if segment
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
alias_method :save_without_new_relic_trace, :save
|
134
|
-
alias_method :save, :save_with_new_relic_trace
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
def instrument_ensure_index
|
139
|
-
::Mongo::Collection.class_eval do
|
140
|
-
def ensure_index_with_new_relic_trace(spec, opts = {}, &block)
|
141
|
-
segment = new_relic_start_segment :ensureIndex, new_relic_default_payload
|
142
|
-
|
143
|
-
begin
|
144
|
-
result = NewRelic::Agent.disable_all_tracing do
|
145
|
-
NewRelic::Agent::Tracer.capture_segment_error segment do
|
146
|
-
ensure_index_without_new_relic_trace(spec, opts, &block)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
spec = case spec
|
151
|
-
when Array
|
152
|
-
Hash[spec]
|
153
|
-
when String, Symbol
|
154
|
-
{ spec => 1 }
|
155
|
-
else
|
156
|
-
spec.dup
|
157
|
-
end
|
158
|
-
|
159
|
-
new_relic_notice_statement(segment, spec, :ensureIndex) if segment
|
160
|
-
result
|
161
|
-
ensure
|
162
|
-
segment.finish if segment
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
alias_method :ensure_index_without_new_relic_trace, :ensure_index
|
167
|
-
alias_method :ensure_index, :ensure_index_with_new_relic_trace
|
168
|
-
end
|
169
|
-
end
|
170
32
|
end
|
@@ -17,8 +17,13 @@ DependencyDetection.defer do
|
|
17
17
|
require 'new_relic/agent/http_clients/net_http_wrappers'
|
18
18
|
end
|
19
19
|
|
20
|
+
# Airbrake uses method chaining on Net::HTTP in versions < 10.0.2 (10.0.2 updated to prepend for Net:HTTP)
|
20
21
|
conflicts_with_prepend do
|
21
|
-
defined?(::Airbrake)
|
22
|
+
defined?(::Airbrake) && defined?(::Airbrake::AIRBRAKE_VERSION) && ::Gem::Version.create(::Airbrake::AIRBRAKE_VERSION) < ::Gem::Version.create('10.0.2')
|
23
|
+
end
|
24
|
+
|
25
|
+
conflicts_with_prepend do
|
26
|
+
defined?(::ScoutApm)
|
22
27
|
end
|
23
28
|
|
24
29
|
conflicts_with_prepend do
|