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
@@ -18,14 +18,14 @@ require_relative 'memcache/prepend'
18
18
  DependencyDetection.defer do
19
19
  named :memcache_client
20
20
 
21
- depends_on { defined? ::MemCache }
21
+ depends_on { defined? MemCache }
22
22
 
23
23
  executes do
24
24
  if use_prepend?
25
- prepend_module = ::NewRelic::Agent::Instrumentation::Memcache::Prepend.client_prepender(::MemCache)
26
- prepend_instrument ::MemCache, prepend_module, "MemcacheClient"
25
+ prepend_module = NewRelic::Agent::Instrumentation::Memcache::Prepend.client_prepender(MemCache)
26
+ prepend_instrument MemCache, prepend_module, "MemcacheClient"
27
27
  else
28
- chain_instrument_target ::MemCache, ::NewRelic::Agent::Instrumentation::Memcache::Chain, "MemcacheClient"
28
+ chain_instrument_target MemCache, NewRelic::Agent::Instrumentation::Memcache::Chain, "MemcacheClient"
29
29
  end
30
30
  end
31
31
  end
@@ -33,14 +33,14 @@ end
33
33
  DependencyDetection.defer do
34
34
  named :memcached
35
35
 
36
- depends_on { defined? ::Memcached }
36
+ depends_on { defined? Memcached }
37
37
 
38
38
  executes do
39
39
  if use_prepend?
40
- prepend_module = ::NewRelic::Agent::Instrumentation::Memcache::Prepend.client_prepender(::Memcached)
41
- prepend_instrument ::Memcached, prepend_module, "Memcached"
40
+ prepend_module = NewRelic::Agent::Instrumentation::Memcache::Prepend.client_prepender(Memcached)
41
+ prepend_instrument Memcached, prepend_module, "Memcached"
42
42
  else
43
- chain_instrument_target ::Memcached, ::NewRelic::Agent::Instrumentation::Memcache::Chain, "Memcached"
43
+ chain_instrument_target Memcached, NewRelic::Agent::Instrumentation::Memcache::Chain, "Memcached"
44
44
  end
45
45
  end
46
46
  end
@@ -49,16 +49,16 @@ DependencyDetection.defer do
49
49
  named :dalli
50
50
  configure_with :memcache
51
51
 
52
- depends_on { defined? ::Dalli::Client }
52
+ depends_on { defined? Dalli::Client }
53
53
 
54
54
  executes do
55
55
  if use_prepend?
56
- prepend_module = ::NewRelic::Agent::Instrumentation::Memcache::Prepend
56
+ prepend_module = NewRelic::Agent::Instrumentation::Memcache::Prepend
57
57
  prepend_module.dalli_prependers do |client_class, instrumenting_module|
58
58
  prepend_instrument client_class, instrumenting_module, "MemcachedDalli"
59
59
  end
60
60
  else
61
- chain_instrument ::NewRelic::Agent::Instrumentation::Memcache::Dalli
61
+ chain_instrument NewRelic::Agent::Instrumentation::Memcache::Dalli
62
62
  end
63
63
  end
64
64
  end
@@ -70,18 +70,18 @@ DependencyDetection.defer do
70
70
  named :dalli_cas_client
71
71
  configure_with :memcache
72
72
 
73
- depends_on { defined? ::Dalli::Client }
74
- depends_on { ::NewRelic::Agent::Instrumentation::Memcache::DalliCAS.should_instrument? }
73
+ depends_on { defined? Dalli::Client }
74
+ depends_on { NewRelic::Agent::Instrumentation::Memcache::DalliCAS.should_instrument? }
75
75
 
76
76
  executes do
77
- ::NewRelic::Agent.logger.info('Installing Dalli CAS Client Memcache instrumentation')
77
+ NewRelic::Agent.logger.info('Installing Dalli CAS Client Memcache instrumentation')
78
78
  if use_prepend?
79
- prepend_module = ::NewRelic::Agent::Instrumentation::Memcache::Prepend
79
+ prepend_module = NewRelic::Agent::Instrumentation::Memcache::Prepend
80
80
  prepend_module.dalli_cas_prependers do |client_class, instrumenting_module|
81
81
  prepend_instrument client_class, instrumenting_module, "MemcachedDalliCAS"
82
82
  end
83
83
  else
84
- chain_instrument ::NewRelic::Agent::Instrumentation::Memcache::DalliCAS
84
+ chain_instrument NewRelic::Agent::Instrumentation::Memcache::DalliCAS
85
85
  end
86
86
  end
87
87
  end
@@ -6,7 +6,7 @@ DependencyDetection.defer do
6
6
  named :mongo
7
7
 
8
8
  depends_on do
9
- defined?(::Mongo)
9
+ defined?(Mongo)
10
10
  end
11
11
 
12
12
  depends_on do
@@ -13,21 +13,21 @@ DependencyDetection.defer do
13
13
  end
14
14
 
15
15
  executes do
16
- ::NewRelic::Agent.logger.info('Installing Net:HTTP Wrappers')
16
+ NewRelic::Agent.logger.info('Installing Net:HTTP Wrappers')
17
17
  require 'new_relic/agent/http_clients/net_http_wrappers'
18
18
  end
19
19
 
20
20
  # Airbrake uses method chaining on Net::HTTP in versions < 10.0.2 (10.0.2 updated to prepend for Net:HTTP)
21
21
  conflicts_with_prepend do
22
- defined?(::Airbrake) && defined?(::Airbrake::AIRBRAKE_VERSION) && ::Gem::Version.create(::Airbrake::AIRBRAKE_VERSION) < ::Gem::Version.create('10.0.2')
22
+ defined?(Airbrake) && defined?(Airbrake::AIRBRAKE_VERSION) && Gem::Version.create(Airbrake::AIRBRAKE_VERSION) < Gem::Version.create('10.0.2')
23
23
  end
24
24
 
25
25
  conflicts_with_prepend do
26
- defined?(::ScoutApm)
26
+ defined?(ScoutApm)
27
27
  end
28
28
 
29
29
  conflicts_with_prepend do
30
- defined?(::Rack::MiniProfiler)
30
+ defined?(Rack::MiniProfiler)
31
31
  end
32
32
 
33
33
  conflicts_with_prepend do
@@ -36,9 +36,9 @@ DependencyDetection.defer do
36
36
 
37
37
  executes do
38
38
  if use_prepend?
39
- prepend_instrument ::Net::HTTP, ::NewRelic::Agent::Instrumentation::NetHTTP::Prepend
39
+ prepend_instrument Net::HTTP, NewRelic::Agent::Instrumentation::NetHTTP::Prepend
40
40
  else
41
- chain_instrument ::NewRelic::Agent::Instrumentation::NetHTTP::Chain
41
+ chain_instrument NewRelic::Agent::Instrumentation::NetHTTP::Chain
42
42
  end
43
43
  end
44
44
  end
@@ -19,12 +19,12 @@ DependencyDetection.defer do
19
19
  @name = :padrino
20
20
  configure_with :sinatra
21
21
 
22
- depends_on { defined?(::Padrino) && defined?(::Padrino::Routing::InstanceMethods) }
22
+ depends_on { defined?(Padrino) && defined?(Padrino::Routing::InstanceMethods) }
23
23
 
24
24
  executes do
25
- ::NewRelic::Agent.logger.info('Installing Padrino instrumentation')
25
+ NewRelic::Agent.logger.info('Installing Padrino instrumentation')
26
26
  if use_prepend?
27
- prepend_instrument ::Padrino::Application, NewRelic::Agent::Instrumentation::PadrinoTracer::Prepend
27
+ prepend_instrument Padrino::Application, NewRelic::Agent::Instrumentation::PadrinoTracer::Prepend
28
28
  else
29
29
  chain_instrument NewRelic::Agent::Instrumentation::PadrinoTracer::Chain
30
30
  end
@@ -6,18 +6,18 @@ DependencyDetection.defer do
6
6
  @name = :passenger
7
7
 
8
8
  depends_on do
9
- defined?(::PhusionPassenger)
9
+ defined?(PhusionPassenger)
10
10
  end
11
11
 
12
12
  executes do
13
- ::NewRelic::Agent.logger.debug("Installing Passenger event hooks.")
13
+ NewRelic::Agent.logger.debug("Installing Passenger event hooks.")
14
14
 
15
- ::PhusionPassenger.on_event(:stopping_worker_process) do
16
- ::NewRelic::Agent.logger.debug("Passenger stopping this process, shutdown the agent.")
15
+ PhusionPassenger.on_event(:stopping_worker_process) do
16
+ NewRelic::Agent.logger.debug("Passenger stopping this process, shutdown the agent.")
17
17
  NewRelic::Agent.instance.shutdown
18
18
  end
19
19
 
20
- ::PhusionPassenger.on_event(:starting_worker_process) do |forked|
20
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
21
21
  # We want to reset the stats from the stats engine in case any carried
22
22
  # over into the spawned process. Don't clear them in case any were
23
23
  # cached. We do this even in conservative spawning.
@@ -13,14 +13,14 @@ DependencyDetection.defer do
13
13
  named :rack
14
14
 
15
15
  depends_on do
16
- defined?(::Rack) && defined?(::Rack::Builder)
16
+ defined?(Rack) && defined?(Rack::Builder)
17
17
  end
18
18
 
19
19
  executes do
20
20
  if use_prepend?
21
- prepend_instrument ::Rack::Builder, NewRelic::Agent::Instrumentation::Rack::Prepend
21
+ prepend_instrument Rack::Builder, NewRelic::Agent::Instrumentation::Rack::Prepend
22
22
  else
23
- chain_instrument_target ::Rack::Builder, NewRelic::Agent::Instrumentation::Rack::Chain
23
+ chain_instrument_target Rack::Builder, NewRelic::Agent::Instrumentation::Rack::Chain
24
24
  end
25
25
  end
26
26
  end
@@ -29,14 +29,14 @@ DependencyDetection.defer do
29
29
  named :puma_rack
30
30
 
31
31
  depends_on do
32
- defined?(::Puma::Rack::Builder)
32
+ defined?(Puma::Rack::Builder)
33
33
  end
34
34
 
35
35
  executes do
36
36
  if use_prepend?
37
- prepend_instrument ::Puma::Rack::Builder, NewRelic::Agent::Instrumentation::Rack::Prepend
37
+ prepend_instrument Puma::Rack::Builder, NewRelic::Agent::Instrumentation::Rack::Prepend
38
38
  else
39
- chain_instrument_target ::Puma::Rack::Builder, NewRelic::Agent::Instrumentation::Rack::Chain
39
+ chain_instrument_target Puma::Rack::Builder, NewRelic::Agent::Instrumentation::Rack::Chain
40
40
  end
41
41
  end
42
42
  end
@@ -45,19 +45,19 @@ DependencyDetection.defer do
45
45
  named :rack_urlmap
46
46
 
47
47
  depends_on do
48
- defined?(::Rack) && defined?(::Rack::URLMap)
48
+ defined?(Rack) && defined?(Rack::URLMap)
49
49
  end
50
50
 
51
51
  depends_on do
52
- ::NewRelic::Agent::Instrumentation::RackHelpers.middleware_instrumentation_enabled?
52
+ NewRelic::Agent::Instrumentation::RackHelpers.middleware_instrumentation_enabled?
53
53
  end
54
54
 
55
55
  executes do
56
56
  if use_prepend?
57
- prepend_instrument ::Rack::URLMap, NewRelic::Agent::Instrumentation::Rack::URLMap::Prepend
57
+ prepend_instrument Rack::URLMap, NewRelic::Agent::Instrumentation::Rack::URLMap::Prepend
58
58
  else
59
- chain_instrument_target ::Rack::URLMap, NewRelic::Agent::Instrumentation::Rack::URLMap::Chain
60
- ::NewRelic::Agent::Instrumentation::RackHelpers.instrument_url_map
59
+ chain_instrument_target Rack::URLMap, NewRelic::Agent::Instrumentation::Rack::URLMap::Chain
60
+ NewRelic::Agent::Instrumentation::RackHelpers.instrument_url_map
61
61
  end
62
62
  end
63
63
  end
@@ -70,14 +70,14 @@ DependencyDetection.defer do
70
70
  end
71
71
 
72
72
  depends_on do
73
- ::NewRelic::Agent::Instrumentation::RackHelpers.middleware_instrumentation_enabled?
73
+ NewRelic::Agent::Instrumentation::RackHelpers.middleware_instrumentation_enabled?
74
74
  end
75
75
 
76
76
  executes do
77
77
  if use_prepend?
78
- prepend_instrument ::Puma::Rack::URLMap, NewRelic::Agent::Instrumentation::Rack::URLMap::Prepend
78
+ prepend_instrument Puma::Rack::URLMap, NewRelic::Agent::Instrumentation::Rack::URLMap::Prepend
79
79
  else
80
- chain_instrument_target ::Puma::Rack::URLMap, NewRelic::Agent::Instrumentation::Rack::URLMap::Chain
80
+ chain_instrument_target Puma::Rack::URLMap, NewRelic::Agent::Instrumentation::Rack::URLMap::Chain
81
81
  end
82
82
  end
83
83
  end
@@ -66,7 +66,7 @@ DependencyDetection.defer do
66
66
  @name = :rails3_controller
67
67
 
68
68
  depends_on do
69
- defined?(::Rails::VERSION::MAJOR) && ::Rails::VERSION::MAJOR.to_i == 3
69
+ defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR.to_i == 3
70
70
  end
71
71
 
72
72
  depends_on do
@@ -74,7 +74,7 @@ DependencyDetection.defer do
74
74
  end
75
75
 
76
76
  executes do
77
- ::NewRelic::Agent.logger.info('Installing Rails 3 Controller instrumentation')
77
+ NewRelic::Agent.logger.info('Installing Rails 3 Controller instrumentation')
78
78
  end
79
79
 
80
80
  executes do
@@ -92,8 +92,8 @@ DependencyDetection.defer do
92
92
 
93
93
  # Enabled for Rails 3.2
94
94
  depends_on do
95
- defined?(::Rails::VERSION::MAJOR) && defined?(::Rails::VERSION::MINOR) &&
96
- ::Rails::VERSION::MAJOR.to_i == 3 && ::Rails::VERSION::MINOR.to_i == 2
95
+ defined?(Rails::VERSION::MAJOR) && defined?(Rails::VERSION::MINOR) &&
96
+ Rails::VERSION::MAJOR.to_i == 3 && Rails::VERSION::MINOR.to_i == 2
97
97
  end
98
98
 
99
99
  depends_on do
@@ -101,7 +101,7 @@ DependencyDetection.defer do
101
101
  end
102
102
 
103
103
  executes do
104
- ::NewRelic::Agent.logger.info('Installing Rails 3.2 view instrumentation')
104
+ NewRelic::Agent.logger.info('Installing Rails 3.2 view instrumentation')
105
105
  end
106
106
 
107
107
  executes do
@@ -8,15 +8,15 @@ DependencyDetection.defer do
8
8
  named :rails_middleware
9
9
 
10
10
  depends_on do
11
- !::NewRelic::Agent.config[:disable_middleware_instrumentation]
11
+ !NewRelic::Agent.config[:disable_middleware_instrumentation]
12
12
  end
13
13
 
14
14
  depends_on do
15
- defined?(::Rails::VERSION::MAJOR) && ::Rails::VERSION::MAJOR.to_i >= 3
15
+ defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR.to_i >= 3
16
16
  end
17
17
 
18
18
  executes do
19
- ::NewRelic::Agent.logger.info("Installing Rails 3+ middleware instrumentation")
19
+ NewRelic::Agent.logger.info("Installing Rails 3+ middleware instrumentation")
20
20
  module ActionDispatch
21
21
  class MiddlewareStack
22
22
  class Middleware
@@ -9,9 +9,9 @@ DependencyDetection.defer do
9
9
  @name = :action_cable_notifications
10
10
 
11
11
  depends_on do
12
- defined?(::Rails::VERSION::MAJOR) &&
13
- ::Rails::VERSION::MAJOR.to_i >= 5 &&
14
- defined?(::ActionCable)
12
+ defined?(Rails::VERSION::MAJOR) &&
13
+ Rails::VERSION::MAJOR.to_i >= 5 &&
14
+ defined?(ActionCable)
15
15
  end
16
16
 
17
17
  depends_on do
@@ -20,7 +20,7 @@ DependencyDetection.defer do
20
20
  end
21
21
 
22
22
  executes do
23
- ::NewRelic::Agent.logger.info('Installing notifications based Action Cable instrumentation')
23
+ NewRelic::Agent.logger.info('Installing notifications based Action Cable instrumentation')
24
24
  end
25
25
 
26
26
  executes do
@@ -29,8 +29,8 @@ DependencyDetection.defer do
29
29
  NewRelic::Agent::Instrumentation::ActionCableSubscriber.new)
30
30
 
31
31
  ActiveSupport.on_load(:action_cable) do
32
- ::NewRelic::Agent::PrependSupportability.record_metrics_for(::ActionCable::Engine) if defined?(::ActionCable::Engine)
33
- ::NewRelic::Agent::PrependSupportability.record_metrics_for(::ActionCable::RemoteConnections) if defined?(::ActionCable::RemoteConnections)
32
+ NewRelic::Agent::PrependSupportability.record_metrics_for(ActionCable::Engine) if defined?(ActionCable::Engine)
33
+ NewRelic::Agent::PrependSupportability.record_metrics_for(ActionCable::RemoteConnections) if defined?(ActionCable::RemoteConnections)
34
34
  end
35
35
  end
36
36
  end
@@ -9,7 +9,7 @@ DependencyDetection.defer do
9
9
  @name = :action_controller_notifications
10
10
 
11
11
  depends_on do
12
- defined?(::Rails::VERSION::MAJOR) && ::Rails::VERSION::MAJOR.to_i >= 4
12
+ defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR.to_i >= 4
13
13
  end
14
14
 
15
15
  depends_on do
@@ -17,7 +17,7 @@ DependencyDetection.defer do
17
17
  end
18
18
 
19
19
  executes do
20
- ::NewRelic::Agent.logger.info('Installing notifications based Action Controller instrumentation')
20
+ NewRelic::Agent.logger.info('Installing notifications based Action Controller instrumentation')
21
21
  end
22
22
 
23
23
  executes do
@@ -9,7 +9,7 @@ DependencyDetection.defer do
9
9
  @name = :action_view_notifications
10
10
 
11
11
  depends_on do
12
- defined?(::Rails::VERSION::MAJOR) && ::Rails::VERSION::MAJOR.to_i >= 4
12
+ defined?(Rails::VERSION::MAJOR) && Rails::VERSION::MAJOR.to_i >= 4
13
13
  end
14
14
 
15
15
  depends_on do
@@ -22,7 +22,9 @@ DependencyDetection.defer do
22
22
  end
23
23
 
24
24
  executes do
25
- NewRelic::Agent::Instrumentation::ActionViewSubscriber.subscribe(/render_.+\.action_view$/)
26
- NewRelic::Agent::PrependSupportability.record_metrics_for(::ActionView::Base, ::ActionView::Template, ::ActionView::Renderer)
25
+ ActiveSupport.on_load(:action_view) do
26
+ NewRelic::Agent::Instrumentation::ActionViewSubscriber.subscribe(/render_.+\.action_view$/)
27
+ NewRelic::Agent::PrependSupportability.record_metrics_for(ActionView::Base, ActionView::Template, ActionView::Renderer)
28
+ end
27
29
  end
28
30
  end
@@ -0,0 +1,30 @@
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
+ require 'new_relic/agent/instrumentation/custom_events_subscriber'
6
+ require 'new_relic/agent/prepend_supportability'
7
+
8
+ DependencyDetection.defer do
9
+ @name = :custom_event_notifications
10
+
11
+ depends_on do
12
+ defined?(ActiveSupport::Notifications) &&
13
+ defined?(ActiveSupport::IsolatedExecutionState)
14
+ end
15
+
16
+ depends_on do
17
+ !NewRelic::Agent.config[:active_support_custom_events_names].empty? &&
18
+ !NewRelic::Agent::Instrumentation::CustomEventsSubscriber.subscribed?
19
+ end
20
+
21
+ executes do
22
+ NewRelic::Agent.logger.info('Installing notifications based ActiveSupport custom events instrumentation')
23
+ end
24
+
25
+ executes do
26
+ NewRelic::Agent.config[:active_support_custom_events_names].each do |name|
27
+ ActiveSupport::Notifications.subscribe(name, NewRelic::Agent::Instrumentation::CustomEventsSubscriber.new)
28
+ end
29
+ end
30
+ end
@@ -6,18 +6,18 @@ DependencyDetection.defer do
6
6
  @name = :rainbows
7
7
 
8
8
  depends_on do
9
- defined?(::Rainbows) && defined?(::Rainbows::HttpServer)
9
+ defined?(Rainbows) && defined?(Rainbows::HttpServer)
10
10
  end
11
11
 
12
12
  executes do
13
- ::NewRelic::Agent.logger.info('Installing Rainbows instrumentation')
14
- ::NewRelic::Agent.logger.info('Detected Rainbows, please see additional documentation: https://newrelic.com/docs/troubleshooting/im-using-unicorn-and-i-dont-see-any-data')
13
+ NewRelic::Agent.logger.info('Installing Rainbows instrumentation')
14
+ NewRelic::Agent.logger.info('Detected Rainbows, please see additional documentation: https://newrelic.com/docs/troubleshooting/im-using-unicorn-and-i-dont-see-any-data')
15
15
 
16
16
  deprecation_msg = 'The dispatcher rainbows is deprecated. It will be removed ' \
17
17
  'in version 9.0.0. Please use a supported dispatcher instead. ' \
18
18
  'Visit https://docs.newrelic.com/docs/apm/agents/ruby-agent/getting-started/ruby-agent-requirements-supported-frameworks for options.'
19
19
 
20
- ::NewRelic::Agent.logger.log_once(
20
+ NewRelic::Agent.logger.log_once(
21
21
  :warn,
22
22
  :deprecated_rainbows_dispatcher,
23
23
  deprecation_msg
@@ -11,19 +11,19 @@ DependencyDetection.defer do
11
11
  named :rake_instrumentation
12
12
  configure_with :rake
13
13
 
14
- depends_on { defined?(::Rake) && defined?(::Rake::VERSION) }
15
- depends_on { Gem::Version.new(::Rake::VERSION) >= Gem::Version.new("10.0.0") }
16
- depends_on { ::NewRelic::Agent.config[:'rake.tasks'].any? }
17
- depends_on { ::NewRelic::Agent::Instrumentation::Rake.safe_from_third_party_gem? }
14
+ depends_on { defined?(Rake) && defined?(Rake::VERSION) }
15
+ depends_on { Gem::Version.new(Rake::VERSION) >= Gem::Version.new("10.0.0") }
16
+ depends_on { NewRelic::Agent.config[:'rake.tasks'].any? }
17
+ depends_on { NewRelic::Agent::Instrumentation::Rake.safe_from_third_party_gem? }
18
18
 
19
19
  executes do
20
- ::NewRelic::Agent.logger.info("Installing Rake instrumentation")
21
- ::NewRelic::Agent.logger.debug("Instrumenting Rake tasks: #{::NewRelic::Agent.config[:'rake.tasks']}")
20
+ NewRelic::Agent.logger.info("Installing Rake instrumentation")
21
+ NewRelic::Agent.logger.debug("Instrumenting Rake tasks: #{NewRelic::Agent.config[:'rake.tasks']}")
22
22
  end
23
23
 
24
24
  executes do
25
25
  if use_prepend?
26
- prepend_instrument ::Rake::Task, NewRelic::Agent::Instrumentation::Rake::Prepend
26
+ prepend_instrument Rake::Task, NewRelic::Agent::Instrumentation::Rake::Prepend
27
27
  else
28
28
  chain_instrument NewRelic::Agent::Instrumentation::Rake::Chain
29
29
  end
@@ -27,12 +27,17 @@ module NewRelic::Agent::Instrumentation
27
27
 
28
28
  # Used for Redis 5.x+
29
29
  def call_pipelined_with_tracing(pipeline)
30
+ db = begin
31
+ _nr_redis_client_config.db
32
+ rescue StandardError => e
33
+ NewRelic::Agent.logger.error("Failed to determine configured Redis db value: #{e.class} - #{e.message}")
34
+ nil
35
+ end
36
+
30
37
  operation = pipeline.flatten.include?('MULTI') ? Constants::MULTI_OPERATION : Constants::PIPELINE_OPERATION
31
38
  statement = ::NewRelic::Agent::Datastores::Redis.format_pipeline_commands(pipeline)
32
39
 
33
- # call_pipelined isn't invoked on the client object, so use client.db to
34
- # access the client instance var on self
35
- with_tracing(operation, statement: statement, database: client.db) { yield }
40
+ with_tracing(operation, statement: statement, database: db) { yield }
36
41
  end
37
42
 
38
43
  private
@@ -49,26 +54,40 @@ module NewRelic::Agent::Instrumentation
49
54
  segment.notice_nosql_statement(statement) if statement
50
55
  NewRelic::Agent::Tracer.capture_segment_error(segment) { yield }
51
56
  ensure
52
- segment.finish if segment
57
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
53
58
  end
54
59
  end
55
60
 
56
61
  def _nr_hostname
57
- _nr_client.path ? Constants::LOCALHOST : _nr_client.host
62
+ _nr_redis_client_config.path ? Constants::LOCALHOST : _nr_redis_client_config.host
58
63
  rescue => e
59
- NewRelic::Agent.logger.debug("Failed to retrieve Redis host: #{e}")
64
+ NewRelic::Agent.logger.debug("Failed to retrieve Redis host: #{e.class} - #{e.message}")
60
65
  Constants::UNKNOWN
61
66
  end
62
67
 
63
68
  def _nr_port_path_or_id
64
- _nr_client.path || _nr_client.port
69
+ _nr_redis_client_config.path || _nr_redis_client_config.port
65
70
  rescue => e
66
- NewRelic::Agent.logger.debug("Failed to retrieve Redis port_path_or_id: #{e}")
71
+ NewRelic::Agent.logger.debug("Failed to retrieve Redis port_path_or_id: #{e.class} - #{e.message}")
67
72
  Constants::UNKNOWN
68
73
  end
69
74
 
70
- def _nr_client
71
- @nr_client ||= self.is_a?(::Redis::Client) ? self : client
75
+ def _nr_redis_client_config
76
+ @nr_config ||= begin
77
+ # redis gem
78
+ config = if defined?(::Redis::Client) && self.is_a?(::Redis::Client)
79
+ self
80
+ # redis-client gem v0.11+ (self is a RedisClient::Middlewares)
81
+ elsif respond_to?(:client)
82
+ client && client.config
83
+ # redis-client gem <0.11 (self is a RedisClient::Middlewares)
84
+ elsif defined?(::RedisClient)
85
+ ::RedisClient.config if ::RedisClient.respond_to?(:config)
86
+ end
87
+ raise 'Unable to locate the underlying Redis client configuration.' unless config
88
+
89
+ config
90
+ end
72
91
  end
73
92
  end
74
93
  end
@@ -17,11 +17,11 @@ DependencyDetection.defer do
17
17
  configure_with :redis
18
18
 
19
19
  depends_on do
20
- defined?(::Redis) && defined?(::Redis::VERSION)
20
+ defined?(Redis) && defined?(Redis::VERSION)
21
21
  end
22
22
 
23
23
  conflicts_with_prepend do
24
- defined?(::PrometheusExporter)
24
+ defined?(PrometheusExporter)
25
25
  end
26
26
 
27
27
  depends_on do
@@ -32,11 +32,11 @@ DependencyDetection.defer do
32
32
  executes do
33
33
  NewRelic::Agent.logger.info('Installing Redis Instrumentation')
34
34
  if NewRelic::Agent::Instrumentation::Redis::Constants::HAS_REDIS_CLIENT
35
- ::RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::Middleware)
35
+ RedisClient.register(NewRelic::Agent::Instrumentation::RedisClient::Middleware)
36
36
  end
37
37
 
38
38
  if use_prepend?
39
- prepend_instrument ::Redis::Client, NewRelic::Agent::Instrumentation::Redis::Prepend
39
+ prepend_instrument Redis::Client, NewRelic::Agent::Instrumentation::Redis::Prepend
40
40
  else
41
41
  chain_instrument NewRelic::Agent::Instrumentation::Redis::Chain
42
42
  end
@@ -10,21 +10,21 @@ DependencyDetection.defer do
10
10
  @name = :resque
11
11
 
12
12
  depends_on do
13
- defined?(::Resque::Job) && !NewRelic::Agent.config[:disable_resque]
13
+ defined?(Resque::Job) && !NewRelic::Agent.config[:disable_resque]
14
14
  end
15
15
 
16
16
  # Airbrake uses method chaining on Resque::Job on versions < 11.0.3
17
17
  conflicts_with_prepend do
18
- defined?(::Airbrake) && defined?(::Airbrake::AIRBRAKE_VERSION) && ::Gem::Version.create(::Airbrake::AIRBRAKE_VERSION) < ::Gem::Version.create('11.0.3')
18
+ defined?(Airbrake) && defined?(Airbrake::AIRBRAKE_VERSION) && Gem::Version.create(Airbrake::AIRBRAKE_VERSION) < Gem::Version.create('11.0.3')
19
19
  end
20
20
 
21
21
  executes do
22
- ::NewRelic::Agent.logger.info('Installing Resque instrumentation')
22
+ NewRelic::Agent.logger.info('Installing Resque instrumentation')
23
23
  end
24
24
 
25
25
  executes do
26
26
  if NewRelic::Agent.config[:'resque.use_ruby_dns'] && NewRelic::Agent.config[:dispatcher] == :resque
27
- ::NewRelic::Agent.logger.info('Requiring resolv-replace')
27
+ NewRelic::Agent.logger.info('Requiring resolv-replace')
28
28
  require 'resolv'
29
29
  require 'resolv-replace'
30
30
  end
@@ -32,30 +32,30 @@ DependencyDetection.defer do
32
32
 
33
33
  executes do
34
34
  if use_prepend?
35
- prepend_instrument ::Resque::Job, NewRelic::Agent::Instrumentation::Resque::Prepend
35
+ prepend_instrument Resque::Job, NewRelic::Agent::Instrumentation::Resque::Prepend
36
36
  else
37
37
  chain_instrument NewRelic::Agent::Instrumentation::Resque::Chain
38
38
  end
39
39
 
40
40
  if NewRelic::Agent::Instrumentation::Resque::Helper.resque_fork_per_job?
41
- ::Resque.before_first_fork do
41
+ Resque.before_first_fork do
42
42
  NewRelic::Agent.manual_start(:dispatcher => :resque,
43
43
  :sync_startup => true,
44
44
  :start_channel_listener => true)
45
45
  end
46
46
 
47
- ::Resque.before_fork do |job|
47
+ Resque.before_fork do |job|
48
48
  NewRelic::Agent.register_report_channel(job.object_id)
49
49
  end
50
50
 
51
- ::Resque.after_fork do |job|
51
+ Resque.after_fork do |job|
52
52
  # Only suppress reporting Instance/Busy for forked children
53
53
  # Traced errors UI relies on having the parent process report that metric
54
54
  NewRelic::Agent.after_fork(:report_to_channel => job.object_id,
55
55
  :report_instance_busy => false)
56
56
  end
57
57
  else
58
- ::Resque.before_first_fork do
58
+ Resque.before_first_fork do
59
59
  NewRelic::Agent.manual_start(:dispatcher => :resque,
60
60
  :sync_startup => true,
61
61
  :start_channel_listener => false)
@@ -7,7 +7,7 @@ DependencyDetection.defer do
7
7
  @name = :sequel
8
8
 
9
9
  depends_on do
10
- defined?(::Sequel)
10
+ defined?(Sequel)
11
11
  end
12
12
 
13
13
  depends_on do
@@ -24,7 +24,7 @@ DependencyDetection.defer do
24
24
  executes do
25
25
  if supported_sequel_version?
26
26
 
27
- ::NewRelic::Agent.logger.info('Installing Sequel instrumentation')
27
+ NewRelic::Agent.logger.info('Installing Sequel instrumentation')
28
28
 
29
29
  if Sequel::Database.respond_to?(:extension)
30
30
  Sequel::Database.extension(:newrelic_instrumentation)