newrelic_rpm 6.5.0.357 → 6.10.0.364
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +65 -5
- data/CHANGELOG.md +243 -0
- data/Guardfile +18 -1
- data/lib/new_relic/agent.rb +89 -7
- data/lib/new_relic/agent/agent.rb +116 -57
- data/lib/new_relic/agent/agent_logger.rb +4 -0
- data/lib/new_relic/agent/attribute_filter.rb +7 -7
- data/lib/new_relic/agent/attributes.rb +150 -0
- data/lib/new_relic/agent/autostart.rb +19 -14
- data/lib/new_relic/agent/configuration/default_source.rb +132 -13
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +11 -5
- data/lib/new_relic/agent/configuration/manager.rb +13 -9
- data/lib/new_relic/agent/configuration/server_source.rb +3 -2
- data/lib/new_relic/agent/configuration/yaml_source.rb +11 -6
- data/lib/new_relic/agent/connect/request_builder.rb +5 -13
- data/lib/new_relic/agent/connect/response_handler.rb +1 -1
- data/lib/new_relic/agent/database.rb +1 -2
- data/lib/new_relic/agent/datastores/mongo.rb +1 -1
- data/lib/new_relic/agent/datastores/mongo/event_formatter.rb +2 -2
- data/lib/new_relic/agent/datastores/mongo/obfuscator.rb +8 -8
- data/lib/new_relic/agent/distributed_tracing.rb +155 -6
- data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +0 -0
- data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +60 -45
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_intrinsics.rb +80 -0
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
- data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +23 -99
- data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
- data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
- data/lib/new_relic/agent/distributed_tracing/trace_context_payload.rb +126 -0
- data/lib/new_relic/agent/error_collector.rb +35 -18
- data/lib/new_relic/agent/error_event_aggregator.rb +9 -6
- data/lib/new_relic/agent/error_trace_aggregator.rb +1 -0
- data/lib/new_relic/agent/event_aggregator.rb +26 -32
- data/lib/new_relic/agent/external.rb +7 -7
- data/lib/new_relic/agent/guid_generator.rb +28 -0
- data/lib/new_relic/agent/hostname.rb +7 -1
- data/lib/new_relic/agent/http_clients/abstract.rb +82 -0
- data/lib/new_relic/agent/http_clients/curb_wrappers.rb +24 -19
- data/lib/new_relic/agent/http_clients/excon_wrappers.rb +28 -13
- data/lib/new_relic/agent/http_clients/http_rb_wrappers.rb +17 -21
- data/lib/new_relic/agent/http_clients/httpclient_wrappers.rb +10 -11
- data/lib/new_relic/agent/http_clients/net_http_wrappers.rb +16 -4
- data/lib/new_relic/agent/http_clients/typhoeus_wrappers.rb +4 -6
- data/lib/new_relic/agent/http_clients/uri_util.rb +3 -2
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +5 -7
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +4 -0
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +11 -2
- data/lib/new_relic/agent/instrumentation/active_record.rb +4 -2
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +7 -2
- data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +8 -4
- data/lib/new_relic/agent/instrumentation/bunny.rb +45 -28
- data/lib/new_relic/agent/instrumentation/curb.rb +59 -18
- data/lib/new_relic/agent/instrumentation/data_mapper.rb +3 -1
- data/lib/new_relic/agent/instrumentation/excon.rb +1 -1
- data/lib/new_relic/agent/instrumentation/excon/connection.rb +6 -3
- data/lib/new_relic/agent/instrumentation/excon/middleware.rb +2 -1
- data/lib/new_relic/agent/instrumentation/grape.rb +5 -10
- data/lib/new_relic/agent/instrumentation/http.rb +6 -3
- data/lib/new_relic/agent/instrumentation/httpclient.rb +5 -3
- data/lib/new_relic/agent/instrumentation/memcache.rb +3 -1
- data/lib/new_relic/agent/instrumentation/memcache/dalli.rb +6 -2
- data/lib/new_relic/agent/instrumentation/mongo.rb +9 -3
- data/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +13 -0
- data/lib/new_relic/agent/instrumentation/net.rb +6 -3
- data/lib/new_relic/agent/instrumentation/notifications_subscriber.rb +25 -1
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +2 -3
- data/lib/new_relic/agent/instrumentation/redis.rb +9 -3
- data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +0 -1
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +23 -6
- data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
- data/lib/new_relic/agent/logging.rb +139 -0
- data/lib/new_relic/agent/messaging.rb +5 -73
- data/lib/new_relic/agent/method_tracer.rb +3 -2
- data/lib/new_relic/agent/method_tracer_helpers.rb +2 -2
- data/lib/new_relic/agent/monitors.rb +27 -0
- data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
- data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
- data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +3 -3
- data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
- data/lib/new_relic/agent/new_relic_service.rb +7 -5
- data/lib/new_relic/agent/noticible_error.rb +22 -0
- data/lib/new_relic/agent/span_event_aggregator.rb +2 -4
- data/lib/new_relic/agent/span_event_primitive.rb +82 -53
- data/lib/new_relic/agent/sql_sampler.rb +3 -3
- data/lib/new_relic/agent/supported_versions.rb +2 -2
- data/lib/new_relic/agent/tracer.rb +65 -18
- data/lib/new_relic/agent/transaction.rb +84 -79
- data/lib/new_relic/agent/transaction/abstract_segment.rb +28 -2
- data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +57 -146
- data/lib/new_relic/agent/transaction/external_request_segment.rb +29 -36
- data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -11
- data/lib/new_relic/agent/transaction/segment.rb +7 -1
- data/lib/new_relic/agent/transaction/trace.rb +2 -4
- data/lib/new_relic/agent/transaction/trace_context.rb +168 -0
- data/lib/new_relic/agent/transaction/trace_node.rb +10 -8
- data/lib/new_relic/agent/transaction_error_primitive.rb +10 -15
- data/lib/new_relic/agent/transaction_event_primitive.rb +28 -39
- data/lib/new_relic/agent/transaction_event_recorder.rb +3 -3
- data/lib/new_relic/cli/commands/deployments.rb +1 -1
- data/lib/new_relic/cli/commands/install.rb +3 -2
- data/lib/new_relic/coerce.rb +31 -6
- data/lib/new_relic/constants.rb +34 -0
- data/lib/new_relic/control/instance_methods.rb +10 -1
- data/lib/new_relic/dependency_detection.rb +4 -4
- data/lib/new_relic/noticed_error.rb +38 -17
- data/lib/new_relic/rack/browser_monitoring.rb +5 -0
- data/lib/new_relic/supportability_helper.rb +14 -0
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/multiverse.rb +25 -0
- data/lib/tasks/tests.rake +6 -1
- data/newrelic_rpm.gemspec +16 -5
- data/test/agent_helper.rb +329 -70
- data/true +0 -0
- metadata +98 -30
- data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
- data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -40
- data/lib/new_relic/agent/http_clients/abstract_request.rb +0 -31
- data/lib/new_relic/agent/transaction/attributes.rb +0 -154
- data/lib/tasks/versions.html.erb +0 -28
- data/lib/tasks/versions.postface.html +0 -8
- data/lib/tasks/versions.preface.html +0 -9
- data/lib/tasks/versions.rake +0 -65
- data/lib/tasks/versions.txt.erb +0 -14
@@ -2,6 +2,7 @@
|
|
2
2
|
# encoding: utf-8
|
3
3
|
# This file is distributed under New Relic's license terms.
|
4
4
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
5
|
+
# frozen_string_literal: true
|
5
6
|
|
6
7
|
# This module includes utilities for manipulating URIs, particularly from the
|
7
8
|
# context of Net::HTTP requests. We don't always have direct access to the full
|
@@ -41,10 +42,10 @@ module NewRelic
|
|
41
42
|
uri
|
42
43
|
end
|
43
44
|
|
44
|
-
QUESTION_MARK = "?"
|
45
|
+
QUESTION_MARK = "?"
|
45
46
|
|
46
47
|
def self.strip_query_string(fragment)
|
47
|
-
if
|
48
|
+
if fragment.include? QUESTION_MARK
|
48
49
|
fragment.split(QUESTION_MARK).first
|
49
50
|
else
|
50
51
|
fragment
|
@@ -29,7 +29,10 @@ module NewRelic
|
|
29
29
|
def finish(name, id, payload) #THREAD_LOCAL_ACCESS
|
30
30
|
return unless state.is_execution_traced?
|
31
31
|
|
32
|
-
|
32
|
+
if exception = exception_object(payload)
|
33
|
+
NewRelic::Agent.notice_error exception
|
34
|
+
end
|
35
|
+
|
33
36
|
finishable = pop_segment(id)
|
34
37
|
finishable.finish if finishable
|
35
38
|
rescue => e
|
@@ -47,14 +50,9 @@ module NewRelic
|
|
47
50
|
end
|
48
51
|
|
49
52
|
DOT_ACTION_CABLE = '.action_cable'.freeze
|
50
|
-
EMPTY_STRING = ''.freeze
|
51
53
|
|
52
54
|
def action_name(name)
|
53
|
-
name.gsub DOT_ACTION_CABLE,
|
54
|
-
end
|
55
|
-
|
56
|
-
def notice_error(payload)
|
57
|
-
NewRelic::Agent.notice_error payload[:exception_object]
|
55
|
+
name.gsub DOT_ACTION_CABLE, NewRelic::EMPTY_STR
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
@@ -35,6 +35,10 @@ module NewRelic
|
|
35
35
|
if state.is_execution_traced? \
|
36
36
|
&& !should_ignore(payload, controller_class(payload))
|
37
37
|
|
38
|
+
if exception = exception_object(payload)
|
39
|
+
finishable.notice_error(exception)
|
40
|
+
end
|
41
|
+
|
38
42
|
finishable.finish
|
39
43
|
else
|
40
44
|
Agent.instance.pop_trace_execution_flag
|
@@ -24,8 +24,13 @@ module NewRelic
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def finish(name, id, payload) #THREAD_LOCAL_ACCESS
|
27
|
-
|
28
|
-
|
27
|
+
if segment = pop_segment(id)
|
28
|
+
|
29
|
+
if exception = exception_object(payload)
|
30
|
+
segment.notice_error exception
|
31
|
+
end
|
32
|
+
segment.finish
|
33
|
+
end
|
29
34
|
rescue => e
|
30
35
|
log_notification_error(e, name, 'finish')
|
31
36
|
end
|
@@ -97,6 +102,10 @@ module NewRelic
|
|
97
102
|
def finish
|
98
103
|
@finishable.finish if @finishable
|
99
104
|
end
|
105
|
+
|
106
|
+
def notice_error error
|
107
|
+
@finishable.notice_error error if @finishable
|
108
|
+
end
|
100
109
|
end
|
101
110
|
end
|
102
111
|
|
@@ -43,7 +43,7 @@ module NewRelic
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def log_with_newrelic_instrumentation(*args, &block)
|
46
|
+
def log_with_newrelic_instrumentation(*args, &block)
|
47
47
|
state = NewRelic::Agent::Tracer.state
|
48
48
|
|
49
49
|
if !state.is_execution_traced?
|
@@ -78,7 +78,9 @@ module NewRelic
|
|
78
78
|
segment._notice_sql(sql, @config, EXPLAINER)
|
79
79
|
|
80
80
|
begin
|
81
|
-
|
81
|
+
NewRelic::Agent::Tracer.capture_segment_error segment do
|
82
|
+
log_without_newrelic_instrumentation(*args, &block)
|
83
|
+
end
|
82
84
|
ensure
|
83
85
|
segment.finish if segment
|
84
86
|
end
|
@@ -58,8 +58,13 @@ module NewRelic
|
|
58
58
|
return if cached?(payload)
|
59
59
|
return unless state.is_execution_traced?
|
60
60
|
|
61
|
-
segment = pop_segment(id)
|
62
|
-
|
61
|
+
if segment = pop_segment(id)
|
62
|
+
if exception = exception_object(payload)
|
63
|
+
segment.notice_error(exception)
|
64
|
+
end
|
65
|
+
segment.finish
|
66
|
+
end
|
67
|
+
|
63
68
|
rescue => e
|
64
69
|
log_notification_error(e, name, 'finish')
|
65
70
|
end
|
@@ -16,7 +16,7 @@ module NewRelic
|
|
16
16
|
|
17
17
|
def finish name, id, payload
|
18
18
|
return unless state.is_execution_traced?
|
19
|
-
finish_segment id
|
19
|
+
finish_segment id, payload
|
20
20
|
rescue => e
|
21
21
|
log_notification_error e, name, 'finish'
|
22
22
|
end
|
@@ -28,9 +28,13 @@ module NewRelic
|
|
28
28
|
push_segment id, segment
|
29
29
|
end
|
30
30
|
|
31
|
-
def finish_segment id
|
32
|
-
segment = pop_segment
|
33
|
-
|
31
|
+
def finish_segment id, payload
|
32
|
+
if segment = pop_segment(id)
|
33
|
+
if exception = exception_object(payload)
|
34
|
+
segment.notice_error(exception)
|
35
|
+
end
|
36
|
+
segment.finish
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
36
40
|
def metric_name name, payload
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# This file is distributed under New Relic's license terms.
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
# frozen_string_literal: true
|
4
5
|
|
5
6
|
DependencyDetection.defer do
|
6
7
|
named :bunny
|
@@ -11,7 +12,7 @@ DependencyDetection.defer do
|
|
11
12
|
|
12
13
|
executes do
|
13
14
|
::NewRelic::Agent.logger.info 'Installing Bunny instrumentation'
|
14
|
-
require 'new_relic/agent/cross_app_tracing'
|
15
|
+
require 'new_relic/agent/distributed_tracing/cross_app_tracing'
|
15
16
|
require 'new_relic/agent/messaging'
|
16
17
|
require 'new_relic/agent/transaction/message_broker_segment'
|
17
18
|
end
|
@@ -41,10 +42,11 @@ DependencyDetection.defer do
|
|
41
42
|
)
|
42
43
|
rescue => e
|
43
44
|
NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Exchange#publish", e
|
44
|
-
end
|
45
|
-
|
46
|
-
begin
|
47
45
|
publish_without_new_relic payload, opts
|
46
|
+
else
|
47
|
+
NewRelic::Agent::Tracer.capture_segment_error segment do
|
48
|
+
publish_without_new_relic payload, opts
|
49
|
+
end
|
48
50
|
ensure
|
49
51
|
segment.finish if segment
|
50
52
|
end
|
@@ -55,28 +57,40 @@ DependencyDetection.defer do
|
|
55
57
|
alias_method :pop_without_new_relic, :pop
|
56
58
|
|
57
59
|
def pop(opts = {:manual_ack => false}, &block)
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
bunny_error, delivery_info, message_properties, _payload = nil, nil, nil, nil
|
61
|
+
begin
|
62
|
+
t0 = Time.now
|
63
|
+
msg = pop_without_new_relic opts, &block
|
64
|
+
delivery_info, message_properties, _payload = msg
|
65
|
+
rescue StandardError => error
|
66
|
+
bunny_error = error
|
67
|
+
end
|
61
68
|
|
62
69
|
begin
|
63
|
-
if delivery_info
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
destination_name: exchange_name,
|
70
|
-
delivery_info: delivery_info,
|
71
|
-
message_properties: message_properties,
|
72
|
-
exchange_type: exchange_type,
|
73
|
-
queue_name: name,
|
74
|
-
start_time: t0
|
75
|
-
)
|
70
|
+
exchange_name, exchange_type = if delivery_info
|
71
|
+
[ NewRelic::Agent::Instrumentation::Bunny.exchange_name(delivery_info.exchange),
|
72
|
+
NewRelic::Agent::Instrumentation::Bunny.exchange_type(delivery_info, channel) ]
|
73
|
+
else
|
74
|
+
[ NewRelic::Agent::Instrumentation::Bunny.exchange_name(NewRelic::EMPTY_STR),
|
75
|
+
NewRelic::Agent::Instrumentation::Bunny.exchange_type({}, channel) ]
|
76
76
|
end
|
77
77
|
|
78
|
+
segment = NewRelic::Agent::Messaging.start_amqp_consume_segment(
|
79
|
+
library: NewRelic::Agent::Instrumentation::Bunny::LIBRARY,
|
80
|
+
destination_name: exchange_name,
|
81
|
+
delivery_info: (delivery_info || {}),
|
82
|
+
message_properties: (message_properties || {headers: {}}),
|
83
|
+
exchange_type: exchange_type,
|
84
|
+
queue_name: name,
|
85
|
+
start_time: t0
|
86
|
+
)
|
78
87
|
rescue => e
|
79
88
|
NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#pop", e
|
89
|
+
else
|
90
|
+
if bunny_error
|
91
|
+
segment.notice_error bunny_error
|
92
|
+
raise bunny_error
|
93
|
+
end
|
80
94
|
ensure
|
81
95
|
segment.finish if segment
|
82
96
|
end
|
@@ -97,10 +111,11 @@ DependencyDetection.defer do
|
|
97
111
|
)
|
98
112
|
rescue => e
|
99
113
|
NewRelic::Agent.logger.error "Error starting message broker segment in Bunny::Queue#purge", e
|
100
|
-
end
|
101
|
-
|
102
|
-
begin
|
103
114
|
purge_without_new_relic(*args)
|
115
|
+
else
|
116
|
+
NewRelic::Agent::Tracer.capture_segment_error segment do
|
117
|
+
purge_without_new_relic(*args)
|
118
|
+
end
|
104
119
|
ensure
|
105
120
|
segment.finish if segment
|
106
121
|
end
|
@@ -134,18 +149,20 @@ module NewRelic
|
|
134
149
|
module Agent
|
135
150
|
module Instrumentation
|
136
151
|
module Bunny
|
137
|
-
LIBRARY = 'RabbitMQ'
|
138
|
-
|
139
|
-
|
152
|
+
LIBRARY = 'RabbitMQ'
|
153
|
+
DEFAULT_NAME = 'Default'
|
154
|
+
DEFAULT_TYPE = :direct
|
155
|
+
|
156
|
+
SLASH = '/'
|
140
157
|
|
141
158
|
class << self
|
142
159
|
def exchange_name name
|
143
|
-
name.empty? ?
|
160
|
+
name.empty? ? DEFAULT_NAME : name
|
144
161
|
end
|
145
162
|
|
146
163
|
def exchange_type delivery_info, channel
|
147
164
|
if di_exchange = delivery_info[:exchange]
|
148
|
-
return
|
165
|
+
return DEFAULT_TYPE if di_exchange.empty?
|
149
166
|
return channel.exchanges[delivery_info[:exchange]].type if channel.exchanges[di_exchange]
|
150
167
|
end
|
151
168
|
end
|
@@ -14,7 +14,7 @@ DependencyDetection.defer do
|
|
14
14
|
|
15
15
|
executes do
|
16
16
|
::NewRelic::Agent.logger.info 'Installing Curb instrumentation'
|
17
|
-
require 'new_relic/agent/cross_app_tracing'
|
17
|
+
require 'new_relic/agent/distributed_tracing/cross_app_tracing'
|
18
18
|
require 'new_relic/agent/http_clients/curb_wrappers'
|
19
19
|
end
|
20
20
|
|
@@ -22,10 +22,12 @@ DependencyDetection.defer do
|
|
22
22
|
class Curl::Easy
|
23
23
|
|
24
24
|
attr_accessor :_nr_instrumented,
|
25
|
+
:_nr_failure_instrumented,
|
25
26
|
:_nr_http_verb,
|
26
27
|
:_nr_header_str,
|
27
28
|
:_nr_original_on_header,
|
28
29
|
:_nr_original_on_complete,
|
30
|
+
:_nr_original_on_failure,
|
29
31
|
:_nr_serial
|
30
32
|
|
31
33
|
# We have to hook these three methods separately, as they don't use
|
@@ -53,7 +55,7 @@ DependencyDetection.defer do
|
|
53
55
|
|
54
56
|
|
55
57
|
# Hook the #http method to set the verb.
|
56
|
-
def http_with_newrelic
|
58
|
+
def http_with_newrelic verb
|
57
59
|
self._nr_http_verb = verb.to_s.upcase
|
58
60
|
http_without_newrelic( verb )
|
59
61
|
end
|
@@ -72,9 +74,9 @@ DependencyDetection.defer do
|
|
72
74
|
alias_method :perform, :perform_with_newrelic
|
73
75
|
|
74
76
|
# Record the HTTP verb for future #perform calls
|
75
|
-
def method_with_newrelic
|
76
|
-
self._nr_http_verb =
|
77
|
-
method_without_newrelic(
|
77
|
+
def method_with_newrelic verb
|
78
|
+
self._nr_http_verb = verb.upcase
|
79
|
+
method_without_newrelic(verb)
|
78
80
|
end
|
79
81
|
|
80
82
|
alias_method :method_without_newrelic, :method
|
@@ -101,12 +103,12 @@ DependencyDetection.defer do
|
|
101
103
|
include NewRelic::Agent::MethodTracer
|
102
104
|
|
103
105
|
# Add CAT with callbacks if the request is serial
|
104
|
-
def add_with_newrelic(curl)
|
106
|
+
def add_with_newrelic(curl)
|
105
107
|
if curl.respond_to?(:_nr_serial) && curl._nr_serial
|
106
108
|
hook_pending_request(curl) if NewRelic::Agent::Tracer.tracing_enabled?
|
107
109
|
end
|
108
110
|
|
109
|
-
return add_without_newrelic
|
111
|
+
return add_without_newrelic curl
|
110
112
|
end
|
111
113
|
|
112
114
|
alias_method :add_without_newrelic, :add
|
@@ -125,9 +127,9 @@ DependencyDetection.defer do
|
|
125
127
|
alias_method :perform, :perform_with_newrelic
|
126
128
|
|
127
129
|
|
128
|
-
# Instrument the specified +request+ (a Curl::Easy object)
|
129
|
-
# tracing if it's enabled.
|
130
|
-
def hook_pending_request(request)
|
130
|
+
# Instrument the specified +request+ (a Curl::Easy object)
|
131
|
+
# and set up cross-application tracing if it's enabled.
|
132
|
+
def hook_pending_request(request)
|
131
133
|
wrapped_request, wrapped_response = wrap_request(request)
|
132
134
|
|
133
135
|
segment = NewRelic::Agent::Tracer.start_external_request_segment(
|
@@ -138,9 +140,11 @@ DependencyDetection.defer do
|
|
138
140
|
|
139
141
|
segment.add_request_headers wrapped_request
|
140
142
|
|
143
|
+
# install all callbacks
|
141
144
|
unless request._nr_instrumented
|
142
145
|
install_header_callback(request, wrapped_response)
|
143
146
|
install_completion_callback(request, wrapped_response, segment)
|
147
|
+
install_failure_callback(request, wrapped_response, segment)
|
144
148
|
request._nr_instrumented = true
|
145
149
|
end
|
146
150
|
rescue => err
|
@@ -149,35 +153,37 @@ DependencyDetection.defer do
|
|
149
153
|
|
150
154
|
|
151
155
|
# Create request and response adapter objects for the specified +request+
|
156
|
+
# NOTE: Although strange to wrap request and response at once, it works
|
157
|
+
# because curb's callback mechanism updates the instantiated wrappers
|
158
|
+
# during the life-cycle of external request
|
152
159
|
def wrap_request(request)
|
153
160
|
return NewRelic::Agent::HTTPClients::CurbRequest.new(request),
|
154
161
|
NewRelic::Agent::HTTPClients::CurbResponse.new(request)
|
155
162
|
end
|
156
163
|
|
157
|
-
|
158
|
-
#
|
159
|
-
|
160
|
-
def install_header_callback( request, wrapped_response )
|
164
|
+
# Install a callback that will record the response headers
|
165
|
+
# to enable CAT linking
|
166
|
+
def install_header_callback(request, wrapped_response)
|
161
167
|
original_callback = request.on_header
|
162
168
|
request._nr_original_on_header = original_callback
|
163
169
|
request._nr_header_str = nil
|
164
170
|
request.on_header do |header_data|
|
165
171
|
if original_callback
|
166
|
-
original_callback.call
|
172
|
+
original_callback.call header_data
|
167
173
|
else
|
168
|
-
wrapped_response.append_header_data
|
174
|
+
wrapped_response.append_header_data header_data
|
169
175
|
header_data.length
|
170
176
|
end
|
171
177
|
end
|
172
178
|
end
|
173
179
|
|
174
180
|
# Install a callback that will finish the trace.
|
175
|
-
def install_completion_callback(request, wrapped_response, segment)
|
181
|
+
def install_completion_callback(request, wrapped_response, segment)
|
176
182
|
original_callback = request.on_complete
|
177
183
|
request._nr_original_on_complete = original_callback
|
178
184
|
request.on_complete do |finished_request|
|
179
185
|
begin
|
180
|
-
segment.
|
186
|
+
segment.process_response_headers wrapped_response
|
181
187
|
ensure
|
182
188
|
segment.finish if segment
|
183
189
|
# Make sure the existing completion callback is run, and restore the
|
@@ -188,12 +194,47 @@ DependencyDetection.defer do
|
|
188
194
|
end
|
189
195
|
end
|
190
196
|
|
197
|
+
# Install a callback that will fire on failures
|
198
|
+
# NOTE: on_failure is not always called, so we're not always
|
199
|
+
# unhooking the callback. No harm/no foul in production, but
|
200
|
+
# definitely something to beware of if debugging callback issues
|
201
|
+
# _nr_failure_instrumented exists to prevent infinitely chaining
|
202
|
+
# our on_failure callback hook.
|
203
|
+
def install_failure_callback(request, wrapped_response, segment)
|
204
|
+
return if request._nr_failure_instrumented
|
205
|
+
original_callback = request.on_failure
|
206
|
+
request._nr_original_on_failure = original_callback
|
207
|
+
request.on_failure do |failed_request, error|
|
208
|
+
begin
|
209
|
+
if segment
|
210
|
+
noticible_error = NewRelic::Agent::NoticibleError.new error[0].name, error[-1]
|
211
|
+
segment.notice_error noticible_error
|
212
|
+
end
|
213
|
+
ensure
|
214
|
+
original_callback.call(failed_request, error) if original_callback
|
215
|
+
remove_failure_callback(failed_request)
|
216
|
+
end
|
217
|
+
request._nr_failure_instrumented = true
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
# on_failure callbacks cannot be removed in the on_complete
|
222
|
+
# callback where this method is invoked because on_complete
|
223
|
+
# fires before the on_failure!
|
191
224
|
def remove_instrumentation_callbacks(request)
|
192
225
|
request.on_complete(&request._nr_original_on_complete)
|
193
226
|
request.on_header(&request._nr_original_on_header)
|
194
227
|
request._nr_instrumented = false
|
195
228
|
end
|
196
229
|
|
230
|
+
# We execute customer's on_failure callback (if any) and
|
231
|
+
# uninstall our hook here since the on_complete callback
|
232
|
+
# fires before the on_failure callback.
|
233
|
+
def remove_failure_callback(request)
|
234
|
+
request.on_failure(&request._nr_original_on_failure)
|
235
|
+
request._nr_failure_instrumented = false
|
236
|
+
end
|
237
|
+
|
197
238
|
private
|
198
239
|
|
199
240
|
def first_request_is_serial?
|