newrelic_rpm 9.4.2 → 9.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +138 -10
  3. data/Rakefile +1 -1
  4. data/lib/new_relic/agent/attribute_pre_filtering.rb +109 -0
  5. data/lib/new_relic/agent/configuration/default_source.rb +153 -33
  6. data/lib/new_relic/agent/http_clients/async_http_wrappers.rb +83 -0
  7. data/lib/new_relic/agent/http_clients/ethon_wrappers.rb +111 -0
  8. data/lib/new_relic/agent/http_clients/httpx_wrappers.rb +93 -0
  9. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -2
  10. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/chain.rb +69 -0
  11. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/instrumentation.rb +13 -0
  12. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/prepend.rb +37 -0
  13. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger.rb +23 -0
  14. data/lib/new_relic/agent/instrumentation/active_support_logger/instrumentation.rb +4 -0
  15. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +3 -1
  16. data/lib/new_relic/agent/instrumentation/async_http/chain.rb +23 -0
  17. data/lib/new_relic/agent/instrumentation/async_http/instrumentation.rb +37 -0
  18. data/lib/new_relic/agent/instrumentation/async_http/prepend.rb +15 -0
  19. data/lib/new_relic/agent/instrumentation/async_http.rb +26 -0
  20. data/lib/new_relic/agent/instrumentation/bunny/instrumentation.rb +9 -0
  21. data/lib/new_relic/agent/instrumentation/concurrent_ruby/instrumentation.rb +2 -2
  22. data/lib/new_relic/agent/instrumentation/curb/instrumentation.rb +4 -0
  23. data/lib/new_relic/agent/instrumentation/delayed_job/instrumentation.rb +3 -0
  24. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +4 -1
  25. data/lib/new_relic/agent/instrumentation/ethon/chain.rb +39 -0
  26. data/lib/new_relic/agent/instrumentation/ethon/instrumentation.rb +105 -0
  27. data/lib/new_relic/agent/instrumentation/ethon/prepend.rb +35 -0
  28. data/lib/new_relic/agent/instrumentation/ethon.rb +39 -0
  29. data/lib/new_relic/agent/instrumentation/excon/middleware.rb +3 -0
  30. data/lib/new_relic/agent/instrumentation/grape/instrumentation.rb +4 -0
  31. data/lib/new_relic/agent/instrumentation/grpc/client/instrumentation.rb +4 -0
  32. data/lib/new_relic/agent/instrumentation/grpc/server/instrumentation.rb +4 -0
  33. data/lib/new_relic/agent/instrumentation/grpc_client.rb +1 -1
  34. data/lib/new_relic/agent/instrumentation/grpc_server.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/httpclient/instrumentation.rb +4 -0
  36. data/lib/new_relic/agent/instrumentation/httprb/instrumentation.rb +4 -0
  37. data/lib/new_relic/agent/instrumentation/httpx/chain.rb +20 -0
  38. data/lib/new_relic/agent/instrumentation/httpx/instrumentation.rb +51 -0
  39. data/lib/new_relic/agent/instrumentation/httpx/prepend.rb +15 -0
  40. data/lib/new_relic/agent/instrumentation/httpx.rb +27 -0
  41. data/lib/new_relic/agent/instrumentation/logger/instrumentation.rb +3 -0
  42. data/lib/new_relic/agent/instrumentation/memcache/instrumentation.rb +9 -0
  43. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +1 -3
  44. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +5 -1
  45. data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +4 -0
  46. data/lib/new_relic/agent/instrumentation/padrino/instrumentation.rb +4 -0
  47. data/lib/new_relic/agent/instrumentation/rack/instrumentation.rb +6 -0
  48. data/lib/new_relic/agent/instrumentation/rails3/action_controller.rb +4 -0
  49. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +1 -0
  50. data/lib/new_relic/agent/instrumentation/rake/instrumentation.rb +4 -0
  51. data/lib/new_relic/agent/instrumentation/redis/instrumentation.rb +4 -0
  52. data/lib/new_relic/agent/instrumentation/resque/instrumentation.rb +4 -0
  53. data/lib/new_relic/agent/instrumentation/roda/ignorer.rb +45 -0
  54. data/lib/new_relic/agent/instrumentation/roda/instrumentation.rb +16 -0
  55. data/lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb +1 -2
  56. data/lib/new_relic/agent/instrumentation/roda.rb +2 -0
  57. data/lib/new_relic/agent/instrumentation/sidekiq/client.rb +4 -0
  58. data/lib/new_relic/agent/instrumentation/sidekiq/server.rb +26 -3
  59. data/lib/new_relic/agent/instrumentation/sidekiq.rb +5 -3
  60. data/lib/new_relic/agent/instrumentation/sinatra/instrumentation.rb +4 -0
  61. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -3
  62. data/lib/new_relic/agent/instrumentation/stripe.rb +28 -0
  63. data/lib/new_relic/agent/instrumentation/stripe_subscriber.rb +77 -0
  64. data/lib/new_relic/agent/instrumentation/tilt/instrumentation.rb +4 -0
  65. data/lib/new_relic/agent/instrumentation/typhoeus/instrumentation.rb +5 -1
  66. data/lib/new_relic/agent/messaging.rb +2 -2
  67. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +12 -1
  68. data/lib/new_relic/agent/rules_engine.rb +1 -1
  69. data/lib/new_relic/agent/span_event_primitive.rb +16 -4
  70. data/lib/new_relic/agent/system_info.rb +26 -0
  71. data/lib/new_relic/agent/tracer.rb +1 -3
  72. data/lib/new_relic/agent/transaction/abstract_segment.rb +55 -0
  73. data/lib/new_relic/agent/transaction/external_request_segment.rb +5 -2
  74. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -2
  75. data/lib/new_relic/agent/transaction/request_attributes.rb +1 -3
  76. data/lib/new_relic/agent/transaction.rb +25 -2
  77. data/lib/new_relic/agent/transaction_error_primitive.rb +16 -0
  78. data/lib/new_relic/agent/transaction_event_primitive.rb +19 -0
  79. data/lib/new_relic/agent/utilization/gcp.rb +1 -3
  80. data/lib/new_relic/agent.rb +18 -2
  81. data/lib/new_relic/constants.rb +3 -0
  82. data/lib/new_relic/control/frameworks/rails.rb +14 -2
  83. data/lib/new_relic/language_support.rb +4 -0
  84. data/lib/new_relic/rack/agent_hooks.rb +1 -1
  85. data/lib/new_relic/rack/agent_middleware.rb +0 -16
  86. data/lib/new_relic/supportability_helper.rb +1 -0
  87. data/lib/new_relic/version.rb +2 -2
  88. data/lib/tasks/instrumentation_generator/instrumentation.thor +3 -3
  89. data/lib/tasks/tests.rake +71 -0
  90. data/newrelic.yml +93 -32
  91. data/newrelic_rpm.gemspec +4 -1
  92. metadata +39 -2
@@ -0,0 +1,93 @@
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_relative 'abstract'
6
+
7
+ module NewRelic
8
+ module Agent
9
+ module HTTPClients
10
+ # HTTPX returns an instance of HTTPX::ErrorResponse on error,
11
+ # and that instance itself yields the underlying HTTP response
12
+ # object via #response, but depending on the error that HTTP
13
+ # response object could be unset.
14
+ class HTTPXErrorResponse
15
+ def status; end
16
+ def headers; {}; end
17
+ end
18
+
19
+ class HTTPXHTTPResponse < AbstractResponse
20
+ def initialize(response)
21
+ if response.is_a?(::HTTPX::ErrorResponse)
22
+ @response = response.response || HTTPXErrorResponse.new
23
+ else
24
+ @response = response
25
+ end
26
+ end
27
+
28
+ def status_code
29
+ @response.status
30
+ end
31
+
32
+ def [](key)
33
+ headers[format_key(key)]
34
+ end
35
+
36
+ def headers
37
+ headers ||= @response.headers.to_hash.each_with_object({}) do |(k, v), h|
38
+ h[format_key(k)] = v
39
+ end
40
+ end
41
+ alias to_hash headers
42
+
43
+ private
44
+
45
+ def format_key(key)
46
+ key.tr('-', '_').downcase
47
+ end
48
+ end
49
+
50
+ class HTTPXHTTPRequest < AbstractRequest
51
+ attr_reader :uri
52
+
53
+ DEFAULT_HOST = 'UNKNOWN_HOST'
54
+ TYPE = 'HTTPX'
55
+ LHOST = 'host'.freeze
56
+ UHOST = 'Host'.freeze
57
+
58
+ def initialize(request)
59
+ @request = request
60
+ @uri = request.uri
61
+ end
62
+
63
+ def type
64
+ TYPE
65
+ end
66
+
67
+ def host_from_header
68
+ self[LHOST] || self[UHOST]
69
+ end
70
+
71
+ def host
72
+ host_from_header || uri.host&.downcase || DEFAULT_HOST
73
+ end
74
+
75
+ def method
76
+ @request.verb
77
+ end
78
+
79
+ def []=(key, value)
80
+ @request.headers[key] = value
81
+ end
82
+
83
+ def headers
84
+ @request.headers
85
+ end
86
+
87
+ def [](key)
88
+ @request.headers[key]
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -232,7 +232,6 @@ module NewRelic
232
232
 
233
233
  DEFAULT = 'default'.freeze
234
234
  UNKNOWN = 'unknown'.freeze
235
- SLASH = '/'.freeze
236
235
  LOCALHOST = 'localhost'.freeze
237
236
 
238
237
  def adapter_from_config(config)
@@ -288,7 +287,7 @@ module NewRelic
288
287
  private
289
288
 
290
289
  def postgres_unix_domain_socket_case?(host, adapter)
291
- adapter == :postgres && host && host.start_with?(SLASH)
290
+ adapter == :postgres && host && host.start_with?(NewRelic::SLASH)
292
291
  end
293
292
 
294
293
  def mysql_default_case?(config, adapter)
@@ -0,0 +1,69 @@
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::Agent::Instrumentation
6
+ module ActiveSupportBroadcastLogger::Chain
7
+ def self.instrument!
8
+ ::ActiveSupportBroadcastLogger.class_eval do
9
+ include NewRelic::Agent::Instrumentation::ActiveSupportBroadcastLogger
10
+
11
+ alias_method(:add_without_new_relic, :add)
12
+
13
+ def add(*args, &task)
14
+ record_one_broadcast_with_new_relic(*args) do
15
+ add_without_new_relic(*args, &traced_task)
16
+ end
17
+ end
18
+
19
+ alias_method(:debug_without_new_relic, :debug)
20
+
21
+ def debug(*args, &task)
22
+ record_one_broadcast_with_new_relic(*args) do
23
+ debug_without_new_relic(*args, &traced_task)
24
+ end
25
+ end
26
+
27
+ alias_method(:info_without_new_relic, :info)
28
+
29
+ def info(*args, &task)
30
+ record_one_broadcast_with_new_relic(*args) do
31
+ info_without_new_relic(*args, &traced_task)
32
+ end
33
+ end
34
+
35
+ alias_method(:warn_without_new_relic, :warn)
36
+
37
+ def warn(*args, &task)
38
+ record_one_broadcast_with_new_relic(*args) do
39
+ warn_without_new_relic(*args, &traced_task)
40
+ end
41
+ end
42
+
43
+ alias_method(:error_without_new_relic, :error)
44
+
45
+ def error(*args, &task)
46
+ record_one_broadcast_with_new_relic(*args) do
47
+ error_without_new_relic(*args, &traced_task)
48
+ end
49
+ end
50
+
51
+ alias_method(:fatal_without_new_relic, :fatal)
52
+
53
+ def fatal(*args, &task)
54
+ record_one_broadcast_with_new_relic(*args) do
55
+ fatal_without_new_relic(*args, &traced_task)
56
+ end
57
+ end
58
+ end
59
+
60
+ alias_method(:unknown_without_new_relic, :unknown)
61
+
62
+ def unknown(*args, &task)
63
+ record_one_broadcast_with_new_relic(*args) do
64
+ unknown_without_new_relic(*args, &traced_task)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,13 @@
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::Agent::Instrumentation
6
+ module ActiveSupportBroadcastLogger
7
+ def record_one_broadcast_with_new_relic(*args)
8
+ broadcasts[1..-1].each { |broadcasted_logger| broadcasted_logger.instance_variable_set(:@skip_instrumenting, true) }
9
+ yield
10
+ broadcasts.each { |broadcasted_logger| broadcasted_logger.instance_variable_set(:@skip_instrumenting, false) }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
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::Agent::Instrumentation
6
+ module ActiveSupportBroadcastLogger::Prepend
7
+ include NewRelic::Agent::Instrumentation::ActiveSupportBroadcastLogger
8
+
9
+ def add(*args)
10
+ record_one_broadcast_with_new_relic(*args) { super }
11
+ end
12
+
13
+ def debug(*args)
14
+ record_one_broadcast_with_new_relic(*args) { super }
15
+ end
16
+
17
+ def info(*args)
18
+ record_one_broadcast_with_new_relic(*args) { super }
19
+ end
20
+
21
+ def warn(*args)
22
+ record_one_broadcast_with_new_relic(*args) { super }
23
+ end
24
+
25
+ def error(*args)
26
+ record_one_broadcast_with_new_relic(*args) { super }
27
+ end
28
+
29
+ def fatal(*args)
30
+ record_one_broadcast_with_new_relic(*args) { super }
31
+ end
32
+
33
+ def unknown(*args)
34
+ record_one_broadcast_with_new_relic(*args) { super }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
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_relative 'active_support_broadcast_logger/instrumentation'
6
+ require_relative 'active_support_broadcast_logger/chain'
7
+ require_relative 'active_support_broadcast_logger/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :'active_support_broadcast_logger'
11
+
12
+ depends_on { defined?(ActiveSupport::BroadcastLogger) }
13
+
14
+ executes do
15
+ NewRelic::Agent.logger.info('Installing ActiveSupport::BroadcastLogger instrumentation')
16
+
17
+ if use_prepend?
18
+ prepend_instrument ActiveSupport::BroadcastLogger, NewRelic::Agent::Instrumentation::ActiveSupportBroadcastLogger::Prepend
19
+ else
20
+ chain_instrument NewRelic::Agent::Instrumentation::ActiveSupportBroadcastLogger::Chain
21
+ end
22
+ end
23
+ end
@@ -6,8 +6,12 @@ module NewRelic
6
6
  module Agent
7
7
  module Instrumentation
8
8
  module ActiveSupportLogger
9
+ INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)
10
+
9
11
  # Mark @skip_instrumenting on any broadcasted loggers to instrument Rails.logger only
10
12
  def broadcast_with_tracing(logger)
13
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
14
+
11
15
  NewRelic::Agent::Instrumentation::Logger.mark_skip_instrumenting(logger)
12
16
  yield
13
17
  rescue => error
@@ -9,7 +9,9 @@ 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 do
13
+ defined?(ActiveSupport::Logger) && defined?(ActiveSupport::Logger.broadcast)
14
+ end
13
15
 
14
16
  executes do
15
17
  NewRelic::Agent.logger.info('Installing ActiveSupport::Logger instrumentation')
@@ -0,0 +1,23 @@
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_relative 'instrumentation'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module AsyncHttp::Chain
9
+ def self.instrument!
10
+ ::Async::HTTP::Internet.class_eval do
11
+ include NewRelic::Agent::Instrumentation::AsyncHttp
12
+
13
+ alias_method(:call_without_new_relic, :call)
14
+
15
+ def call(method, url, headers = nil, body = nil)
16
+ call_with_new_relic(method, url, headers, body) do |hdr|
17
+ call_without_new_relic(method, url, hdr, body)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
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/http_clients/async_http_wrappers'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module AsyncHttp
9
+ def call_with_new_relic(method, url, headers = nil, body = nil)
10
+ headers ||= {} # if it is nil, we need to make it a hash so we can insert headers
11
+ wrapped_request = NewRelic::Agent::HTTPClients::AsyncHTTPRequest.new(self, method, url, headers)
12
+
13
+ segment = NewRelic::Agent::Tracer.start_external_request_segment(
14
+ library: wrapped_request.type,
15
+ uri: wrapped_request.uri,
16
+ procedure: wrapped_request.method
17
+ )
18
+
19
+ begin
20
+ response = nil
21
+ segment.add_request_headers(wrapped_request)
22
+
23
+ NewRelic::Agent.disable_all_tracing do
24
+ response = NewRelic::Agent::Tracer.capture_segment_error(segment) do
25
+ yield(headers)
26
+ end
27
+ end
28
+
29
+ wrapped_response = NewRelic::Agent::HTTPClients::AsyncHTTPResponse.new(response)
30
+ segment.process_response_headers(wrapped_response)
31
+ response
32
+ ensure
33
+ segment&.finish
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
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_relative 'instrumentation'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module AsyncHttp::Prepend
9
+ include NewRelic::Agent::Instrumentation::AsyncHttp
10
+
11
+ def call(method, url, headers = nil, body = nil)
12
+ call_with_new_relic(method, url, headers, body) { |hdr| super(method, url, hdr, body) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
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_relative 'async_http/instrumentation'
6
+ require_relative 'async_http/chain'
7
+ require_relative 'async_http/prepend'
8
+
9
+ DependencyDetection.defer do
10
+ named :async_http
11
+
12
+ depends_on do
13
+ defined?(Async::HTTP) && Gem::Version.new(Async::HTTP::VERSION) >= Gem::Version.new('0.59.0')
14
+ end
15
+
16
+ executes do
17
+ NewRelic::Agent.logger.info('Installing async_http instrumentation')
18
+
19
+ require 'async/http/internet'
20
+ if use_prepend?
21
+ prepend_instrument Async::HTTP::Internet, NewRelic::Agent::Instrumentation::AsyncHttp::Prepend
22
+ else
23
+ chain_instrument NewRelic::Agent::Instrumentation::AsyncHttp::Chain
24
+ end
25
+ end
26
+ end
@@ -12,6 +12,7 @@ module NewRelic
12
12
  DEFAULT_NAME = 'Default'
13
13
  DEFAULT_TYPE = :direct
14
14
  SLASH = '/'
15
+ INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)
15
16
 
16
17
  def exchange_name(name)
17
18
  name.empty? ? DEFAULT_NAME : name
@@ -28,6 +29,8 @@ module NewRelic
28
29
  include Bunny
29
30
 
30
31
  def publish_with_tracing(payload, opts = {})
32
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
33
+
31
34
  begin
32
35
  destination = exchange_name(name)
33
36
 
@@ -62,6 +65,8 @@ module NewRelic
62
65
  include Bunny
63
66
 
64
67
  def pop_with_tracing
68
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
69
+
65
70
  bunny_error, delivery_info, message_properties, _payload = nil, nil, nil, nil
66
71
  begin
67
72
  t0 = Process.clock_gettime(Process::CLOCK_REALTIME)
@@ -104,6 +109,8 @@ module NewRelic
104
109
  end
105
110
 
106
111
  def purge_with_tracing
112
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
113
+
107
114
  begin
108
115
  type = server_named? ? :temporary_queue : :queue
109
116
  segment = NewRelic::Agent::Tracer.start_message_broker_segment(
@@ -129,6 +136,8 @@ module NewRelic
129
136
  include Bunny
130
137
 
131
138
  def call_with_tracing(*args)
139
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
140
+
132
141
  delivery_info, message_properties, _ = args
133
142
  queue_name = queue.respond_to?(:name) ? queue.name : queue
134
143
 
@@ -5,10 +5,10 @@
5
5
  module NewRelic::Agent::Instrumentation
6
6
  module ConcurrentRuby
7
7
  SEGMENT_NAME = 'Concurrent/Task'
8
- SUPPORTABILITY_METRIC = 'Supportability/ConcurrentRuby/Invoked'
8
+ INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)
9
9
 
10
10
  def add_task_tracing(&task)
11
- NewRelic::Agent.record_metric_once(SUPPORTABILITY_METRIC)
11
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
12
12
 
13
13
  NewRelic::Agent::Tracer.thread_block_with_current_transaction(
14
14
  segment_name: SEGMENT_NAME,
@@ -68,6 +68,8 @@ module NewRelic
68
68
  module Multi
69
69
  include NewRelic::Agent::MethodTracer
70
70
 
71
+ INSTRUMENTATION_NAME = 'Curb'
72
+
71
73
  # Add CAT with callbacks if the request is serial
72
74
  def add_with_tracing(curl)
73
75
  if curl.respond_to?(:_nr_serial) && curl._nr_serial
@@ -81,6 +83,8 @@ module NewRelic
81
83
  def perform_with_tracing
82
84
  return yield if first_request_is_serial?
83
85
 
86
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
87
+
84
88
  trace_execution_scoped('External/Multiple/Curb::Multi/perform') do
85
89
  yield
86
90
  end
@@ -31,8 +31,11 @@ module NewRelic
31
31
  include NewRelic::Agent::Instrumentation::ControllerInstrumentation
32
32
 
33
33
  NR_TRANSACTION_CATEGORY = 'OtherTransaction/DelayedJob'.freeze
34
+ INSTRUMENTATION_NAME = 'DelayedJob'
34
35
 
35
36
  def invoke_job_with_tracing
37
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
38
+
36
39
  options = {
37
40
  :category => NR_TRANSACTION_CATEGORY,
38
41
  :path => ::NewRelic::Agent::Instrumentation::DelayedJob::Naming.name_from_payload(payload_object)
@@ -8,15 +8,18 @@ module NewRelic::Agent::Instrumentation
8
8
  module Elasticsearch
9
9
  PRODUCT_NAME = 'Elasticsearch'
10
10
  OPERATION = 'perform_request'
11
+ INSTRUMENTATION_NAME = NewRelic::Agent.base_name(name)
11
12
 
12
13
  def perform_request_with_tracing(method, path, params = {}, body = nil, headers = nil)
13
14
  return yield unless NewRelic::Agent::Tracer.tracing_enabled?
14
15
 
16
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
17
+
15
18
  segment = NewRelic::Agent::Tracer.start_datastore_segment(
16
19
  product: PRODUCT_NAME,
17
20
  operation: nr_operation || OPERATION,
18
21
  host: nr_hosts[:host],
19
- port_path_or_id: path,
22
+ port_path_or_id: nr_hosts[:port],
20
23
  database_name: nr_cluster_name
21
24
  )
22
25
  begin
@@ -0,0 +1,39 @@
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::Agent::Instrumentation
6
+ module Ethon
7
+ module Chain
8
+ def self.instrument!
9
+ ::Ethon::Easy.class_eval do
10
+ include NewRelic::Agent::Instrumentation::Ethon::Easy
11
+
12
+ alias_method(:fabricate_without_tracing, :fabricate)
13
+ def fabricate(url, action_name, options)
14
+ fabricate_with_tracing(url, action_name, options) { fabricate_without_tracing(url, action_name, options) }
15
+ end
16
+
17
+ alias_method(:headers_equals_without_tracing, :headers=)
18
+ def headers=(headers)
19
+ headers_equals_with_tracing(headers) { headers_equals_without_tracing(headers) }
20
+ end
21
+
22
+ alias_method(:perform_without_tracing, :perform)
23
+ def perform(*args)
24
+ perform_with_tracing(*args) { perform_without_tracing(*args) }
25
+ end
26
+ end
27
+
28
+ ::Ethon::Multi.class_eval do
29
+ include NewRelic::Agent::Instrumentation::Ethon::Multi
30
+
31
+ alias_method(:perform_without_tracing, :perform)
32
+ def perform(*args)
33
+ perform_with_tracing(*args) { perform_without_tracing(*args) }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,105 @@
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/http_clients/ethon_wrappers'
6
+
7
+ module NewRelic::Agent::Instrumentation
8
+ module Ethon
9
+ module NRShared
10
+ INSTRUMENTATION_NAME = 'Ethon'
11
+ NOTICEABLE_ERROR_CLASS = 'Ethon::Errors::EthonError'
12
+
13
+ def prep_easy(easy, parent = nil)
14
+ wrapped_request = NewRelic::Agent::HTTPClients::EthonHTTPRequest.new(easy)
15
+ segment = NewRelic::Agent::Tracer.start_external_request_segment(
16
+ library: wrapped_request.type,
17
+ uri: wrapped_request.uri,
18
+ procedure: wrapped_request.method,
19
+ parent: parent
20
+ )
21
+ segment.add_request_headers(wrapped_request)
22
+
23
+ callback = proc do
24
+ wrapped_response = NewRelic::Agent::HTTPClients::EthonHTTPResponse.new(easy)
25
+ segment.process_response_headers(wrapped_response)
26
+
27
+ if easy.return_code != :ok
28
+ e = NewRelic::Agent::NoticeableError.new(NOTICEABLE_ERROR_CLASS,
29
+ "return_code: >>#{easy.return_code}<<, response_code: >>#{easy.response_code}<<")
30
+ segment.notice_error(e)
31
+ end
32
+
33
+ ::NewRelic::Agent::Transaction::Segment.finish(segment)
34
+ end
35
+
36
+ easy.on_complete { callback.call }
37
+
38
+ segment
39
+ end
40
+
41
+ def wrap_with_tracing(segment, &block)
42
+ NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
43
+
44
+ NewRelic::Agent::Tracer.capture_segment_error(segment) do
45
+ yield
46
+ end
47
+ ensure
48
+ NewRelic::Agent::Transaction::Segment.finish(segment)
49
+ end
50
+ end
51
+
52
+ module Easy
53
+ include NRShared
54
+
55
+ ACTION_INSTANCE_VAR = :@nr_action
56
+ HEADERS_INSTANCE_VAR = :@nr_headers
57
+
58
+ # `Ethon::Easy` doesn't expose the "action name" ('GET', 'POST', etc.)
59
+ # and Ethon's fabrication of HTTP classes uses
60
+ # `Ethon::Easy::Http::Custom` for non-standard actions. To be able to
61
+ # know the action name at `#perform` time, we set a new instance variable
62
+ # on the `Ethon::Easy` instance with the base name of the fabricated
63
+ # class, respecting the 'Custom' name where appropriate.
64
+ def fabricate_with_tracing(_url, action_name, _options)
65
+ fabbed = yield
66
+ instance_variable_set(ACTION_INSTANCE_VAR, NewRelic::Agent.base_name(fabbed.class.name).upcase)
67
+ fabbed
68
+ end
69
+
70
+ # `Ethon::Easy` uses `Ethon::Easy::Header` to set request headers on
71
+ # libcurl with `#headers=`. After they are set, they aren't easy to get
72
+ # at again except via FFI so set a new instance variable on the
73
+ # `Ethon::Easy` instance to store them in Ruby hash format.
74
+ def headers_equals_with_tracing(headers)
75
+ instance_variable_set(HEADERS_INSTANCE_VAR, headers)
76
+ yield
77
+ end
78
+
79
+ def perform_with_tracing(*args)
80
+ return unless NewRelic::Agent::Tracer.state.is_execution_traced?
81
+
82
+ segment = prep_easy(self)
83
+ wrap_with_tracing(segment) { yield }
84
+ end
85
+ end
86
+
87
+ module Multi
88
+ include NRShared
89
+
90
+ MULTI_SEGMENT_NAME = 'External/Multiple/Ethon::Multi/perform'
91
+
92
+ def perform_with_tracing(*args)
93
+ return unless NewRelic::Agent::Tracer.state.is_execution_traced?
94
+
95
+ segment = NewRelic::Agent::Tracer.start_segment(name: MULTI_SEGMENT_NAME)
96
+
97
+ wrap_with_tracing(segment) do
98
+ easy_handles.each { |easy| prep_easy(easy, segment) }
99
+
100
+ yield
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,35 @@
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::Agent::Instrumentation
6
+ module Ethon
7
+ module Easy
8
+ module Prepend
9
+ include NewRelic::Agent::Instrumentation::Ethon::Easy
10
+
11
+ def fabricate(url, action_name, options)
12
+ fabricate_with_tracing(url, action_name, options) { super }
13
+ end
14
+
15
+ def headers=(headers)
16
+ headers_equals_with_tracing(headers) { super }
17
+ end
18
+
19
+ def perform(*args)
20
+ perform_with_tracing(*args) { super }
21
+ end
22
+ end
23
+ end
24
+
25
+ module Multi
26
+ module Prepend
27
+ include NewRelic::Agent::Instrumentation::Ethon::Multi
28
+
29
+ def perform(*args)
30
+ perform_with_tracing(*args) { super }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end