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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +154 -7
- data/CONTRIBUTING.md +0 -7
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/bin/newrelic +2 -9
- data/bin/newrelic_rpm +15 -0
- data/init.rb +2 -2
- data/lib/new_relic/agent/agent.rb +1 -1
- data/lib/new_relic/agent/agent_helpers/shutdown.rb +1 -1
- data/lib/new_relic/agent/agent_helpers/special_startup.rb +1 -1
- data/lib/new_relic/agent/agent_helpers/start_worker_thread.rb +2 -2
- data/lib/new_relic/agent/agent_helpers/startup.rb +2 -2
- data/lib/new_relic/agent/attribute_filter.rb +3 -3
- data/lib/new_relic/agent/configuration/default_source.rb +131 -36
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
- data/lib/new_relic/agent/configuration/manager.rb +13 -9
- data/lib/new_relic/agent/configuration/security_policy_source.rb +11 -0
- data/lib/new_relic/agent/custom_event_aggregator.rb +27 -1
- data/lib/new_relic/agent/datastores/mongo/metric_translator.rb +1 -1
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_payload.rb +3 -3
- data/lib/new_relic/agent/error_collector.rb +2 -0
- data/lib/new_relic/agent/event_loop.rb +1 -1
- data/lib/new_relic/agent/http_clients/abstract.rb +4 -0
- data/lib/new_relic/agent/http_clients/async_http_wrappers.rb +80 -0
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +1 -3
- data/lib/new_relic/agent/http_clients/ethon_wrappers.rb +109 -0
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +0 -3
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +1 -3
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +0 -3
- data/lib/new_relic/agent/http_clients/httpx_wrappers.rb +91 -0
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +1 -4
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +0 -3
- data/lib/new_relic/agent/instrumentation/active_merchant.rb +1 -1
- data/lib/new_relic/agent/instrumentation/active_record_helper.rb +1 -2
- data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/chain.rb +69 -0
- data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/instrumentation.rb +17 -0
- data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger/prepend.rb +37 -0
- data/lib/new_relic/agent/instrumentation/active_support_broadcast_logger.rb +23 -0
- data/lib/new_relic/agent/instrumentation/active_support_logger.rb +3 -1
- data/lib/new_relic/agent/instrumentation/async_http/chain.rb +23 -0
- data/lib/new_relic/agent/instrumentation/async_http/instrumentation.rb +37 -0
- data/lib/new_relic/agent/instrumentation/async_http/prepend.rb +15 -0
- data/lib/new_relic/agent/instrumentation/async_http.rb +28 -0
- data/lib/new_relic/agent/instrumentation/concurrent_ruby.rb +1 -0
- data/lib/new_relic/agent/instrumentation/elasticsearch/instrumentation.rb +1 -1
- data/lib/new_relic/agent/instrumentation/ethon/chain.rb +39 -0
- data/lib/new_relic/agent/instrumentation/ethon/instrumentation.rb +105 -0
- data/lib/new_relic/agent/instrumentation/ethon/prepend.rb +35 -0
- data/lib/new_relic/agent/instrumentation/ethon.rb +39 -0
- data/lib/new_relic/agent/instrumentation/fiber/instrumentation.rb +1 -4
- data/lib/new_relic/agent/instrumentation/grpc_server.rb +1 -1
- data/lib/new_relic/agent/instrumentation/httpx/chain.rb +20 -0
- data/lib/new_relic/agent/instrumentation/httpx/instrumentation.rb +51 -0
- data/lib/new_relic/agent/instrumentation/httpx/prepend.rb +15 -0
- data/lib/new_relic/agent/instrumentation/httpx.rb +27 -0
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +1 -3
- data/lib/new_relic/agent/instrumentation/net_http/instrumentation.rb +7 -1
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_controller.rb +1 -0
- data/lib/new_relic/agent/instrumentation/roda/ignorer.rb +45 -0
- data/lib/new_relic/agent/instrumentation/roda/instrumentation.rb +12 -0
- data/lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb +1 -2
- data/lib/new_relic/agent/instrumentation/roda.rb +2 -0
- data/lib/new_relic/agent/instrumentation/ruby_openai/chain.rb +36 -0
- data/lib/new_relic/agent/instrumentation/ruby_openai/instrumentation.rb +197 -0
- data/lib/new_relic/agent/instrumentation/ruby_openai/prepend.rb +20 -0
- data/lib/new_relic/agent/instrumentation/ruby_openai.rb +35 -0
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +3 -1
- data/lib/new_relic/agent/instrumentation/sinatra/ignorer.rb +1 -1
- data/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +1 -3
- data/lib/new_relic/agent/instrumentation/sinatra.rb +1 -1
- data/lib/new_relic/agent/instrumentation/thread/instrumentation.rb +1 -4
- data/lib/new_relic/agent/instrumentation/view_component/chain.rb +21 -0
- data/lib/new_relic/agent/instrumentation/view_component/instrumentation.rb +39 -0
- data/lib/new_relic/agent/instrumentation/view_component/prepend.rb +13 -0
- data/lib/new_relic/agent/instrumentation/view_component.rb +26 -0
- data/lib/new_relic/agent/javascript_instrumentor.rb +0 -1
- data/lib/new_relic/agent/llm/chat_completion_message.rb +25 -0
- data/lib/new_relic/agent/llm/chat_completion_summary.rb +66 -0
- data/lib/new_relic/agent/llm/embedding.rb +60 -0
- data/lib/new_relic/agent/llm/llm_event.rb +95 -0
- data/lib/new_relic/agent/llm/response_headers.rb +80 -0
- data/lib/new_relic/agent/llm.rb +49 -0
- data/lib/new_relic/agent/messaging.rb +2 -2
- data/lib/new_relic/agent/monitors/synthetics_monitor.rb +12 -1
- data/lib/new_relic/agent/new_relic_service/encoders.rb +2 -2
- data/lib/new_relic/agent/new_relic_service.rb +8 -6
- data/lib/new_relic/agent/obfuscator.rb +0 -2
- data/lib/new_relic/agent/pipe_channel_manager.rb +2 -2
- data/lib/new_relic/agent/rules_engine/segment_terms_rule.rb +1 -2
- data/lib/new_relic/agent/rules_engine.rb +1 -1
- data/lib/new_relic/agent/span_event_primitive.rb +16 -4
- data/lib/new_relic/agent/sql_sampler.rb +0 -1
- data/lib/new_relic/agent/system_info.rb +26 -0
- data/lib/new_relic/agent/threading/agent_thread.rb +1 -2
- data/lib/new_relic/agent/tracer.rb +9 -10
- data/lib/new_relic/agent/transaction/abstract_segment.rb +4 -1
- data/lib/new_relic/agent/transaction/external_request_segment.rb +5 -2
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +1 -2
- data/lib/new_relic/agent/transaction/request_attributes.rb +1 -3
- data/lib/new_relic/agent/transaction/tracing.rb +11 -1
- data/lib/new_relic/agent/transaction.rb +25 -2
- data/lib/new_relic/agent/transaction_error_primitive.rb +16 -0
- data/lib/new_relic/agent/transaction_event_primitive.rb +19 -0
- data/lib/new_relic/agent/utilization/gcp.rb +1 -3
- data/lib/new_relic/agent/vm/{mri_vm.rb → c_ruby_vm.rb} +7 -15
- data/lib/new_relic/agent/vm.rb +2 -2
- data/lib/new_relic/agent/worker_loop.rb +1 -1
- data/lib/new_relic/agent.rb +102 -7
- data/lib/new_relic/base64.rb +25 -0
- data/lib/new_relic/cli/command.rb +6 -4
- data/lib/new_relic/constants.rb +5 -0
- data/lib/new_relic/control/frameworks/rails.rb +17 -5
- data/lib/new_relic/control/instrumentation.rb +1 -1
- data/lib/new_relic/language_support.rb +4 -0
- data/lib/new_relic/local_environment.rb +22 -13
- data/lib/new_relic/rack/browser_monitoring.rb +8 -4
- data/lib/new_relic/supportability_helper.rb +3 -1
- data/lib/new_relic/thread_local_storage.rb +31 -0
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/config.rake +1 -1
- data/lib/tasks/helpers/config.html.erb +6 -6
- data/lib/tasks/helpers/newrelicyml.rb +1 -1
- data/lib/tasks/instrumentation_generator/instrumentation.thor +3 -3
- data/lib/tasks/instrumentation_generator/templates/chain.tt +0 -1
- data/lib/tasks/instrumentation_generator/templates/chain_method.tt +0 -1
- data/lib/tasks/tests.rake +71 -0
- data/newrelic.yml +76 -36
- data/newrelic_rpm.gemspec +5 -4
- data/test/agent_helper.rb +14 -2
- metadata +43 -7
- data/bin/newrelic_cmd +0 -7
@@ -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
|
@@ -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
|
+
require_relative 'ethon/instrumentation'
|
6
|
+
require_relative 'ethon/chain'
|
7
|
+
require_relative 'ethon/prepend'
|
8
|
+
|
9
|
+
DependencyDetection.defer do
|
10
|
+
named :ethon
|
11
|
+
|
12
|
+
# If Ethon is being used as a dependency of Typhoeus, allow the Typhoeus
|
13
|
+
# instrumentation to handle everything. Otherwise each external network call
|
14
|
+
# will confusingly result in "Ethon" segments duplicating the information
|
15
|
+
# already provided by "Typhoeus" segments.
|
16
|
+
depends_on do
|
17
|
+
!defined?(Typhoeus)
|
18
|
+
end
|
19
|
+
|
20
|
+
depends_on do
|
21
|
+
defined?(Ethon) && Gem::Version.new(Ethon::VERSION) >= Gem::Version.new('0.12.0')
|
22
|
+
end
|
23
|
+
|
24
|
+
executes do
|
25
|
+
NewRelic::Agent.logger.info('Installing ethon instrumentation')
|
26
|
+
end
|
27
|
+
|
28
|
+
executes do
|
29
|
+
if use_prepend?
|
30
|
+
# NOTE: by default prepend_instrument will go with the module name that
|
31
|
+
# precedes 'Prepend' (so 'Easy' and 'Multi'), but we want to use
|
32
|
+
# 'Ethon::Easy' and 'Ethon::Multi' so 3rd argument is supplied
|
33
|
+
prepend_instrument Ethon::Easy, NewRelic::Agent::Instrumentation::Ethon::Easy::Prepend, Ethon::Easy.name
|
34
|
+
prepend_instrument Ethon::Multi, NewRelic::Agent::Instrumentation::Ethon::Multi::Prepend, Ethon::Multi.name
|
35
|
+
else
|
36
|
+
chain_instrument NewRelic::Agent::Instrumentation::Ethon::Chain
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -14,10 +14,7 @@ module NewRelic::Agent::Instrumentation
|
|
14
14
|
def add_thread_tracing(&block)
|
15
15
|
return block if !NewRelic::Agent::Tracer.thread_tracing_enabled?
|
16
16
|
|
17
|
-
NewRelic::Agent::Tracer.thread_block_with_current_transaction(
|
18
|
-
segment_name: 'Ruby/Fiber',
|
19
|
-
&block
|
20
|
-
)
|
17
|
+
NewRelic::Agent::Tracer.thread_block_with_current_transaction(&block)
|
21
18
|
end
|
22
19
|
end
|
23
20
|
end
|
@@ -14,7 +14,7 @@ DependencyDetection.defer do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
executes do
|
17
|
-
supportability_name = NewRelic::Agent::Instrumentation::GRPC::
|
17
|
+
supportability_name = NewRelic::Agent::Instrumentation::GRPC::Server::INSTRUMENTATION_NAME
|
18
18
|
if use_prepend?
|
19
19
|
prepend_instrument GRPC::RpcServer, NewRelic::Agent::Instrumentation::GRPC::Server::RpcServerPrepend, supportability_name
|
20
20
|
prepend_instrument GRPC::RpcDesc, NewRelic::Agent::Instrumentation::GRPC::Server::RpcDescPrepend, supportability_name
|
@@ -0,0 +1,20 @@
|
|
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 HTTPX
|
7
|
+
module Chain
|
8
|
+
def self.instrument!
|
9
|
+
::HTTPX::Session.class_eval do
|
10
|
+
include NewRelic::Agent::Instrumentation::HTTPX
|
11
|
+
|
12
|
+
alias_method(:send_requests_without_tracing, :send_requests)
|
13
|
+
def send_requests(*requests)
|
14
|
+
send_requests_with_tracing(*requests) { send_requests_without_tracing(*requests) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
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/httpx_wrappers'
|
6
|
+
|
7
|
+
module NewRelic::Agent::Instrumentation::HTTPX
|
8
|
+
INSTRUMENTATION_NAME = 'HTTPX'
|
9
|
+
NOTICEABLE_ERROR_CLASS = 'HTTPX::Error'
|
10
|
+
|
11
|
+
def send_requests_with_tracing(*requests)
|
12
|
+
NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME)
|
13
|
+
requests.each { |r| nr_start_segment(r) }
|
14
|
+
yield
|
15
|
+
end
|
16
|
+
|
17
|
+
def nr_start_segment(request)
|
18
|
+
return unless NewRelic::Agent::Tracer.state.is_execution_traced?
|
19
|
+
|
20
|
+
wrapped_request = NewRelic::Agent::HTTPClients::HTTPXHTTPRequest.new(request)
|
21
|
+
segment = NewRelic::Agent::Tracer.start_external_request_segment(
|
22
|
+
library: wrapped_request.type,
|
23
|
+
uri: wrapped_request.uri,
|
24
|
+
procedure: wrapped_request.method
|
25
|
+
)
|
26
|
+
segment.add_request_headers(wrapped_request)
|
27
|
+
|
28
|
+
request.on(:response) { nr_finish_segment.call(request, segment) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def nr_finish_segment
|
32
|
+
proc do |request, segment|
|
33
|
+
response = @responses[request]
|
34
|
+
|
35
|
+
unless response
|
36
|
+
NewRelic::Agent.logger.debug('Processed an on-response callback for HTTPX but could not find the response!')
|
37
|
+
next
|
38
|
+
end
|
39
|
+
|
40
|
+
wrapped_response = NewRelic::Agent::HTTPClients::HTTPXHTTPResponse.new(response)
|
41
|
+
segment.process_response_headers(wrapped_response)
|
42
|
+
|
43
|
+
if response.is_a?(::HTTPX::ErrorResponse)
|
44
|
+
e = NewRelic::Agent::NoticeableError.new(NOTICEABLE_ERROR_CLASS, "Couldn't connect: #{response}")
|
45
|
+
segment.notice_error(e)
|
46
|
+
end
|
47
|
+
|
48
|
+
::NewRelic::Agent::Transaction::Segment.finish(segment)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
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
|
+
module NewRelic::Agent::Instrumentation
|
6
|
+
module HTTPX
|
7
|
+
module Prepend
|
8
|
+
include NewRelic::Agent::Instrumentation::HTTPX
|
9
|
+
|
10
|
+
def send_requests(*requests)
|
11
|
+
send_requests_with_tracing(*requests) { super }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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 'httpx/chain'
|
6
|
+
require_relative 'httpx/instrumentation'
|
7
|
+
require_relative 'httpx/prepend'
|
8
|
+
|
9
|
+
DependencyDetection.defer do
|
10
|
+
named :httpx
|
11
|
+
|
12
|
+
depends_on do
|
13
|
+
defined?(HTTPX) && Gem::Version.new(HTTPX::VERSION) >= Gem::Version.new('1.0.0')
|
14
|
+
end
|
15
|
+
|
16
|
+
executes do
|
17
|
+
NewRelic::Agent.logger.info('Installing httpx instrumentation')
|
18
|
+
end
|
19
|
+
|
20
|
+
executes do
|
21
|
+
if use_prepend?
|
22
|
+
prepend_instrument HTTPX::Session, NewRelic::Agent::Instrumentation::HTTPX::Prepend
|
23
|
+
else
|
24
|
+
chain_instrument NewRelic::Agent::Instrumentation::HTTPX::Chain
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -32,10 +32,16 @@ module NewRelic
|
|
32
32
|
end
|
33
33
|
|
34
34
|
wrapped_response = NewRelic::Agent::HTTPClients::NetHTTPResponse.new(response)
|
35
|
+
|
36
|
+
if NewRelic::Agent::LLM.openai_parent?(segment)
|
37
|
+
NewRelic::Agent::LLM.populate_openai_response_headers(wrapped_response, segment.parent)
|
38
|
+
end
|
39
|
+
|
35
40
|
segment.process_response_headers(wrapped_response)
|
41
|
+
|
36
42
|
response
|
37
43
|
ensure
|
38
|
-
segment
|
44
|
+
segment&.finish
|
39
45
|
end
|
40
46
|
end
|
41
47
|
end
|
@@ -0,0 +1,45 @@
|
|
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 Roda
|
7
|
+
module Ignorer
|
8
|
+
def self.should_ignore?(app, type)
|
9
|
+
return false unless app.opts.include?(:newrelic_ignores)
|
10
|
+
|
11
|
+
app.opts[:newrelic_ignores][type].any? do |pattern|
|
12
|
+
pattern === app.request.path_info
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def newrelic_ignore(*routes)
|
17
|
+
set_newrelic_ignore(:routes, *routes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def newrelic_ignore_apdex(*routes)
|
21
|
+
set_newrelic_ignore(:apdex, *routes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def newrelic_ignore_enduser(*routes)
|
25
|
+
set_newrelic_ignore(:enduser, *routes)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def set_newrelic_ignore(type, *routes)
|
31
|
+
# Create a newrelic_ignores hash if one doesn't exist
|
32
|
+
opts[:newrelic_ignores] = Hash.new([]) if !opts.include?(:newrelic_ignores)
|
33
|
+
|
34
|
+
if routes.empty?
|
35
|
+
opts[:newrelic_ignores][type] += [Regexp.new('.*')]
|
36
|
+
else
|
37
|
+
opts[:newrelic_ignores][type] += routes.map do |r|
|
38
|
+
# Roda adds leading slashes to routes, so we need to do the same
|
39
|
+
"#{'/' unless r.start_with?('/')}#{r}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -51,6 +51,18 @@ module NewRelic::Agent::Instrumentation
|
|
51
51
|
yield
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
def do_not_trace?
|
56
|
+
NewRelic::Agent::Instrumentation::Roda::Ignorer.should_ignore?(self, :routes)
|
57
|
+
end
|
58
|
+
|
59
|
+
def ignore_apdex?
|
60
|
+
NewRelic::Agent::Instrumentation::Roda::Ignorer.should_ignore?(self, :apdex)
|
61
|
+
end
|
62
|
+
|
63
|
+
def ignore_enduser?
|
64
|
+
NewRelic::Agent::Instrumentation::Roda::Ignorer.should_ignore?(self, :enduser)
|
65
|
+
end
|
54
66
|
end
|
55
67
|
end
|
56
68
|
end
|
@@ -9,13 +9,12 @@ module NewRelic
|
|
9
9
|
module TransactionNamer
|
10
10
|
extend self
|
11
11
|
|
12
|
-
ROOT = '/'.freeze
|
13
12
|
REGEX_MULTIPLE_SLASHES = %r{^[/^]*(.*?)[/$?]*$}.freeze
|
14
13
|
|
15
14
|
def transaction_name(request)
|
16
15
|
path = request.path || ::NewRelic::Agent::UNKNOWN_METRIC
|
17
16
|
name = path.gsub(REGEX_MULTIPLE_SLASHES, '\1') # remove any rogue slashes
|
18
|
-
name = ROOT if name.empty?
|
17
|
+
name = NewRelic::ROOT if name.empty?
|
19
18
|
name = "#{request.request_method} #{name}" if request.respond_to?(:request_method)
|
20
19
|
|
21
20
|
name
|
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
require_relative 'roda/instrumentation'
|
6
6
|
require_relative 'roda/roda_transaction_namer'
|
7
|
+
require_relative 'roda/ignorer'
|
7
8
|
|
8
9
|
DependencyDetection.defer do
|
9
10
|
named :roda
|
@@ -30,5 +31,6 @@ DependencyDetection.defer do
|
|
30
31
|
chain_instrument NewRelic::Agent::Instrumentation::Roda::Build::Chain
|
31
32
|
chain_instrument NewRelic::Agent::Instrumentation::Roda::Chain
|
32
33
|
end
|
34
|
+
Roda.class_eval { extend NewRelic::Agent::Instrumentation::Roda::Ignorer }
|
33
35
|
end
|
34
36
|
end
|
@@ -0,0 +1,36 @@
|
|
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 OpenAI::Chain
|
7
|
+
def self.instrument!
|
8
|
+
::OpenAI::Client.class_eval do
|
9
|
+
include NewRelic::Agent::Instrumentation::OpenAI
|
10
|
+
|
11
|
+
alias_method(:json_post_without_new_relic, :json_post)
|
12
|
+
|
13
|
+
# In versions 4.0.0+ json_post is an instance method
|
14
|
+
# defined in the OpenAI::HTTP module, included by the
|
15
|
+
# OpenAI::Client class
|
16
|
+
def json_post(**kwargs)
|
17
|
+
json_post_with_new_relic(**kwargs) do
|
18
|
+
json_post_without_new_relic(**kwargs)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# In versions below 4.0.0 json_post is a class method
|
23
|
+
# on OpenAI::Client
|
24
|
+
class << self
|
25
|
+
alias_method(:json_post_without_new_relic, :json_post)
|
26
|
+
|
27
|
+
def json_post(**kwargs)
|
28
|
+
json_post_with_new_relic(**kwargs) do
|
29
|
+
json_post_without_new_relic(**kwargs)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|