newrelic_rpm 9.5.0 → 9.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +154 -7
  3. data/CONTRIBUTING.md +0 -7
  4. data/README.md +1 -1
  5. data/Rakefile +1 -1
  6. data/bin/newrelic +2 -9
  7. data/bin/newrelic_rpm +15 -0
  8. data/init.rb +2 -2
  9. data/lib/new_relic/agent/agent.rb +1 -1
  10. data/lib/new_relic/agent/agent_helpers/shutdown.rb +1 -1
  11. data/lib/new_relic/agent/agent_helpers/special_startup.rb +1 -1
  12. data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +2 -2
  13. data/lib/new_relic/agent/agent_helpers/startup.rb +2 -2
  14. data/lib/new_relic/agent/attribute_filter.rb +3 -3
  15. data/lib/new_relic/agent/configuration/default_source.rb +131 -36
  16. data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
  17. data/lib/new_relic/agent/configuration/manager.rb +13 -9
  18. data/lib/new_relic/agent/configuration/security_policy_source.rb +11 -0
  19. data/lib/new_relic/agent/custom_event_aggregator.rb +27 -1
  20. data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
  21. data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +3 -3
  22. data/lib/new_relic/agent/error_collector.rb +2 -0
  23. data/lib/new_relic/agent/event_loop.rb +1 -1
  24. data/lib/new_relic/agent/http_clients/abstract.rb +4 -0
  25. data/lib/new_relic/agent/http_clients/async_http_wrappers.rb +80 -0
  26. data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -3
  27. data/lib/new_relic/agent/http_clients/ethon_wrappers.rb +109 -0
  28. data/lib/new_relic/agent/http_clients/excon_wrappers.rb +0 -3
  29. data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +1 -3
  30. data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +0 -3
  31. data/lib/new_relic/agent/http_clients/httpx_wrappers.rb +91 -0
  32. data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +1 -4
  33. data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +0 -3
  34. data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
  35. data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -2
  36. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/chain.rb +69 -0
  37. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/instrumentation.rb +17 -0
  38. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/prepend.rb +37 -0
  39. data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger.rb +23 -0
  40. data/lib/new_relic/agent/instrumentation/active_support_logger.rb +3 -1
  41. data/lib/new_relic/agent/instrumentation/async_http/chain.rb +23 -0
  42. data/lib/new_relic/agent/instrumentation/async_http/instrumentation.rb +37 -0
  43. data/lib/new_relic/agent/instrumentation/async_http/prepend.rb +15 -0
  44. data/lib/new_relic/agent/instrumentation/async_http.rb +28 -0
  45. data/lib/new_relic/agent/instrumentation/concurrent_ruby.rb +1 -0
  46. data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +1 -1
  47. data/lib/new_relic/agent/instrumentation/ethon/chain.rb +39 -0
  48. data/lib/new_relic/agent/instrumentation/ethon/instrumentation.rb +105 -0
  49. data/lib/new_relic/agent/instrumentation/ethon/prepend.rb +35 -0
  50. data/lib/new_relic/agent/instrumentation/ethon.rb +39 -0
  51. data/lib/new_relic/agent/instrumentation/fiber/instrumentation.rb +1 -4
  52. data/lib/new_relic/agent/instrumentation/grpc_server.rb +1 -1
  53. data/lib/new_relic/agent/instrumentation/httpx/chain.rb +20 -0
  54. data/lib/new_relic/agent/instrumentation/httpx/instrumentation.rb +51 -0
  55. data/lib/new_relic/agent/instrumentation/httpx/prepend.rb +15 -0
  56. data/lib/new_relic/agent/instrumentation/httpx.rb +27 -0
  57. data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +1 -3
  58. data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +7 -1
  59. data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +1 -0
  60. data/lib/new_relic/agent/instrumentation/roda/ignorer.rb +45 -0
  61. data/lib/new_relic/agent/instrumentation/roda/instrumentation.rb +12 -0
  62. data/lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb +1 -2
  63. data/lib/new_relic/agent/instrumentation/roda.rb +2 -0
  64. data/lib/new_relic/agent/instrumentation/ruby_openai/chain.rb +36 -0
  65. data/lib/new_relic/agent/instrumentation/ruby_openai/instrumentation.rb +197 -0
  66. data/lib/new_relic/agent/instrumentation/ruby_openai/prepend.rb +20 -0
  67. data/lib/new_relic/agent/instrumentation/ruby_openai.rb +35 -0
  68. data/lib/new_relic/agent/instrumentation/sidekiq.rb +3 -1
  69. data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
  70. data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -3
  71. data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
  72. data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -4
  73. data/lib/new_relic/agent/instrumentation/view_component/chain.rb +21 -0
  74. data/lib/new_relic/agent/instrumentation/view_component/instrumentation.rb +39 -0
  75. data/lib/new_relic/agent/instrumentation/view_component/prepend.rb +13 -0
  76. data/lib/new_relic/agent/instrumentation/view_component.rb +26 -0
  77. data/lib/new_relic/agent/javascript_instrumentor.rb +0 -1
  78. data/lib/new_relic/agent/llm/chat_completion_message.rb +25 -0
  79. data/lib/new_relic/agent/llm/chat_completion_summary.rb +66 -0
  80. data/lib/new_relic/agent/llm/embedding.rb +60 -0
  81. data/lib/new_relic/agent/llm/llm_event.rb +95 -0
  82. data/lib/new_relic/agent/llm/response_headers.rb +80 -0
  83. data/lib/new_relic/agent/llm.rb +49 -0
  84. data/lib/new_relic/agent/messaging.rb +2 -2
  85. data/lib/new_relic/agent/monitors/synthetics_monitor.rb +12 -1
  86. data/lib/new_relic/agent/new_relic_service/encoders.rb +2 -2
  87. data/lib/new_relic/agent/new_relic_service.rb +8 -6
  88. data/lib/new_relic/agent/obfuscator.rb +0 -2
  89. data/lib/new_relic/agent/pipe_channel_manager.rb +2 -2
  90. data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -2
  91. data/lib/new_relic/agent/rules_engine.rb +1 -1
  92. data/lib/new_relic/agent/span_event_primitive.rb +16 -4
  93. data/lib/new_relic/agent/sql_sampler.rb +0 -1
  94. data/lib/new_relic/agent/system_info.rb +26 -0
  95. data/lib/new_relic/agent/threading/agent_thread.rb +1 -2
  96. data/lib/new_relic/agent/tracer.rb +9 -10
  97. data/lib/new_relic/agent/transaction/abstract_segment.rb +4 -1
  98. data/lib/new_relic/agent/transaction/external_request_segment.rb +5 -2
  99. data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -2
  100. data/lib/new_relic/agent/transaction/request_attributes.rb +1 -3
  101. data/lib/new_relic/agent/transaction/tracing.rb +11 -1
  102. data/lib/new_relic/agent/transaction.rb +25 -2
  103. data/lib/new_relic/agent/transaction_error_primitive.rb +16 -0
  104. data/lib/new_relic/agent/transaction_event_primitive.rb +19 -0
  105. data/lib/new_relic/agent/utilization/gcp.rb +1 -3
  106. data/lib/new_relic/agent/vm/{mri_vm.rb → c_ruby_vm.rb} +7 -15
  107. data/lib/new_relic/agent/vm.rb +2 -2
  108. data/lib/new_relic/agent/worker_loop.rb +1 -1
  109. data/lib/new_relic/agent.rb +102 -7
  110. data/lib/new_relic/base64.rb +25 -0
  111. data/lib/new_relic/cli/command.rb +6 -4
  112. data/lib/new_relic/constants.rb +5 -0
  113. data/lib/new_relic/control/frameworks/rails.rb +17 -5
  114. data/lib/new_relic/control/instrumentation.rb +1 -1
  115. data/lib/new_relic/language_support.rb +4 -0
  116. data/lib/new_relic/local_environment.rb +22 -13
  117. data/lib/new_relic/rack/browser_monitoring.rb +8 -4
  118. data/lib/new_relic/supportability_helper.rb +3 -1
  119. data/lib/new_relic/thread_local_storage.rb +31 -0
  120. data/lib/new_relic/version.rb +1 -1
  121. data/lib/tasks/config.rake +1 -1
  122. data/lib/tasks/helpers/config.html.erb +6 -6
  123. data/lib/tasks/helpers/newrelicyml.rb +1 -1
  124. data/lib/tasks/instrumentation_generator/instrumentation.thor +3 -3
  125. data/lib/tasks/instrumentation_generator/templates/chain.tt +0 -1
  126. data/lib/tasks/instrumentation_generator/templates/chain_method.tt +0 -1
  127. data/lib/tasks/tests.rake +71 -0
  128. data/newrelic.yml +76 -36
  129. data/newrelic_rpm.gemspec +5 -4
  130. data/test/agent_helper.rb +14 -2
  131. metadata +43 -7
  132. data/bin/newrelic_cmd +0 -7
@@ -0,0 +1,80 @@
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
+ require 'resolv'
7
+
8
+ module NewRelic
9
+ module Agent
10
+ module HTTPClients
11
+ class AsyncHTTPResponse < AbstractResponse
12
+ def get_status_code
13
+ get_status_code_using(:status)
14
+ end
15
+
16
+ def [](key)
17
+ to_hash[key.downcase]&.first
18
+ end
19
+
20
+ def to_hash
21
+ @wrapped_response.headers.to_h
22
+ end
23
+ end
24
+
25
+ class AsyncHTTPRequest < AbstractRequest
26
+ def initialize(connection, method, url, headers)
27
+ @connection = connection
28
+ @method = method
29
+ @url = ::NewRelic::Agent::HTTPClients::URIUtil.parse_and_normalize_url(url)
30
+ @headers = headers
31
+ end
32
+
33
+ ASYNC_HTTP = 'Async::HTTP'
34
+
35
+ def type
36
+ ASYNC_HTTP
37
+ end
38
+
39
+ def host_from_header
40
+ if hostname = (self[LHOST] || self[UHOST])
41
+ hostname.split(COLON).first
42
+ end
43
+ end
44
+
45
+ def host
46
+ host_from_header || uri.host.to_s
47
+ end
48
+
49
+ def [](key)
50
+ return headers[key] unless headers.is_a?(Array)
51
+
52
+ headers.each do |header|
53
+ return header[1] if header[0].casecmp?(key)
54
+ end
55
+ nil
56
+ end
57
+
58
+ def []=(key, value)
59
+ if headers.is_a?(Array)
60
+ headers << [key, value]
61
+ else
62
+ headers[key] = value
63
+ end
64
+ end
65
+
66
+ def uri
67
+ @url
68
+ end
69
+
70
+ def headers
71
+ @headers
72
+ end
73
+
74
+ def method
75
+ @method
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -7,10 +7,8 @@ require_relative 'abstract'
7
7
  module NewRelic
8
8
  module Agent
9
9
  module HTTPClients
10
- class CurbRequest
10
+ class CurbRequest < AbstractRequest
11
11
  CURB = 'Curb'
12
- LHOST = 'host'
13
- UHOST = 'Host'
14
12
 
15
13
  def initialize(curlobj)
16
14
  @curlobj = curlobj
@@ -0,0 +1,109 @@
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 'uri'
6
+ require_relative 'abstract'
7
+
8
+ module NewRelic
9
+ module Agent
10
+ module HTTPClients
11
+ class EthonHTTPResponse < AbstractResponse
12
+ def initialize(easy)
13
+ @easy = easy
14
+ end
15
+
16
+ def status_code
17
+ @easy.response_code
18
+ end
19
+
20
+ def [](key)
21
+ headers[format_key(key)]
22
+ end
23
+
24
+ def headers
25
+ # Ethon::Easy#response_headers will return '' if headers are unset
26
+ @easy.response_headers.scan(/\n([^:]+?): ([^:\n]+?)\r/).each_with_object({}) do |pair, hash|
27
+ hash[format_key(pair[0])] = pair[1]
28
+ end
29
+ end
30
+ alias to_hash headers
31
+
32
+ private
33
+
34
+ def format_key(key)
35
+ key.tr('-', '_').downcase
36
+ end
37
+ end
38
+
39
+ class EthonHTTPRequest < AbstractRequest
40
+ attr_reader :uri
41
+
42
+ DEFAULT_ACTION = 'GET'
43
+ DEFAULT_HOST = 'UNKNOWN_HOST'
44
+ ETHON = 'Ethon'
45
+
46
+ def initialize(easy)
47
+ @easy = easy
48
+ @uri = uri_from_easy
49
+ end
50
+
51
+ def type
52
+ ETHON
53
+ end
54
+
55
+ def host_from_header
56
+ self[LHOST] || self[UHOST]
57
+ end
58
+
59
+ def uri_from_easy
60
+ # anticipate `Ethon::Easy#url` being `example.com` without a protocol
61
+ # defined and use an 'http' protocol prefix for `URI.parse` to work
62
+ # with the URL as desired
63
+ url_str = @easy.url.match?(':') ? @easy.url : "http://#{@easy.url}"
64
+ begin
65
+ URI.parse(url_str)
66
+ rescue URI::InvalidURIError => e
67
+ NewRelic::Agent.logger.debug("Failed to parse URI '#{url_str}': #{e.class} - #{e.message}")
68
+ URI.parse(NewRelic::EMPTY_STR)
69
+ end
70
+ end
71
+
72
+ def host
73
+ host_from_header || uri.host&.downcase || DEFAULT_HOST
74
+ end
75
+
76
+ def method
77
+ return DEFAULT_ACTION unless @easy.instance_variable_defined?(action_instance_var)
78
+
79
+ @easy.instance_variable_get(action_instance_var)
80
+ end
81
+
82
+ def action_instance_var
83
+ NewRelic::Agent::Instrumentation::Ethon::Easy::ACTION_INSTANCE_VAR
84
+ end
85
+
86
+ def []=(key, value)
87
+ headers[key] = value
88
+ @easy.headers = headers
89
+ end
90
+
91
+ def headers
92
+ @headers ||= if @easy.instance_variable_defined?(headers_instance_var)
93
+ @easy.instance_variable_get(headers_instance_var)
94
+ else
95
+ {}
96
+ end
97
+ end
98
+
99
+ def headers_instance_var
100
+ NewRelic::Agent::Instrumentation::Ethon::Easy::HEADERS_INSTANCE_VAR
101
+ end
102
+
103
+ def [](key)
104
+ headers[key]
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -47,9 +47,6 @@ module NewRelic
47
47
  attr_reader :method
48
48
 
49
49
  EXCON = 'Excon'
50
- LHOST = 'host'
51
- UHOST = 'Host'
52
- COLON = ':'
53
50
 
54
51
  def initialize(datum)
55
52
  @datum = datum
@@ -20,8 +20,6 @@ module NewRelic
20
20
 
21
21
  class HTTPRequest < AbstractRequest
22
22
  HTTP_RB = 'http.rb'
23
- HOST = 'host'
24
- COLON = ':'
25
23
 
26
24
  def initialize(wrapped_request)
27
25
  @wrapped_request = wrapped_request
@@ -36,7 +34,7 @@ module NewRelic
36
34
  end
37
35
 
38
36
  def host_from_header
39
- if hostname = self[HOST]
37
+ if hostname = self[LHOST]
40
38
  hostname.split(COLON).first
41
39
  end
42
40
  end
@@ -26,9 +26,6 @@ module NewRelic
26
26
  attr_reader :request
27
27
 
28
28
  HTTP_CLIENT = 'HTTPClient'.freeze
29
- LHOST = 'host'.freeze
30
- UHOST = 'Host'.freeze
31
- COLON = ':'.freeze
32
29
 
33
30
  def initialize(request)
34
31
  @request = request
@@ -0,0 +1,91 @@
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
+
56
+ def initialize(request)
57
+ @request = request
58
+ @uri = request.uri
59
+ end
60
+
61
+ def type
62
+ TYPE
63
+ end
64
+
65
+ def host_from_header
66
+ self[LHOST] || self[UHOST]
67
+ end
68
+
69
+ def host
70
+ host_from_header || uri.host&.downcase || DEFAULT_HOST
71
+ end
72
+
73
+ def method
74
+ @request.verb
75
+ end
76
+
77
+ def []=(key, value)
78
+ @request.headers[key] = value
79
+ end
80
+
81
+ def headers
82
+ @request.headers
83
+ end
84
+
85
+ def [](key)
86
+ @request.headers[key]
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -30,11 +30,8 @@ module NewRelic
30
30
  NET_HTTP
31
31
  end
32
32
 
33
- HOST = 'host'
34
- COLON = ':'
35
-
36
33
  def host_from_header
37
- if hostname = self[HOST]
34
+ if hostname = self[LHOST]
38
35
  hostname.split(COLON).first
39
36
  end
40
37
  end
@@ -48,9 +48,6 @@ module NewRelic
48
48
  TYPHOEUS
49
49
  end
50
50
 
51
- LHOST = 'host'.freeze
52
- UHOST = 'Host'.freeze
53
-
54
51
  def host_from_header
55
52
  self[LHOST] || self[UHOST]
56
53
  end
@@ -39,7 +39,7 @@ DependencyDetection.defer do
39
39
  executes do
40
40
  next unless Gem::Version.new(ActiveMerchant::VERSION) < Gem::Version.new('1.65.0')
41
41
 
42
- deprecation_msg = 'The Ruby Agent is dropping support for ActiveMerchant versions below 1.65.0 ' \
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
45
  NewRelic::Agent.logger.log_once(
@@ -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,17 @@
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
+ if broadcasts && broadcasts[1..-1]
9
+ broadcasts[1..-1].each { |broadcasted_logger| broadcasted_logger.instance_variable_set(:@skip_instrumenting, true) }
10
+ yield
11
+ broadcasts.each { |broadcasted_logger| broadcasted_logger.instance_variable_set(:@skip_instrumenting, false) }
12
+ else
13
+ NewRelic::Agent.logger.error('Error recording broadcasted logger')
14
+ end
15
+ end
16
+ end
17
+ 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
@@ -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,28 @@
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) &&
14
+ Gem::Version.new(Async::HTTP::VERSION) >= Gem::Version.new('0.59.0') &&
15
+ !defined?(Traces::Backend::NewRelic) # defined in the traces-backend-newrelic gem
16
+ end
17
+
18
+ executes do
19
+ NewRelic::Agent.logger.info('Installing async_http instrumentation')
20
+
21
+ require 'async/http/internet'
22
+ if use_prepend?
23
+ prepend_instrument Async::HTTP::Internet, NewRelic::Agent::Instrumentation::AsyncHttp::Prepend
24
+ else
25
+ chain_instrument NewRelic::Agent::Instrumentation::AsyncHttp::Chain
26
+ end
27
+ end
28
+ end
@@ -11,6 +11,7 @@ DependencyDetection.defer do
11
11
 
12
12
  depends_on do
13
13
  defined?(Concurrent) &&
14
+ defined?(Concurrent::VERSION) &&
14
15
  Gem::Version.new(Concurrent::VERSION) >= Gem::Version.new('1.1.5')
15
16
  end
16
17
 
@@ -56,7 +56,7 @@ module NewRelic::Agent::Instrumentation
56
56
  return if nr_hosts.empty?
57
57
 
58
58
  NewRelic::Agent.disable_all_tracing do
59
- @nr_cluster_name ||= perform_request('GET', '_cluster/health').body['cluster_name']
59
+ @nr_cluster_name ||= perform_request('GET', '/').body['cluster_name']
60
60
  end
61
61
  rescue StandardError => e
62
62
  NewRelic::Agent.logger.error('Failed to get cluster name for elasticsearch', e)