newrelic_rpm 6.6.0.358 → 6.11.0.365
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +81 -5
- data/CHANGELOG.md +262 -0
- data/Gemfile +6 -2
- data/Guardfile +18 -1
- data/LICENSE +1 -1
- data/Rakefile +2 -0
- data/lib/new_relic/agent.rb +89 -7
- data/lib/new_relic/agent/agent.rb +115 -58
- 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 +154 -9
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +11 -5
- data/lib/new_relic/agent/configuration/manager.rb +0 -8
- 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/database.rb +1 -2
- data/lib/new_relic/agent/database/obfuscation_helpers.rb +1 -1
- 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} +2 -1
- 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} +24 -101
- 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 +33 -16
- data/lib/new_relic/agent/error_event_aggregator.rb +7 -5
- 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/redis.rb +9 -3
- data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
- data/lib/new_relic/agent/instrumentation/sidekiq.rb +47 -23
- data/lib/new_relic/agent/instrumentation/typhoeus.rb +23 -6
- 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 +18 -6
- 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} +1 -1
- data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
- data/lib/new_relic/agent/new_relic_service.rb +7 -6
- data/lib/new_relic/agent/noticible_error.rb +22 -0
- data/lib/new_relic/agent/span_event_aggregator.rb +1 -0
- data/lib/new_relic/agent/span_event_primitive.rb +86 -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/system_info.rb +12 -3
- 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/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 +38 -0
- data/lib/new_relic/control/instance_methods.rb +10 -1
- data/lib/new_relic/dependency_detection.rb +4 -4
- data/lib/new_relic/environment_report.rb +5 -1
- 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 +19 -8
- data/test/agent_helper.rb +323 -71
- metadata +100 -33
- 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
@@ -1,39 +1,68 @@
|
|
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
|
-
require 'new_relic/agent/distributed_trace_payload'
|
6
|
+
require 'new_relic/agent/distributed_tracing/distributed_trace_payload'
|
7
|
+
require 'new_relic/agent/distributed_tracing/distributed_trace_intrinsics'
|
8
|
+
require 'new_relic/agent/distributed_tracing/distributed_trace_metrics'
|
6
9
|
|
7
10
|
module NewRelic
|
8
11
|
module Agent
|
9
12
|
class Transaction
|
10
13
|
module DistributedTracing
|
11
14
|
attr_accessor :distributed_trace_payload
|
15
|
+
attr_writer :distributed_trace_payload_created
|
16
|
+
|
17
|
+
SUPPORTABILITY_DISTRIBUTED_TRACE = "Supportability/DistributedTrace"
|
18
|
+
CREATE_PREFIX = "#{SUPPORTABILITY_DISTRIBUTED_TRACE}/CreatePayload"
|
19
|
+
ACCEPT_PREFIX = "#{SUPPORTABILITY_DISTRIBUTED_TRACE}/AcceptPayload"
|
20
|
+
IGNORE_PREFIX = "#{ACCEPT_PREFIX}/Ignored"
|
21
|
+
|
22
|
+
CREATE_SUCCESS_METRIC = "#{CREATE_PREFIX}/Success"
|
23
|
+
CREATE_EXCEPTION_METRIC = "#{CREATE_PREFIX}/Exception"
|
24
|
+
ACCEPT_SUCCESS_METRIC = "#{ACCEPT_PREFIX}/Success"
|
25
|
+
ACCEPT_EXCEPTION_METRIC = "#{ACCEPT_PREFIX}/Exception"
|
26
|
+
ACCEPT_PARSE_EXCEPTION_METRIC = "#{ACCEPT_PREFIX}/ParseException"
|
27
|
+
|
28
|
+
IGNORE_ACCEPT_AFTER_CREATE_METRIC = "#{IGNORE_PREFIX}/CreateBeforeAccept"
|
29
|
+
IGNORE_MULTIPLE_ACCEPT_METRIC = "#{IGNORE_PREFIX}/Multiple"
|
30
|
+
IGNORE_ACCEPT_NULL_METRIC = "#{IGNORE_PREFIX}/Null"
|
31
|
+
IGNORE_ACCEPT_MAJOR_VERSION_METRIC = "#{IGNORE_PREFIX}/MajorVersion"
|
32
|
+
IGNORE_ACCEPT_UNTRUSTED_ACCOUNT_METRIC = "#{IGNORE_PREFIX}/UntrustedAccount"
|
33
|
+
|
34
|
+
LBRACE = "{"
|
35
|
+
NULL_PAYLOAD = 'null'
|
12
36
|
|
13
|
-
|
14
|
-
|
37
|
+
NEWRELIC_TRACE_KEY = "HTTP_NEWRELIC"
|
38
|
+
|
39
|
+
def accept_distributed_tracing_incoming_request request
|
40
|
+
return unless Agent.config[:'distributed_tracing.enabled']
|
41
|
+
return unless payload = request[NEWRELIC_TRACE_KEY]
|
42
|
+
|
43
|
+
accept_distributed_trace_payload payload
|
15
44
|
end
|
16
45
|
|
17
|
-
|
18
|
-
|
46
|
+
def distributed_trace_payload_created?
|
47
|
+
@distributed_trace_payload_created ||= false
|
48
|
+
end
|
19
49
|
|
20
50
|
def create_distributed_trace_payload
|
21
51
|
return unless Agent.config[:'distributed_tracing.enabled']
|
22
|
-
|
23
|
-
|
24
|
-
|
52
|
+
|
53
|
+
@distributed_trace_payload_created = true
|
54
|
+
payload = DistributedTracePayload.for_transaction transaction
|
55
|
+
NewRelic::Agent.increment_metric CREATE_SUCCESS_METRIC
|
25
56
|
payload
|
26
57
|
rescue => e
|
27
|
-
NewRelic::Agent.increment_metric
|
58
|
+
NewRelic::Agent.increment_metric CREATE_EXCEPTION_METRIC
|
28
59
|
NewRelic::Agent.logger.warn "Failed to create distributed trace payload", e
|
29
60
|
nil
|
30
61
|
end
|
31
62
|
|
32
|
-
SUPPORTABILITY_ACCEPT_PAYLOAD_SUCCESS = "Supportability/DistributedTrace/AcceptPayload/Success".freeze
|
33
|
-
SUPPORTABILITY_ACCEPT_PAYLOAD_EXCEPTION = "Supportability/DistributedTrace/AcceptPayload/Exception".freeze
|
34
|
-
|
35
63
|
def accept_distributed_trace_payload payload
|
36
64
|
return unless Agent.config[:'distributed_tracing.enabled']
|
65
|
+
|
37
66
|
return false if check_payload_ignored(payload)
|
38
67
|
return false unless check_payload_present(payload)
|
39
68
|
return false unless payload = decode_payload(payload)
|
@@ -43,95 +72,37 @@ module NewRelic
|
|
43
72
|
|
44
73
|
assign_payload_and_sampling_params(payload)
|
45
74
|
|
46
|
-
NewRelic::Agent.increment_metric
|
75
|
+
NewRelic::Agent.increment_metric ACCEPT_SUCCESS_METRIC
|
47
76
|
true
|
48
77
|
rescue => e
|
49
|
-
NewRelic::Agent.increment_metric
|
78
|
+
NewRelic::Agent.increment_metric ACCEPT_EXCEPTION_METRIC
|
50
79
|
NewRelic::Agent.logger.warn "Failed to accept distributed trace payload", e
|
51
80
|
false
|
52
81
|
end
|
53
82
|
|
54
|
-
def trace_id
|
55
|
-
if distributed_trace_payload
|
56
|
-
distributed_trace_payload.trace_id
|
57
|
-
else
|
58
|
-
guid
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def parent_id
|
63
|
-
# The payload comes from our parent transaction, so its ID
|
64
|
-
# is our parent ID.
|
65
|
-
#
|
66
|
-
distributed_trace_payload && distributed_trace_payload.transaction_id
|
67
|
-
end
|
68
|
-
|
69
|
-
def distributed_trace_payload_created?
|
70
|
-
@distributed_trace_payload_created ||= false
|
71
|
-
end
|
72
|
-
|
73
|
-
attr_writer :distributed_trace_payload_created
|
74
|
-
|
75
|
-
def append_distributed_trace_info transaction_payload
|
76
|
-
return unless Agent.config[:'distributed_tracing.enabled']
|
77
|
-
if distributed_trace_payload
|
78
|
-
distributed_trace_payload.assign_intrinsics self, transaction_payload
|
79
|
-
else
|
80
|
-
DistributedTracePayload.assign_initial_intrinsics self, transaction_payload
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def assign_distributed_trace_intrinsics
|
85
|
-
return unless Agent.config[:'distributed_tracing.enabled']
|
86
|
-
DistributedTracePayload::INTRINSIC_KEYS.each do |key|
|
87
|
-
next unless @payload.key? key
|
88
|
-
attributes.add_intrinsic_attribute key, @payload[key]
|
89
|
-
end
|
90
|
-
nil
|
91
|
-
end
|
92
|
-
|
93
|
-
# This method returns transport_duration in seconds. Transport duration
|
94
|
-
# is stored in milliseconds on the payload, but it's needed in seconds
|
95
|
-
# for metrics and intrinsics.
|
96
|
-
def transport_duration
|
97
|
-
return unless distributed_trace_payload
|
98
|
-
duration = (start_time.to_f * 1000 - distributed_trace_payload.timestamp) / 1000
|
99
|
-
duration < 0 ? 0 : duration
|
100
|
-
end
|
101
|
-
|
102
83
|
private
|
103
84
|
|
104
|
-
SUPPORTABILITY_CREATE_BEFORE_ACCEPT_PAYLOAD = "Supportability/DistributedTrace/AcceptPayload/Ignored/CreateBeforeAccept".freeze
|
105
|
-
SUPPORTABILITY_MULTIPLE_ACCEPT_PAYLOAD = "Supportability/DistributedTrace/AcceptPayload/Ignored/Multiple".freeze
|
106
|
-
SUPPORTABILITY_PAYLOAD_ACCEPT_IGNORED_NULL = "Supportability/DistributedTrace/AcceptPayload/Ignored/Null".freeze
|
107
|
-
SUPPORTABILITY_PAYLOAD_ACCEPT_IGNORED_BROWSER = "Supportability/DistributedTrace/AcceptPayload/Ignored/BrowserAgentInjected".freeze
|
108
|
-
|
109
85
|
def check_payload_ignored(payload)
|
110
86
|
if distributed_trace_payload
|
111
|
-
NewRelic::Agent.increment_metric
|
87
|
+
NewRelic::Agent.increment_metric IGNORE_MULTIPLE_ACCEPT_METRIC
|
112
88
|
return true
|
113
89
|
elsif distributed_trace_payload_created?
|
114
|
-
NewRelic::Agent.increment_metric
|
90
|
+
NewRelic::Agent.increment_metric IGNORE_ACCEPT_AFTER_CREATE_METRIC
|
115
91
|
return true
|
116
92
|
end
|
117
93
|
false
|
118
94
|
end
|
119
95
|
|
120
|
-
NULL_PAYLOAD = 'null'.freeze
|
121
|
-
|
122
96
|
def check_payload_present(payload)
|
123
97
|
# We might be passed a Ruby `nil` object _or_ the JSON "null"
|
124
98
|
if payload.nil? || payload == NULL_PAYLOAD
|
125
|
-
NewRelic::Agent.increment_metric
|
99
|
+
NewRelic::Agent.increment_metric IGNORE_ACCEPT_NULL_METRIC
|
126
100
|
return nil
|
127
101
|
end
|
128
102
|
|
129
103
|
payload
|
130
104
|
end
|
131
105
|
|
132
|
-
SUPPORTABILITY_PAYLOAD_ACCEPT_IGNORED_PARSE_EXCEPTION = "Supportability/DistributedTrace/AcceptPayload/ParseException".freeze
|
133
|
-
LBRACE = "{".freeze
|
134
|
-
|
135
106
|
def decode_payload(payload)
|
136
107
|
decoded = if payload.start_with? LBRACE
|
137
108
|
DistributedTracePayload.from_json payload
|
@@ -143,7 +114,7 @@ module NewRelic
|
|
143
114
|
|
144
115
|
decoded
|
145
116
|
rescue => e
|
146
|
-
NewRelic::Agent.increment_metric
|
117
|
+
NewRelic::Agent.increment_metric ACCEPT_PARSE_EXCEPTION_METRIC
|
147
118
|
NewRelic::Agent.logger.warn "Error parsing distributed trace payload", e
|
148
119
|
nil
|
149
120
|
end
|
@@ -160,100 +131,40 @@ module NewRelic
|
|
160
131
|
|
161
132
|
true
|
162
133
|
else
|
163
|
-
NewRelic::Agent.increment_metric
|
134
|
+
NewRelic::Agent.increment_metric ACCEPT_PARSE_EXCEPTION_METRIC
|
164
135
|
false
|
165
136
|
end
|
166
137
|
end
|
167
138
|
|
168
|
-
SUPPORTABILITY_PAYLOAD_ACCEPT_IGNORED_MAJOR_VERSION = "Supportability/DistributedTrace/AcceptPayload/Ignored/MajorVersion".freeze
|
169
|
-
|
170
139
|
def check_valid_version(payload)
|
171
140
|
if DistributedTracePayload.major_version_matches?(payload)
|
172
141
|
true
|
173
142
|
else
|
174
|
-
NewRelic::Agent.increment_metric
|
143
|
+
NewRelic::Agent.increment_metric IGNORE_ACCEPT_MAJOR_VERSION_METRIC
|
175
144
|
false
|
176
145
|
end
|
177
146
|
end
|
178
147
|
|
179
|
-
SUPPORTABILITY_PAYLOAD_ACCEPT_UNTRUSTED_ACCOUNT = "Supportability/DistributedTrace/AcceptPayload/Ignored/UntrustedAccount".freeze
|
180
|
-
|
181
148
|
def check_trusted_account(payload)
|
182
149
|
compare_key = payload.trusted_account_key || payload.parent_account_id
|
183
150
|
unless compare_key == NewRelic::Agent.config[:trusted_account_key]
|
184
|
-
NewRelic::Agent.increment_metric
|
151
|
+
NewRelic::Agent.increment_metric IGNORE_ACCEPT_UNTRUSTED_ACCOUNT_METRIC
|
185
152
|
return false
|
186
153
|
end
|
187
154
|
true
|
188
155
|
end
|
189
156
|
|
190
157
|
def assign_payload_and_sampling_params(payload)
|
191
|
-
|
158
|
+
@distributed_trace_payload = payload
|
159
|
+
return if transaction.distributed_tracer.trace_context_header_data
|
160
|
+
transaction.trace_id = payload.trace_id
|
161
|
+
transaction.distributed_tracer.parent_transaction_id = payload.transaction_id
|
162
|
+
transaction.parent_span_id = payload.id
|
192
163
|
|
193
164
|
unless payload.sampled.nil?
|
194
|
-
|
195
|
-
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
ALL_SUFFIX = "all".freeze
|
200
|
-
ALL_WEB_SUFFIX = "allWeb".freeze
|
201
|
-
ALL_OTHER_SUFFIX = "allOther".freeze
|
202
|
-
|
203
|
-
def transaction_type_suffix
|
204
|
-
if Transaction.recording_web_transaction?
|
205
|
-
ALL_WEB_SUFFIX
|
206
|
-
else
|
207
|
-
ALL_OTHER_SUFFIX
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
def record_distributed_tracing_metrics
|
212
|
-
return unless Agent.config[:'distributed_tracing.enabled']
|
213
|
-
|
214
|
-
record_caller_by_duration_metrics
|
215
|
-
record_transport_duration_metrics
|
216
|
-
record_errors_by_caller_metrics
|
217
|
-
end
|
218
|
-
|
219
|
-
DURATION_BY_CALLER_UNKOWN_PREFIX = "DurationByCaller/Unknown/Unknown/Unknown/Unknown".freeze
|
220
|
-
|
221
|
-
def record_caller_by_duration_metrics
|
222
|
-
prefix = if distributed_trace?
|
223
|
-
payload = distributed_trace_payload
|
224
|
-
"DurationByCaller/#{payload.parent_type}/#{payload.parent_account_id}/#{payload.parent_app_id}/#{payload.caller_transport_type}"
|
225
|
-
else
|
226
|
-
DURATION_BY_CALLER_UNKOWN_PREFIX
|
165
|
+
transaction.sampled = payload.sampled
|
166
|
+
transaction.priority = payload.priority if payload.priority
|
227
167
|
end
|
228
|
-
|
229
|
-
metrics.record_unscoped "#{prefix}/#{ALL_SUFFIX}", duration
|
230
|
-
metrics.record_unscoped "#{prefix}/#{transaction_type_suffix}", duration
|
231
|
-
end
|
232
|
-
|
233
|
-
def record_transport_duration_metrics
|
234
|
-
return unless distributed_trace?
|
235
|
-
|
236
|
-
payload = distributed_trace_payload
|
237
|
-
prefix = "TransportDuration/#{payload.parent_type}/#{payload.parent_account_id}/#{payload.parent_app_id}/#{payload.caller_transport_type}"
|
238
|
-
|
239
|
-
metrics.record_unscoped "#{prefix}/#{ALL_SUFFIX}", transport_duration
|
240
|
-
metrics.record_unscoped "#{prefix}/#{transaction_type_suffix}", transport_duration
|
241
|
-
end
|
242
|
-
|
243
|
-
ERRORS_BY_CALLER_UNKOWN_PREFIX = "ErrorsByCaller/Unknown/Unknown/Unknown/Unknown".freeze
|
244
|
-
|
245
|
-
def record_errors_by_caller_metrics
|
246
|
-
return unless exceptions.size > 0
|
247
|
-
|
248
|
-
prefix = if distributed_trace?
|
249
|
-
payload = distributed_trace_payload
|
250
|
-
"ErrorsByCaller/#{payload.parent_type}/#{payload.parent_account_id}/#{payload.parent_app_id}/#{payload.caller_transport_type}"
|
251
|
-
else
|
252
|
-
ERRORS_BY_CALLER_UNKOWN_PREFIX
|
253
|
-
end
|
254
|
-
|
255
|
-
metrics.record_unscoped "#{prefix}/#{ALL_SUFFIX}", 1
|
256
|
-
metrics.record_unscoped "#{prefix}/#{transaction_type_suffix}", 1
|
257
168
|
end
|
258
169
|
end
|
259
170
|
end
|
@@ -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
|
require 'new_relic/agent/transaction/segment'
|
6
7
|
require 'new_relic/agent/http_clients/uri_util'
|
@@ -14,10 +15,16 @@ module NewRelic
|
|
14
15
|
#
|
15
16
|
# @api public
|
16
17
|
class ExternalRequestSegment < Segment
|
17
|
-
|
18
|
+
NR_SYNTHETICS_HEADER = 'X-NewRelic-Synthetics'
|
19
|
+
APP_DATA_KEY = 'NewRelicAppData'
|
18
20
|
|
19
|
-
|
21
|
+
EXTERNAL_ALL = "External/all"
|
22
|
+
EXTERNAL_ALL_WEB = "External/allWeb"
|
23
|
+
EXTERNAL_ALL_OTHER = "External/allOther"
|
24
|
+
MISSING_STATUS_CODE = "MissingHTTPStatusCode"
|
20
25
|
|
26
|
+
attr_reader :library, :uri, :procedure
|
27
|
+
attr_reader :http_status_code
|
21
28
|
|
22
29
|
def initialize library, uri, procedure, start_time = nil # :nodoc:
|
23
30
|
@library = library
|
@@ -25,6 +32,7 @@ module NewRelic
|
|
25
32
|
@procedure = procedure
|
26
33
|
@host_header = nil
|
27
34
|
@app_data = nil
|
35
|
+
@http_status_code = nil
|
28
36
|
super(nil, nil, start_time)
|
29
37
|
end
|
30
38
|
|
@@ -52,8 +60,7 @@ module NewRelic
|
|
52
60
|
|
53
61
|
return unless record_metrics?
|
54
62
|
|
55
|
-
|
56
|
-
insert_distributed_trace_header request
|
63
|
+
transaction.distributed_tracer.insert_headers request
|
57
64
|
rescue => e
|
58
65
|
NewRelic::Agent.logger.error "Error in add_request_headers", e
|
59
66
|
end
|
@@ -99,10 +106,6 @@ module NewRelic
|
|
99
106
|
@app_data && @app_data[1]
|
100
107
|
end
|
101
108
|
|
102
|
-
EXTERNAL_TRANSACTION_PREFIX = 'ExternalTransaction/'.freeze
|
103
|
-
SLASH = '/'.freeze
|
104
|
-
APP_DATA_KEY = 'NewRelicAppData'.freeze
|
105
|
-
|
106
109
|
# Obtain an obfuscated +String+ suitable for delivery across public networks that identifies this application
|
107
110
|
# and transaction to another application which is also running a New Relic agent. This +String+ can be processed
|
108
111
|
# by +process_request_metadata+ on the receiving application.
|
@@ -124,14 +127,14 @@ module NewRelic
|
|
124
127
|
NewRelicTransaction: [
|
125
128
|
transaction.guid,
|
126
129
|
false,
|
127
|
-
transaction.cat_trip_id,
|
128
|
-
transaction.cat_path_hash
|
130
|
+
transaction.distributed_tracer.cat_trip_id,
|
131
|
+
transaction.distributed_tracer.cat_path_hash
|
129
132
|
]
|
130
133
|
}
|
131
134
|
|
132
135
|
# flag cross app in the state so transaction knows to add bits to paylaod
|
133
136
|
#
|
134
|
-
transaction.is_cross_app_caller = true
|
137
|
+
transaction.distributed_tracer.is_cross_app_caller = true
|
135
138
|
|
136
139
|
# add Synthetics header if we have it
|
137
140
|
#
|
@@ -179,8 +182,23 @@ module NewRelic
|
|
179
182
|
super
|
180
183
|
end
|
181
184
|
|
185
|
+
def process_response_headers response # :nodoc:
|
186
|
+
set_http_status_code response
|
187
|
+
read_response_headers response
|
188
|
+
end
|
189
|
+
|
182
190
|
private
|
183
191
|
|
192
|
+
# Only sets the http_status_code if response.status_code is non-empty value
|
193
|
+
def set_http_status_code response
|
194
|
+
if response.respond_to? :status_code
|
195
|
+
@http_status_code = response.status_code if response.has_status_code?
|
196
|
+
else
|
197
|
+
NewRelic::Agent.logger.warn "Cannot extract HTTP Status Code from response #{response.class.to_s}"
|
198
|
+
NewRelic::Agent.record_metric "#{name}/#{MISSING_STATUS_CODE}", 1
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
184
202
|
def insert_synthetics_header request, header
|
185
203
|
request[NR_SYNTHETICS_HEADER] = header
|
186
204
|
end
|
@@ -200,27 +218,6 @@ module NewRelic
|
|
200
218
|
end
|
201
219
|
end
|
202
220
|
|
203
|
-
def insert_cross_app_header request
|
204
|
-
return unless CrossAppTracing.cross_app_enabled?
|
205
|
-
|
206
|
-
transaction.is_cross_app_caller = true
|
207
|
-
txn_guid = transaction.guid
|
208
|
-
trip_id = transaction && transaction.cat_trip_id
|
209
|
-
path_hash = transaction && transaction.cat_path_hash
|
210
|
-
|
211
|
-
CrossAppTracing.insert_request_headers request, txn_guid, trip_id, path_hash
|
212
|
-
end
|
213
|
-
|
214
|
-
NEWRELIC_TRACE_HEADER = "newrelic".freeze
|
215
|
-
|
216
|
-
def insert_distributed_trace_header request
|
217
|
-
return unless Agent.config[:'distributed_tracing.enabled']
|
218
|
-
payload = transaction.create_distributed_trace_payload
|
219
|
-
request[NEWRELIC_TRACE_HEADER] = payload.http_safe if payload
|
220
|
-
end
|
221
|
-
|
222
|
-
EXTERNAL_ALL = "External/all".freeze
|
223
|
-
|
224
221
|
def add_unscoped_metrics
|
225
222
|
@unscoped_metrics = [ EXTERNAL_ALL,
|
226
223
|
"External/#{host}/all",
|
@@ -232,9 +229,6 @@ module NewRelic
|
|
232
229
|
end
|
233
230
|
end
|
234
231
|
|
235
|
-
EXTERNAL_ALL_WEB = "External/allWeb".freeze
|
236
|
-
EXTERNAL_ALL_OTHER = "External/allOther".freeze
|
237
|
-
|
238
232
|
def suffixed_rollup_metric
|
239
233
|
if Transaction.recording_web_transaction?
|
240
234
|
EXTERNAL_ALL_WEB
|
@@ -258,7 +252,6 @@ module NewRelic
|
|
258
252
|
def record_span_event
|
259
253
|
aggregator = ::NewRelic::Agent.agent.span_event_aggregator
|
260
254
|
priority = transaction.priority
|
261
|
-
|
262
255
|
aggregator.record(priority: priority) do
|
263
256
|
SpanEventPrimitive.for_external_request_segment(self)
|
264
257
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
4
|
|
5
5
|
require 'new_relic/agent/transaction/segment'
|
6
|
-
require 'new_relic/agent/cross_app_tracing'
|
6
|
+
require 'new_relic/agent/distributed_tracing/cross_app_tracing'
|
7
7
|
|
8
8
|
module NewRelic
|
9
9
|
module Agent
|
@@ -89,18 +89,10 @@ module NewRelic
|
|
89
89
|
@name
|
90
90
|
end
|
91
91
|
|
92
|
-
NEWRELIC_TRACE_KEY = "newrelic".freeze
|
93
|
-
|
94
|
-
def insert_distributed_trace_header
|
95
|
-
return unless Agent.config[:'distributed_tracing.enabled']
|
96
|
-
payload = transaction.create_distributed_trace_payload
|
97
|
-
headers[NEWRELIC_TRACE_KEY] = payload.http_safe if payload
|
98
|
-
end
|
99
|
-
|
100
92
|
def transaction_assigned
|
101
93
|
if headers && transaction && action == :produce && record_metrics?
|
102
|
-
insert_distributed_trace_header
|
103
|
-
transaction.
|
94
|
+
transaction.distributed_tracer.insert_distributed_trace_header headers
|
95
|
+
transaction.distributed_tracer.insert_cat_headers headers
|
104
96
|
end
|
105
97
|
rescue => e
|
106
98
|
NewRelic::Agent.logger.error "Error during message header processing", e
|