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
@@ -0,0 +1,80 @@
|
|
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 DistributedTraceIntrinsics
|
9
|
+
extend self
|
10
|
+
|
11
|
+
# Intrinsic Keys
|
12
|
+
INTRINSIC_KEYS = [
|
13
|
+
PARENT_TYPE_KEY = "parent.type",
|
14
|
+
PARENT_APP_KEY = "parent.app",
|
15
|
+
PARENT_ACCOUNT_ID_KEY = "parent.account",
|
16
|
+
PARENT_TRANSPORT_TYPE_KEY = "parent.transportType",
|
17
|
+
PARENT_TRANSPORT_DURATION_KEY = "parent.transportDuration",
|
18
|
+
GUID_KEY = "guid",
|
19
|
+
TRACE_ID_KEY = "traceId",
|
20
|
+
PARENT_TRANSACTION_ID_KEY = "parentId",
|
21
|
+
PARENT_SPAN_ID_KEY = "parentSpanId",
|
22
|
+
SAMPLED_KEY = "sampled",
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
# This method extracts intrinsics from the transaction_payload and
|
26
|
+
# inserts them into the specified destination.
|
27
|
+
def copy_to_hash transaction_payload, destination
|
28
|
+
return unless enabled?
|
29
|
+
INTRINSIC_KEYS.each do |key|
|
30
|
+
value = transaction_payload[key]
|
31
|
+
destination[key] = value unless value.nil?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# This method extracts intrinsics from the transaction_payload and
|
36
|
+
# inserts them as intrinsics in the specified transaction_attributes
|
37
|
+
def copy_to_attributes transaction_payload, destination
|
38
|
+
return unless enabled?
|
39
|
+
INTRINSIC_KEYS.each do |key|
|
40
|
+
next unless transaction_payload.key? key
|
41
|
+
destination.add_intrinsic_attribute key, transaction_payload[key]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# This method takes all distributed tracing intrinsics from the transaction
|
46
|
+
# and the trace_payload, and populates them into the destination
|
47
|
+
def copy_from_transaction transaction, trace_payload, destination
|
48
|
+
transport_type = transaction.distributed_tracer.caller_transport_type
|
49
|
+
destination[PARENT_TRANSPORT_TYPE_KEY] = DistributedTraceTransportType.from transport_type
|
50
|
+
|
51
|
+
destination[GUID_KEY] = transaction.guid
|
52
|
+
destination[SAMPLED_KEY] = transaction.sampled?
|
53
|
+
destination[TRACE_ID_KEY] = transaction.trace_id
|
54
|
+
|
55
|
+
if transaction.parent_span_id
|
56
|
+
destination[PARENT_SPAN_ID_KEY] = transaction.parent_span_id
|
57
|
+
end
|
58
|
+
|
59
|
+
if trace_payload
|
60
|
+
destination[PARENT_TYPE_KEY] = trace_payload.parent_type
|
61
|
+
destination[PARENT_APP_KEY] = trace_payload.parent_app_id
|
62
|
+
destination[PARENT_ACCOUNT_ID_KEY] = trace_payload.parent_account_id
|
63
|
+
|
64
|
+
destination[PARENT_TRANSPORT_DURATION_KEY] = transaction.calculate_transport_duration trace_payload
|
65
|
+
|
66
|
+
if parent_transaction_id = transaction.distributed_tracer.parent_transaction_id
|
67
|
+
destination[PARENT_TRANSACTION_ID_KEY] = parent_transaction_id
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def enabled?
|
75
|
+
return Agent.config[:'distributed_tracing.enabled']
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,75 @@
|
|
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 DistributedTraceMetrics
|
9
|
+
extend self
|
10
|
+
|
11
|
+
ALL_SUFFIX = "all"
|
12
|
+
ALL_WEB_SUFFIX = "allWeb"
|
13
|
+
ALL_OTHER_SUFFIX = "allOther"
|
14
|
+
|
15
|
+
UNKNOWN_CALLER_PREFIX = "%s/Unknown/Unknown/Unknown/%s"
|
16
|
+
|
17
|
+
def transaction_type_suffix
|
18
|
+
if Transaction.recording_web_transaction?
|
19
|
+
ALL_WEB_SUFFIX
|
20
|
+
else
|
21
|
+
ALL_OTHER_SUFFIX
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def record_metrics_for_transaction transaction
|
26
|
+
return unless Agent.config[:'distributed_tracing.enabled']
|
27
|
+
dt = transaction.distributed_tracer
|
28
|
+
payload = dt.distributed_trace_payload || dt.trace_state_payload
|
29
|
+
|
30
|
+
record_caller_by_duration_metrics transaction, payload
|
31
|
+
record_transport_duration_metrics transaction, payload
|
32
|
+
record_errors_by_caller_metrics transaction, payload
|
33
|
+
end
|
34
|
+
|
35
|
+
def prefix_for_metric name, transaction, payload
|
36
|
+
if payload
|
37
|
+
"#{name}/" \
|
38
|
+
"#{payload.parent_type}/" \
|
39
|
+
"#{payload.parent_account_id}/" \
|
40
|
+
"#{payload.parent_app_id}/" \
|
41
|
+
"#{transaction.distributed_tracer.caller_transport_type}"
|
42
|
+
else
|
43
|
+
UNKNOWN_CALLER_PREFIX % [name, transaction.distributed_tracer.caller_transport_type]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def record_caller_by_duration_metrics transaction, payload
|
48
|
+
prefix = prefix_for_metric "DurationByCaller", transaction, payload
|
49
|
+
record_unscoped_metric transaction, prefix, transaction.duration
|
50
|
+
end
|
51
|
+
|
52
|
+
def record_transport_duration_metrics transaction, payload
|
53
|
+
return unless payload
|
54
|
+
|
55
|
+
prefix = prefix_for_metric "TransportDuration", transaction, payload
|
56
|
+
duration = transaction.calculate_transport_duration payload
|
57
|
+
record_unscoped_metric transaction, prefix, duration
|
58
|
+
end
|
59
|
+
|
60
|
+
def record_errors_by_caller_metrics transaction, payload
|
61
|
+
return unless transaction.exceptions.size > 0
|
62
|
+
|
63
|
+
prefix = prefix_for_metric "ErrorsByCaller", transaction, payload
|
64
|
+
record_unscoped_metric transaction, prefix, 1
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def record_unscoped_metric transaction, prefix, duration
|
70
|
+
transaction.metrics.record_unscoped "#{prefix}/#{ALL_SUFFIX}", duration
|
71
|
+
transaction.metrics.record_unscoped "#{prefix}/#{transaction_type_suffix}", duration
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -1,9 +1,10 @@
|
|
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
|
5
|
+
|
4
6
|
require 'json'
|
5
7
|
require 'base64'
|
6
|
-
require 'set'
|
7
8
|
|
8
9
|
module NewRelic
|
9
10
|
module Agent
|
@@ -14,52 +15,25 @@ module NewRelic
|
|
14
15
|
#
|
15
16
|
# @api public
|
16
17
|
class DistributedTracePayload
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
extend Coerce
|
19
|
+
|
20
|
+
VERSION = [0, 1].freeze
|
21
|
+
PARENT_TYPE = "App"
|
22
|
+
POUND = '#'
|
20
23
|
|
21
24
|
# Key names for serialization
|
22
|
-
VERSION_KEY
|
23
|
-
DATA_KEY
|
24
|
-
PARENT_TYPE_KEY
|
25
|
-
PARENT_ACCOUNT_ID_KEY
|
26
|
-
PARENT_APP_KEY
|
27
|
-
TRUSTED_ACCOUNT_KEY
|
28
|
-
ID_KEY
|
29
|
-
TX_KEY
|
30
|
-
TRACE_ID_KEY
|
31
|
-
SAMPLED_KEY
|
32
|
-
TIMESTAMP_KEY
|
33
|
-
PRIORITY_KEY
|
34
|
-
|
35
|
-
# Intrinsic Keys
|
36
|
-
PARENT_TYPE_INTRINSIC_KEY = "parent.type".freeze
|
37
|
-
PARENT_APP_INTRINSIC_KEY = "parent.app".freeze
|
38
|
-
PARENT_ACCOUNT_ID_INTRINSIC_KEY = "parent.account".freeze
|
39
|
-
PARENT_TRANSPORT_TYPE_INTRINSIC_KEY = "parent.transportType".freeze
|
40
|
-
PARENT_TRANSPORT_DURATION_INTRINSIC_KEY = "parent.transportDuration".freeze
|
41
|
-
GUID_INTRINSIC_KEY = "guid".freeze
|
42
|
-
TRACE_ID_INTRINSIC_KEY = "traceId".freeze
|
43
|
-
PARENT_ID_INTRINSIC_KEY = "parentId".freeze
|
44
|
-
PARENT_SPAN_ID_INTRINSIC_KEY = "parentSpanId".freeze
|
45
|
-
SAMPLED_INTRINSIC_KEY = "sampled".freeze
|
46
|
-
COMMA = ",".freeze
|
47
|
-
|
48
|
-
INTRINSIC_KEYS = [
|
49
|
-
PARENT_TYPE_INTRINSIC_KEY,
|
50
|
-
PARENT_APP_INTRINSIC_KEY,
|
51
|
-
PARENT_ACCOUNT_ID_INTRINSIC_KEY,
|
52
|
-
PARENT_TRANSPORT_TYPE_INTRINSIC_KEY,
|
53
|
-
PARENT_TRANSPORT_DURATION_INTRINSIC_KEY,
|
54
|
-
GUID_INTRINSIC_KEY,
|
55
|
-
TRACE_ID_INTRINSIC_KEY,
|
56
|
-
PARENT_ID_INTRINSIC_KEY,
|
57
|
-
PARENT_SPAN_ID_INTRINSIC_KEY,
|
58
|
-
SAMPLED_INTRINSIC_KEY
|
59
|
-
].freeze
|
60
|
-
|
61
|
-
# Intrinsic Values
|
62
|
-
PARENT_TRANSPORT_TYPE_UNKNOWN = 'Unknown'.freeze
|
25
|
+
VERSION_KEY = 'v'
|
26
|
+
DATA_KEY = 'd'
|
27
|
+
PARENT_TYPE_KEY = 'ty'
|
28
|
+
PARENT_ACCOUNT_ID_KEY = 'ac'
|
29
|
+
PARENT_APP_KEY = 'ap'
|
30
|
+
TRUSTED_ACCOUNT_KEY = 'tk'
|
31
|
+
ID_KEY = 'id'
|
32
|
+
TX_KEY = 'tx'
|
33
|
+
TRACE_ID_KEY = 'tr'
|
34
|
+
SAMPLED_KEY = 'sa'
|
35
|
+
TIMESTAMP_KEY = 'ti'
|
36
|
+
PRIORITY_KEY = 'pr'
|
63
37
|
|
64
38
|
class << self
|
65
39
|
|
@@ -110,24 +84,12 @@ module NewRelic
|
|
110
84
|
from_json decoded_payload
|
111
85
|
end
|
112
86
|
|
113
|
-
def assign_initial_intrinsics transaction, transaction_payload
|
114
|
-
transaction_payload[GUID_INTRINSIC_KEY] = transaction.guid
|
115
|
-
transaction_payload[TRACE_ID_INTRINSIC_KEY] = transaction.trace_id
|
116
|
-
transaction_payload[SAMPLED_INTRINSIC_KEY] = transaction.sampled?
|
117
|
-
end
|
118
|
-
|
119
87
|
def major_version_matches?(payload)
|
120
88
|
payload.version[0] == VERSION[0]
|
121
89
|
end
|
122
90
|
|
123
91
|
private
|
124
92
|
|
125
|
-
# We use the presence of the account_id and primary_application in the
|
126
|
-
# config to tell if we have connected yet.
|
127
|
-
def connected?
|
128
|
-
Agent.config[:account_id] && Agent.config[:primary_application_id]
|
129
|
-
end
|
130
|
-
|
131
93
|
def assign_trusted_account_key payload, account_id
|
132
94
|
trusted_account_key = Agent.config[:trusted_account_key]
|
133
95
|
|
@@ -142,6 +104,10 @@ module NewRelic
|
|
142
104
|
transaction.current_segment.guid
|
143
105
|
end
|
144
106
|
end
|
107
|
+
|
108
|
+
def connected?
|
109
|
+
Agent.instance.connected?
|
110
|
+
end
|
145
111
|
end
|
146
112
|
|
147
113
|
attr_accessor :version,
|
@@ -158,16 +124,6 @@ module NewRelic
|
|
158
124
|
|
159
125
|
alias_method :sampled?, :sampled
|
160
126
|
|
161
|
-
attr_reader :caller_transport_type
|
162
|
-
|
163
|
-
def caller_transport_type=(type)
|
164
|
-
@caller_transport_type = valid_transport_type_for(type)
|
165
|
-
end
|
166
|
-
|
167
|
-
def initialize
|
168
|
-
@caller_transport_type = PARENT_TRANSPORT_TYPE_UNKNOWN
|
169
|
-
end
|
170
|
-
|
171
127
|
# Represent this payload as a raw JSON string.
|
172
128
|
#
|
173
129
|
# @return [String] Payload translated to JSON
|
@@ -205,38 +161,6 @@ module NewRelic
|
|
205
161
|
def http_safe
|
206
162
|
Base64.strict_encode64 text
|
207
163
|
end
|
208
|
-
|
209
|
-
def assign_intrinsics transaction, transaction_payload
|
210
|
-
transaction_payload[PARENT_TYPE_INTRINSIC_KEY] = parent_type
|
211
|
-
transaction_payload[PARENT_APP_INTRINSIC_KEY] = parent_app_id
|
212
|
-
transaction_payload[PARENT_ACCOUNT_ID_INTRINSIC_KEY] = parent_account_id
|
213
|
-
transaction_payload[PARENT_TRANSPORT_TYPE_INTRINSIC_KEY] = caller_transport_type
|
214
|
-
transaction_payload[PARENT_TRANSPORT_DURATION_INTRINSIC_KEY] = transaction.transport_duration
|
215
|
-
transaction_payload[GUID_INTRINSIC_KEY] = transaction.guid
|
216
|
-
transaction_payload[TRACE_ID_INTRINSIC_KEY] = trace_id
|
217
|
-
transaction_payload[PARENT_ID_INTRINSIC_KEY] = transaction.parent_id if transaction.parent_id
|
218
|
-
transaction_payload[PARENT_SPAN_ID_INTRINSIC_KEY] = id if id
|
219
|
-
transaction_payload[SAMPLED_INTRINSIC_KEY] = transaction.sampled?
|
220
|
-
end
|
221
|
-
|
222
|
-
private
|
223
|
-
|
224
|
-
ALLOWABLE_TRANSPORT_TYPES = Set.new(%w[
|
225
|
-
Unknown
|
226
|
-
HTTP
|
227
|
-
HTTPS
|
228
|
-
Kafka
|
229
|
-
JMS
|
230
|
-
IronMQ
|
231
|
-
AMQP
|
232
|
-
Queue
|
233
|
-
Other
|
234
|
-
]).freeze
|
235
|
-
|
236
|
-
def valid_transport_type_for(value)
|
237
|
-
return value if ALLOWABLE_TRANSPORT_TYPES.include?(value)
|
238
|
-
PARENT_TRANSPORT_TYPE_UNKNOWN
|
239
|
-
end
|
240
164
|
end
|
241
165
|
end
|
242
166
|
end
|
@@ -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
|