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
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
module NewRelic
|
7
|
+
module Agent
|
8
|
+
module DistributedTraceTransportType
|
9
|
+
extend self
|
10
|
+
|
11
|
+
ALLOWABLE_TRANSPORT_TYPES = [
|
12
|
+
NewRelic::UNKNOWN,
|
13
|
+
NewRelic::HTTP,
|
14
|
+
NewRelic::HTTPS,
|
15
|
+
"Kafka",
|
16
|
+
"JMS",
|
17
|
+
"IronMQ",
|
18
|
+
"AMQP",
|
19
|
+
"Queue",
|
20
|
+
"Other",
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
URL_SCHEMES = {
|
24
|
+
'http' => NewRelic::HTTP,
|
25
|
+
'https' => NewRelic::HTTPS,
|
26
|
+
}.freeze
|
27
|
+
|
28
|
+
RACK_URL_SCHEME = 'rack.url_scheme'
|
29
|
+
|
30
|
+
def from value
|
31
|
+
ALLOWABLE_TRANSPORT_TYPES.include?(value) ? value : NewRelic::UNKNOWN
|
32
|
+
end
|
33
|
+
|
34
|
+
def for_rack_request request
|
35
|
+
URL_SCHEMES[request[RACK_URL_SCHEME]]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,246 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
# frozen_string_literal: true
|
5
|
+
|
6
|
+
require_relative 'trace_context_payload'
|
7
|
+
|
8
|
+
module NewRelic
|
9
|
+
module Agent
|
10
|
+
module DistributedTracing
|
11
|
+
class TraceContext
|
12
|
+
VERSION = 0x0
|
13
|
+
|
14
|
+
COMMA = ','
|
15
|
+
EQUALS = '='
|
16
|
+
INVALID_TRACE_ID = ('0' * 32)
|
17
|
+
INVALID_PARENT_ID = ('0' * 16)
|
18
|
+
INVALID_VERSION = 'ff'
|
19
|
+
|
20
|
+
TRACE_ID_KEY = 'trace_id'
|
21
|
+
TRACE_FLAGS_KEY = 'trace_flags'
|
22
|
+
PARENT_ID_KEY = 'parent_id'
|
23
|
+
VERSION_KEY = 'version'
|
24
|
+
UNDEFINED_FIELDS_KEY = 'undefined_fields'
|
25
|
+
|
26
|
+
TP_VERSION = "(?<#{VERSION_KEY}>[a-f\\d]{2})"
|
27
|
+
TP_TRACE_ID = "(?<#{TRACE_ID_KEY}>[a-f\\d]{32})"
|
28
|
+
TP_PARENT_ID = "(?<#{PARENT_ID_KEY}>[a-f\\d]{16})"
|
29
|
+
TP_TRACE_FLAGS = "(?<#{TRACE_FLAGS_KEY}>\\d{2})"
|
30
|
+
TP_UNDEFINED_FIELDS = "(?<#{UNDEFINED_FIELDS_KEY}>-[a-zA-Z\\d-]*)"
|
31
|
+
TRACE_PARENT_REGEX = /\A#{TP_VERSION}-#{TP_TRACE_ID}-#{TP_PARENT_ID}-#{TP_TRACE_FLAGS}#{TP_UNDEFINED_FIELDS}?\z/
|
32
|
+
|
33
|
+
TRACE_PARENT_FORMAT_STRING = "%02x-%s-%s-%02x"
|
34
|
+
|
35
|
+
MAX_TRACE_STATE_SIZE = 512 # bytes
|
36
|
+
MAX_TRACE_STATE_ENTRY_SIZE = 128 # bytes
|
37
|
+
|
38
|
+
SUPPORTABILITY_TRACE_PARENT_PARSE_EXCEPTION = "Supportability/TraceContext/TraceParent/Parse/Exception"
|
39
|
+
SUPPORTABILITY_TRACE_STATE_PARSE_EXCEPTION = "Supportability/TraceContext/TraceState/Parse/Exception"
|
40
|
+
SUPPORTABILITY_TRACE_STATE_INVALID_NR_ENTRY = "Supportability/TraceContext/TraceState/InvalidNrEntry"
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def insert format: NewRelic::FORMAT_NON_RACK,
|
44
|
+
carrier: nil,
|
45
|
+
parent_id: nil,
|
46
|
+
trace_id: nil,
|
47
|
+
trace_flags: nil,
|
48
|
+
trace_state: nil
|
49
|
+
|
50
|
+
trace_parent_header = trace_parent_header_for_format format
|
51
|
+
carrier[trace_parent_header] = format_trace_parent \
|
52
|
+
trace_id: trace_id,
|
53
|
+
parent_id: parent_id,
|
54
|
+
trace_flags: trace_flags
|
55
|
+
|
56
|
+
trace_state_header = trace_state_header_for_format format
|
57
|
+
carrier[trace_state_header] = trace_state if trace_state && !trace_state.empty?
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse format: NewRelic::FORMAT_NON_RACK,
|
61
|
+
carrier: nil,
|
62
|
+
trace_state_entry_key: nil
|
63
|
+
trace_parent = extract_traceparent(format, carrier)
|
64
|
+
unless trace_parent_valid? trace_parent
|
65
|
+
NewRelic::Agent.increment_metric SUPPORTABILITY_TRACE_PARENT_PARSE_EXCEPTION
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
|
69
|
+
begin
|
70
|
+
if header_data = extract_tracestate(format, carrier, trace_state_entry_key)
|
71
|
+
header_data.trace_parent = trace_parent
|
72
|
+
header_data
|
73
|
+
end
|
74
|
+
rescue Exception
|
75
|
+
NewRelic::Agent.increment_metric SUPPORTABILITY_TRACE_STATE_PARSE_EXCEPTION
|
76
|
+
return nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def create_trace_state_entry entry_key, payload
|
81
|
+
"#{entry_key}=#{payload}".dup
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def format_trace_parent trace_id: nil,
|
87
|
+
parent_id: nil,
|
88
|
+
trace_flags: nil
|
89
|
+
sprintf TRACE_PARENT_FORMAT_STRING,
|
90
|
+
VERSION,
|
91
|
+
trace_id,
|
92
|
+
parent_id,
|
93
|
+
trace_flags
|
94
|
+
end
|
95
|
+
|
96
|
+
def extract_traceparent format, carrier
|
97
|
+
header_name = trace_parent_header_for_format format
|
98
|
+
return unless header = carrier[header_name]
|
99
|
+
if matchdata = header.match(TRACE_PARENT_REGEX)
|
100
|
+
TRACE_PARENT_REGEX.named_captures.inject({}) do |hash, (name, (index))|
|
101
|
+
hash[name] = matchdata[index]
|
102
|
+
hash
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def trace_parent_valid? trace_parent
|
108
|
+
return false if trace_parent.nil?
|
109
|
+
return false if trace_parent[TRACE_ID_KEY] == INVALID_TRACE_ID
|
110
|
+
return false if trace_parent[PARENT_ID_KEY] == INVALID_PARENT_ID
|
111
|
+
return false if trace_parent[VERSION_KEY] == INVALID_VERSION
|
112
|
+
return false if trace_parent[VERSION_KEY].to_i(16) == VERSION && !trace_parent[UNDEFINED_FIELDS_KEY].nil?
|
113
|
+
|
114
|
+
true
|
115
|
+
end
|
116
|
+
|
117
|
+
def trace_parent_header_for_format format
|
118
|
+
if format == NewRelic::FORMAT_RACK
|
119
|
+
NewRelic::HTTP_TRACEPARENT_KEY
|
120
|
+
else
|
121
|
+
NewRelic::TRACEPARENT_KEY
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def trace_state_header_for_format format
|
126
|
+
if format == NewRelic::FORMAT_RACK
|
127
|
+
NewRelic::HTTP_TRACESTATE_KEY
|
128
|
+
else
|
129
|
+
NewRelic::TRACESTATE_KEY
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def extract_tracestate format, carrier, trace_state_entry_key
|
134
|
+
header_name = trace_state_header_for_format format
|
135
|
+
header = carrier[header_name]
|
136
|
+
return HeaderData.create if header.nil? || header.empty?
|
137
|
+
|
138
|
+
payload = nil
|
139
|
+
trace_state_size = 0
|
140
|
+
trace_state_vendors = String.new
|
141
|
+
trace_state = header.split(COMMA).map(&:strip)
|
142
|
+
trace_state.reject! do |entry|
|
143
|
+
if entry == NewRelic::EMPTY_STR
|
144
|
+
false
|
145
|
+
else
|
146
|
+
vendor_id = entry.slice 0, entry.index(EQUALS)
|
147
|
+
if vendor_id == trace_state_entry_key
|
148
|
+
payload = entry.slice! trace_state_entry_key.size + 1, entry.size
|
149
|
+
true
|
150
|
+
else
|
151
|
+
trace_state_size += entry.size
|
152
|
+
trace_state_vendors << vendor_id << COMMA
|
153
|
+
false
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
trace_state_vendors.chomp! COMMA
|
159
|
+
|
160
|
+
HeaderData.create trace_state_payload: payload ? decode_payload(payload) : nil,
|
161
|
+
trace_state_entries: trace_state,
|
162
|
+
trace_state_size: trace_state_size,
|
163
|
+
trace_state_vendors: trace_state_vendors
|
164
|
+
end
|
165
|
+
|
166
|
+
def decode_payload payload
|
167
|
+
TraceContextPayload.from_s payload
|
168
|
+
rescue
|
169
|
+
if payload
|
170
|
+
NewRelic::Agent.increment_metric SUPPORTABILITY_TRACE_STATE_INVALID_NR_ENTRY
|
171
|
+
end
|
172
|
+
return nil
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
class HeaderData
|
177
|
+
class << self
|
178
|
+
def create trace_parent: nil,
|
179
|
+
trace_state_payload: nil,
|
180
|
+
trace_state_entries: nil,
|
181
|
+
trace_state_size: 0,
|
182
|
+
trace_state_vendors: nil
|
183
|
+
new trace_parent, \
|
184
|
+
trace_state_payload, \
|
185
|
+
trace_state_entries, \
|
186
|
+
trace_state_size, \
|
187
|
+
trace_state_vendors
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def initialize trace_parent, trace_state_payload, trace_state_entries, trace_state_size, trace_state_vendors
|
192
|
+
@trace_parent = trace_parent
|
193
|
+
@trace_state = nil
|
194
|
+
@trace_state_entries = trace_state_entries
|
195
|
+
@trace_state_payload = trace_state_payload
|
196
|
+
@trace_state_size = trace_state_size
|
197
|
+
@trace_state_vendors = trace_state_vendors
|
198
|
+
end
|
199
|
+
|
200
|
+
attr_accessor :trace_parent, :trace_state_payload, :trace_state_vendors
|
201
|
+
|
202
|
+
def trace_state trace_state_entry
|
203
|
+
@trace_state ||= join_trace_state trace_state_entry.size
|
204
|
+
@trace_state_entries = nil
|
205
|
+
|
206
|
+
trace_state_entry << @trace_state
|
207
|
+
end
|
208
|
+
|
209
|
+
def trace_id
|
210
|
+
@trace_parent[TRACE_ID_KEY]
|
211
|
+
end
|
212
|
+
|
213
|
+
def parent_id
|
214
|
+
@trace_parent[PARENT_ID_KEY]
|
215
|
+
end
|
216
|
+
|
217
|
+
private
|
218
|
+
|
219
|
+
def join_trace_state trace_state_entry_size
|
220
|
+
return @trace_state || NewRelic::EMPTY_STR if @trace_state_entries.nil? || @trace_state_entries.empty?
|
221
|
+
|
222
|
+
max_size = MAX_TRACE_STATE_SIZE - trace_state_entry_size
|
223
|
+
return @trace_state_entries.join(COMMA).prepend(COMMA) if @trace_state_size < max_size
|
224
|
+
|
225
|
+
joined_trace_state = ''.dup
|
226
|
+
|
227
|
+
used_size = 0
|
228
|
+
|
229
|
+
@trace_state_entries.each do |entry|
|
230
|
+
entry_size = entry.size + 1
|
231
|
+
break if used_size + entry_size > max_size
|
232
|
+
next if entry_size > MAX_TRACE_STATE_ENTRY_SIZE
|
233
|
+
|
234
|
+
joined_trace_state << COMMA << entry
|
235
|
+
used_size += entry_size
|
236
|
+
end
|
237
|
+
|
238
|
+
joined_trace_state
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under New Relic's license terms.
|
3
|
+
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
|
+
|
5
|
+
require 'new_relic/coerce'
|
6
|
+
|
7
|
+
module NewRelic
|
8
|
+
module Agent
|
9
|
+
class TraceContextPayload
|
10
|
+
VERSION = 0
|
11
|
+
PARENT_TYPE = 0
|
12
|
+
DELIMITER = "-".freeze
|
13
|
+
SUPPORTABILITY_PARSE_EXCEPTION = "Supportability/TraceContext/Parse/Exception".freeze
|
14
|
+
|
15
|
+
TRUE_CHAR = '1'.freeze
|
16
|
+
FALSE_CHAR = '0'.freeze
|
17
|
+
|
18
|
+
PARENT_TYPES = %w(App Browser Mobile).map(&:freeze).freeze
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def create version: VERSION,
|
22
|
+
parent_type: PARENT_TYPE,
|
23
|
+
parent_account_id: nil,
|
24
|
+
parent_app_id: nil,
|
25
|
+
id: nil,
|
26
|
+
transaction_id: nil,
|
27
|
+
sampled: nil,
|
28
|
+
priority: nil,
|
29
|
+
timestamp: now_ms
|
30
|
+
|
31
|
+
new version, parent_type, parent_account_id, parent_app_id, id,
|
32
|
+
transaction_id, sampled, priority, timestamp
|
33
|
+
end
|
34
|
+
|
35
|
+
include NewRelic::Coerce
|
36
|
+
|
37
|
+
def from_s payload_string
|
38
|
+
attrs = payload_string.split(DELIMITER)
|
39
|
+
|
40
|
+
payload = create \
|
41
|
+
version: int!(attrs[0]),
|
42
|
+
parent_type: int!(attrs[1]),
|
43
|
+
parent_account_id: attrs[2],
|
44
|
+
parent_app_id: attrs[3],
|
45
|
+
id: value_or_nil(attrs[4]),
|
46
|
+
transaction_id: value_or_nil(attrs[5]),
|
47
|
+
sampled: value_or_nil(attrs[6]) ? boolean_int!(attrs[6]) == 1 : nil,
|
48
|
+
priority: float!(attrs[7]),
|
49
|
+
timestamp: int!(attrs[8])
|
50
|
+
handle_invalid_payload message: 'payload missing attributes' unless payload.valid?
|
51
|
+
payload
|
52
|
+
rescue => e
|
53
|
+
handle_invalid_payload error: e
|
54
|
+
raise
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def now_ms
|
60
|
+
(Time.now.to_f * 1000).round
|
61
|
+
end
|
62
|
+
|
63
|
+
def handle_invalid_payload error: nil, message: nil
|
64
|
+
NewRelic::Agent.increment_metric SUPPORTABILITY_PARSE_EXCEPTION
|
65
|
+
if error
|
66
|
+
NewRelic::Agent.logger.warn "Error parsing trace context payload", error
|
67
|
+
elsif message
|
68
|
+
NewRelic::Agent.logger.warn "Error parsing trace context payload: #{message}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
attr_accessor :version,
|
74
|
+
:parent_type_id,
|
75
|
+
:parent_account_id,
|
76
|
+
:parent_app_id,
|
77
|
+
:id,
|
78
|
+
:transaction_id,
|
79
|
+
:sampled,
|
80
|
+
:priority,
|
81
|
+
:timestamp
|
82
|
+
|
83
|
+
alias_method :sampled?, :sampled
|
84
|
+
|
85
|
+
def initialize version, parent_type_id, parent_account_id, parent_app_id,
|
86
|
+
id, transaction_id, sampled, priority, timestamp
|
87
|
+
@version = version
|
88
|
+
@parent_type_id = parent_type_id
|
89
|
+
@parent_account_id = parent_account_id
|
90
|
+
@parent_app_id = parent_app_id
|
91
|
+
@id = id
|
92
|
+
@transaction_id = transaction_id
|
93
|
+
@sampled = sampled
|
94
|
+
@priority = priority
|
95
|
+
@timestamp = timestamp
|
96
|
+
end
|
97
|
+
|
98
|
+
def parent_type
|
99
|
+
@parent_type_string ||= PARENT_TYPES[@parent_type_id]
|
100
|
+
end
|
101
|
+
|
102
|
+
def valid?
|
103
|
+
version \
|
104
|
+
&& parent_type_id \
|
105
|
+
&& !parent_account_id.empty? \
|
106
|
+
&& !parent_app_id.empty? \
|
107
|
+
&& timestamp
|
108
|
+
rescue
|
109
|
+
false
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_s
|
113
|
+
result = version.to_s
|
114
|
+
result << DELIMITER << parent_type_id.to_s
|
115
|
+
result << DELIMITER << parent_account_id
|
116
|
+
result << DELIMITER << parent_app_id
|
117
|
+
result << DELIMITER << (id || NewRelic::EMPTY_STR)
|
118
|
+
result << DELIMITER << (transaction_id || NewRelic::EMPTY_STR)
|
119
|
+
result << DELIMITER << (sampled ? TRUE_CHAR : FALSE_CHAR)
|
120
|
+
result << DELIMITER << sprintf("%.6f", priority)
|
121
|
+
result << DELIMITER << timestamp.to_s
|
122
|
+
result
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -32,7 +32,6 @@ module NewRelic
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
35
|
def initialize_ignored_errors(ignore_errors)
|
37
36
|
@ignore.clear
|
38
37
|
ignore_errors = ignore_errors.split(",") if ignore_errors.is_a? String
|
@@ -74,7 +73,7 @@ module NewRelic
|
|
74
73
|
end
|
75
74
|
|
76
75
|
def self.ignore_error_filter
|
77
|
-
@ignore_filter
|
76
|
+
defined?(@ignore_filter) ? @ignore_filter : nil
|
78
77
|
end
|
79
78
|
|
80
79
|
# errors is an array of Exception Class Names
|
@@ -117,14 +116,22 @@ module NewRelic
|
|
117
116
|
NewRelic::LanguageSupport.jruby? && exception.respond_to?(:java_class)
|
118
117
|
end
|
119
118
|
|
120
|
-
def
|
119
|
+
def exception_tagged_with?(ivar, exception)
|
121
120
|
return false if exception_is_java_object?(exception)
|
122
|
-
exception.instance_variable_defined?(
|
121
|
+
exception.instance_variable_defined?(ivar)
|
122
|
+
end
|
123
|
+
|
124
|
+
def tag_exception_using(ivar, exception)
|
125
|
+
return if exception_is_java_object?(exception) || exception.frozen?
|
126
|
+
begin
|
127
|
+
exception.instance_variable_set(ivar, true)
|
128
|
+
rescue => e
|
129
|
+
NewRelic::Agent.logger.warn("Failed to tag exception: #{exception}: ", e)
|
130
|
+
end
|
123
131
|
end
|
124
132
|
|
125
133
|
def tag_exception(exception)
|
126
|
-
return if exception_is_java_object?(exception)
|
127
|
-
return if exception.frozen?
|
134
|
+
return if exception_is_java_object?(exception) || exception.frozen?
|
128
135
|
begin
|
129
136
|
exception.instance_variable_set(EXCEPTION_TAG_IVAR, true)
|
130
137
|
rescue => e
|
@@ -169,9 +176,9 @@ module NewRelic
|
|
169
176
|
|
170
177
|
def skip_notice_error?(exception)
|
171
178
|
disabled? ||
|
172
|
-
|
173
|
-
|
174
|
-
|
179
|
+
error_is_ignored?(exception) ||
|
180
|
+
exception.nil? ||
|
181
|
+
exception_tagged_with?(EXCEPTION_TAG_IVAR, exception)
|
175
182
|
end
|
176
183
|
|
177
184
|
# calls a method on an object, if it responds to it - used for
|
@@ -191,8 +198,18 @@ module NewRelic
|
|
191
198
|
sense_method(actual_exception, :backtrace) || '<no stack trace>'
|
192
199
|
end
|
193
200
|
|
201
|
+
def notice_segment_error(segment, exception, options={})
|
202
|
+
return if skip_notice_error?(exception)
|
203
|
+
|
204
|
+
segment.set_noticed_error create_noticed_error(exception, options)
|
205
|
+
exception
|
206
|
+
rescue => e
|
207
|
+
::NewRelic::Agent.logger.warn("Failure when capturing segment error '#{exception}':", e)
|
208
|
+
nil
|
209
|
+
end
|
210
|
+
|
194
211
|
# See NewRelic::Agent.notice_error for options and commentary
|
195
|
-
def notice_error(exception, options={})
|
212
|
+
def notice_error(exception, options={}, span_id=nil)
|
196
213
|
return if skip_notice_error?(exception)
|
197
214
|
|
198
215
|
tag_exception(exception)
|
@@ -205,8 +222,10 @@ module NewRelic
|
|
205
222
|
|
206
223
|
noticed_error = create_noticed_error(exception, options)
|
207
224
|
error_trace_aggregator.add_to_error_queue(noticed_error)
|
208
|
-
|
209
|
-
|
225
|
+
transaction = state.current_transaction
|
226
|
+
payload = transaction ? transaction.payload : nil
|
227
|
+
span_id ||= (transaction && transaction.current_segment) ? transaction.current_segment.guid : nil
|
228
|
+
error_event_aggregator.record(noticed_error, payload, span_id)
|
210
229
|
exception
|
211
230
|
rescue => e
|
212
231
|
::NewRelic::Agent.logger.warn("Failure when capturing error '#{exception}':", e)
|
@@ -227,13 +246,11 @@ module NewRelic
|
|
227
246
|
truncated_trace
|
228
247
|
end
|
229
248
|
|
230
|
-
EMPTY_STRING = ''.freeze
|
231
|
-
|
232
249
|
def create_noticed_error(exception, options)
|
233
|
-
error_metric = options.delete(:metric) ||
|
250
|
+
error_metric = options.delete(:metric) || NewRelic::EMPTY_STR
|
234
251
|
|
235
252
|
noticed_error = NewRelic::NoticedError.new(error_metric, exception)
|
236
|
-
noticed_error.request_uri = options.delete(:uri) ||
|
253
|
+
noticed_error.request_uri = options.delete(:uri) || NewRelic::EMPTY_STR
|
237
254
|
noticed_error.request_port = options.delete(:port)
|
238
255
|
noticed_error.attributes = options.delete(:attributes)
|
239
256
|
|