newrelic_rpm 6.3.0.355 → 6.8.0.360
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 +50 -10
- data/CHANGELOG.md +198 -0
- data/Guardfile +7 -1
- data/lib/new_relic/agent.rb +80 -0
- data/lib/new_relic/agent/agent.rb +87 -26
- 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 +152 -0
- data/lib/new_relic/agent/autostart.rb +19 -14
- data/lib/new_relic/agent/commands/agent_command_router.rb +2 -21
- data/lib/new_relic/agent/configuration/default_source.rb +129 -39
- data/lib/new_relic/agent/configuration/environment_source.rb +4 -2
- data/lib/new_relic/agent/configuration/event_harvest_config.rb +45 -0
- data/lib/new_relic/agent/configuration/high_security_source.rb +1 -0
- data/lib/new_relic/agent/configuration/manager.rb +13 -9
- data/lib/new_relic/agent/configuration/server_source.rb +33 -9
- data/lib/new_relic/agent/configuration/yaml_source.rb +10 -5
- data/lib/new_relic/agent/connect/request_builder.rb +11 -13
- data/lib/new_relic/agent/connect/response_handler.rb +1 -1
- data/lib/new_relic/agent/cross_app_monitor.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_trace_intrinsics.rb +90 -0
- data/lib/new_relic/agent/distributed_trace_metrics.rb +74 -0
- data/lib/new_relic/agent/distributed_trace_monitor.rb +2 -12
- data/lib/new_relic/agent/distributed_trace_payload.rb +9 -76
- data/lib/new_relic/agent/distributed_trace_transport_type.rb +43 -0
- data/lib/new_relic/agent/error_collector.rb +2 -2
- data/lib/new_relic/agent/error_event_aggregator.rb +2 -1
- 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/guid_generator.rb +28 -0
- data/lib/new_relic/agent/inbound_request_monitor.rb +2 -2
- data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +24 -42
- data/lib/new_relic/agent/instrumentation/action_controller_subscriber.rb +45 -69
- data/lib/new_relic/agent/instrumentation/action_view_subscriber.rb +70 -53
- data/lib/new_relic/agent/instrumentation/active_record_notifications.rb +25 -18
- data/lib/new_relic/agent/instrumentation/active_record_subscriber.rb +33 -47
- data/lib/new_relic/agent/instrumentation/active_storage_subscriber.rb +4 -4
- data/lib/new_relic/agent/instrumentation/grape.rb +2 -3
- data/lib/new_relic/agent/instrumentation/{evented_subscriber.rb → notifications_subscriber.rb} +7 -66
- data/lib/new_relic/agent/instrumentation/rails_notifications/action_cable.rb +2 -3
- data/lib/new_relic/agent/javascript_instrumentor.rb +1 -1
- data/lib/new_relic/agent/logging.rb +129 -0
- data/lib/new_relic/agent/new_relic_service.rb +7 -9
- data/lib/new_relic/agent/priority_sampled_buffer.rb +2 -0
- data/lib/new_relic/agent/span_event_aggregator.rb +2 -4
- data/lib/new_relic/agent/span_event_primitive.rb +29 -7
- data/lib/new_relic/agent/sql_sampler.rb +1 -1
- data/lib/new_relic/agent/threading/backtrace_service.rb +3 -3
- data/lib/new_relic/agent/threading/thread_profile.rb +9 -23
- data/lib/new_relic/agent/trace_context.rb +244 -0
- data/lib/new_relic/agent/trace_context_payload.rb +134 -0
- data/lib/new_relic/agent/trace_context_request_monitor.rb +42 -0
- data/lib/new_relic/agent/tracer.rb +32 -0
- data/lib/new_relic/agent/transaction.rb +26 -20
- data/lib/new_relic/agent/transaction/abstract_segment.rb +2 -2
- data/lib/new_relic/agent/transaction/distributed_tracing.rb +20 -101
- data/lib/new_relic/agent/transaction/external_request_segment.rb +18 -5
- data/lib/new_relic/agent/transaction/segment.rb +7 -1
- data/lib/new_relic/agent/transaction/trace.rb +3 -8
- data/lib/new_relic/agent/transaction/trace_builder.rb +0 -1
- data/lib/new_relic/agent/transaction/trace_context.rb +159 -0
- data/lib/new_relic/agent/transaction/trace_node.rb +8 -3
- data/lib/new_relic/agent/transaction_error_primitive.rb +4 -11
- data/lib/new_relic/agent/transaction_event_primitive.rb +3 -11
- data/lib/new_relic/agent/transaction_event_recorder.rb +3 -3
- data/lib/new_relic/agent/transaction_sampler.rb +1 -5
- data/lib/new_relic/cli/commands/deployments.rb +1 -1
- data/lib/new_relic/coerce.rb +29 -6
- 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 +8 -4
- data/lib/new_relic/rack/browser_monitoring.rb +10 -8
- data/lib/new_relic/version.rb +1 -1
- data/lib/tasks/config.rake +1 -2
- data/newrelic_rpm.gemspec +13 -4
- data/test/agent_helper.rb +95 -9
- data/true +0 -0
- metadata +58 -24
- data/lib/new_relic/agent/commands/xray_session.rb +0 -55
- data/lib/new_relic/agent/commands/xray_session_collection.rb +0 -161
- data/lib/new_relic/agent/configuration/event_data.rb +0 -39
- data/lib/new_relic/agent/transaction/attributes.rb +0 -154
- data/lib/new_relic/agent/transaction/xray_sample_buffer.rb +0 -64
- 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,134 @@
|
|
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/agent/distributed_trace_transport_type'
|
6
|
+
require 'new_relic/coerce'
|
7
|
+
|
8
|
+
module NewRelic
|
9
|
+
module Agent
|
10
|
+
class TraceContextPayload
|
11
|
+
VERSION = 0
|
12
|
+
PARENT_TYPE = 0
|
13
|
+
DELIMITER = "-".freeze
|
14
|
+
SUPPORTABILITY_PARSE_EXCEPTION = "Supportability/TraceContext/Parse/Exception".freeze
|
15
|
+
|
16
|
+
TRUE_CHAR = '1'.freeze
|
17
|
+
FALSE_CHAR = '0'.freeze
|
18
|
+
|
19
|
+
PARENT_TYPES = %w(App Browser Mobile).map(&:freeze).freeze
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def create version: VERSION,
|
23
|
+
parent_type: PARENT_TYPE,
|
24
|
+
parent_account_id: nil,
|
25
|
+
parent_app_id: nil,
|
26
|
+
id: nil,
|
27
|
+
transaction_id: nil,
|
28
|
+
sampled: nil,
|
29
|
+
priority: nil,
|
30
|
+
timestamp: now_ms
|
31
|
+
|
32
|
+
new version, parent_type, parent_account_id, parent_app_id, id,
|
33
|
+
transaction_id, sampled, priority, timestamp
|
34
|
+
end
|
35
|
+
|
36
|
+
include NewRelic::Coerce
|
37
|
+
|
38
|
+
def from_s payload_string
|
39
|
+
attrs = payload_string.split(DELIMITER)
|
40
|
+
|
41
|
+
payload = create \
|
42
|
+
version: int!(attrs[0]),
|
43
|
+
parent_type: int!(attrs[1]),
|
44
|
+
parent_account_id: attrs[2],
|
45
|
+
parent_app_id: attrs[3],
|
46
|
+
id: value_or_nil(attrs[4]),
|
47
|
+
transaction_id: value_or_nil(attrs[5]),
|
48
|
+
sampled: value_or_nil(attrs[6]) ? boolean_int!(attrs[6]) == 1 : nil,
|
49
|
+
priority: float!(attrs[7]),
|
50
|
+
timestamp: int!(attrs[8])
|
51
|
+
handle_invalid_payload message: 'payload missing attributes' unless payload.valid?
|
52
|
+
payload
|
53
|
+
rescue => e
|
54
|
+
handle_invalid_payload error: e
|
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
|
+
attr_reader :caller_transport_type
|
99
|
+
|
100
|
+
def caller_transport_type= type
|
101
|
+
@caller_transport_type = DistributedTraceTransportType.from type
|
102
|
+
end
|
103
|
+
|
104
|
+
def parent_type
|
105
|
+
@parent_type_string ||= PARENT_TYPES[@parent_type_id]
|
106
|
+
end
|
107
|
+
|
108
|
+
def valid?
|
109
|
+
version \
|
110
|
+
&& parent_type_id \
|
111
|
+
&& !parent_account_id.empty? \
|
112
|
+
&& !parent_app_id.empty? \
|
113
|
+
&& timestamp
|
114
|
+
rescue
|
115
|
+
false
|
116
|
+
end
|
117
|
+
|
118
|
+
EMPTY = "".freeze
|
119
|
+
|
120
|
+
def to_s
|
121
|
+
result = version.to_s
|
122
|
+
result << DELIMITER << parent_type_id.to_s
|
123
|
+
result << DELIMITER << parent_account_id
|
124
|
+
result << DELIMITER << parent_app_id
|
125
|
+
result << DELIMITER << (id || EMPTY)
|
126
|
+
result << DELIMITER << (transaction_id || EMPTY)
|
127
|
+
result << DELIMITER << (sampled ? TRUE_CHAR : FALSE_CHAR)
|
128
|
+
result << DELIMITER << priority.to_s
|
129
|
+
result << DELIMITER << timestamp.to_s
|
130
|
+
result
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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/agent/distributed_trace_transport_type'
|
6
|
+
require 'new_relic/agent/inbound_request_monitor'
|
7
|
+
require 'new_relic/agent/trace_context'
|
8
|
+
|
9
|
+
module NewRelic
|
10
|
+
module Agent
|
11
|
+
class TraceContextRequestMonitor < InboundRequestMonitor
|
12
|
+
TRACEPARENT = 'HTTP_TRACEPARENT'.freeze
|
13
|
+
|
14
|
+
def on_finished_configuring(events)
|
15
|
+
return unless enabled?
|
16
|
+
events.subscribe(:before_call, &method(:on_before_call))
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_before_call(request)
|
20
|
+
return unless enabled? && request[TRACEPARENT]
|
21
|
+
trace_context = TraceContext.parse(
|
22
|
+
format: TraceContext::FORMAT_RACK,
|
23
|
+
carrier: request,
|
24
|
+
trace_state_entry_key: TraceContext::AccountHelpers.trace_state_entry_key,
|
25
|
+
)
|
26
|
+
return if trace_context.nil?
|
27
|
+
|
28
|
+
return unless txn = Tracer.current_transaction
|
29
|
+
|
30
|
+
if txn.accept_trace_context trace_context
|
31
|
+
txn.trace_state_payload.caller_transport_type = DistributedTraceTransportType.for_rack_request(request)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
W3C_FORMAT = "w3c".freeze
|
36
|
+
|
37
|
+
def enabled?
|
38
|
+
NewRelic::Agent.config[:'distributed_tracing.enabled'] && (NewRelic::Agent.config[:'distributed_tracing.format'] == W3C_FORMAT)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -39,6 +39,38 @@ module NewRelic
|
|
39
39
|
state.current_transaction
|
40
40
|
end
|
41
41
|
|
42
|
+
# Returns the trace_id of the current_transaction, or +nil+ if
|
43
|
+
# none exists.
|
44
|
+
#
|
45
|
+
# @api public
|
46
|
+
def current_trace_id
|
47
|
+
if txn = current_transaction
|
48
|
+
txn.trace_id
|
49
|
+
end
|
50
|
+
end
|
51
|
+
alias_method :trace_id, :current_trace_id
|
52
|
+
|
53
|
+
# Returns the id of the current span, or +nil+ if none exists.
|
54
|
+
#
|
55
|
+
# @api public
|
56
|
+
def current_span_id
|
57
|
+
if span = current_segment
|
58
|
+
span.guid
|
59
|
+
end
|
60
|
+
end
|
61
|
+
alias_method :span_id, :current_span_id
|
62
|
+
|
63
|
+
# Returns a boolean indicating whether the current_transaction
|
64
|
+
# is sampled, or +nil+ if there is no current transaction.
|
65
|
+
#
|
66
|
+
# @api public
|
67
|
+
def transaction_sampled?
|
68
|
+
if txn = current_transaction
|
69
|
+
txn.sampled?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
alias_method :sampled?, :transaction_sampled?
|
73
|
+
|
42
74
|
# Runs the given block of code in a transaction.
|
43
75
|
#
|
44
76
|
# @param [String] name reserved for New Relic internal use
|
@@ -5,13 +5,15 @@
|
|
5
5
|
require 'new_relic/agent/instrumentation/queue_time'
|
6
6
|
require 'new_relic/agent/transaction_metrics'
|
7
7
|
require 'new_relic/agent/method_tracer_helpers'
|
8
|
-
require 'new_relic/agent/
|
8
|
+
require 'new_relic/agent/attributes'
|
9
9
|
require 'new_relic/agent/transaction/request_attributes'
|
10
10
|
require 'new_relic/agent/transaction/tracing'
|
11
|
+
require 'new_relic/agent/transaction/trace_context'
|
11
12
|
require 'new_relic/agent/transaction/distributed_tracing'
|
12
13
|
require 'new_relic/agent/cross_app_tracing'
|
13
14
|
require 'new_relic/agent/transaction_time_aggregator'
|
14
15
|
require 'new_relic/agent/deprecator'
|
16
|
+
require 'new_relic/agent/guid_generator'
|
15
17
|
|
16
18
|
module NewRelic
|
17
19
|
module Agent
|
@@ -21,6 +23,7 @@ module NewRelic
|
|
21
23
|
# @api public
|
22
24
|
class Transaction
|
23
25
|
include Tracing
|
26
|
+
include TraceContext
|
24
27
|
include DistributedTracing
|
25
28
|
include CrossAppTracing
|
26
29
|
|
@@ -70,7 +73,9 @@ module NewRelic
|
|
70
73
|
:nesting_max_depth,
|
71
74
|
:segments,
|
72
75
|
:end_time,
|
73
|
-
:duration
|
76
|
+
:duration,
|
77
|
+
:parent_transaction_id,
|
78
|
+
:parent_span_id
|
74
79
|
|
75
80
|
attr_writer :sampled,
|
76
81
|
:priority
|
@@ -242,7 +247,7 @@ module NewRelic
|
|
242
247
|
|
243
248
|
@exceptions = {}
|
244
249
|
@metrics = TransactionMetrics.new
|
245
|
-
@guid = generate_guid
|
250
|
+
@guid = NewRelic::Agent::GuidGenerator.generate_guid
|
246
251
|
|
247
252
|
@ignore_this_transaction = false
|
248
253
|
@ignore_apdex = options.fetch(:ignore_apdex, false)
|
@@ -273,6 +278,10 @@ module NewRelic
|
|
273
278
|
@sampled
|
274
279
|
end
|
275
280
|
|
281
|
+
def trace_id
|
282
|
+
@trace_id ||= NewRelic::Agent::GuidGenerator.generate_guid 32
|
283
|
+
end
|
284
|
+
|
276
285
|
def priority
|
277
286
|
if @priority.nil?
|
278
287
|
@priority = rand.round(6)
|
@@ -355,8 +364,6 @@ module NewRelic
|
|
355
364
|
|
356
365
|
# For common interface with Trace
|
357
366
|
alias_method :transaction_name, :best_name
|
358
|
-
|
359
|
-
attr_accessor :xray_session_id
|
360
367
|
# End common interface
|
361
368
|
|
362
369
|
def promoted_transaction_name(name)
|
@@ -526,7 +533,7 @@ module NewRelic
|
|
526
533
|
record_apdex unless ignore_apdex?
|
527
534
|
record_queue_time
|
528
535
|
record_cross_app_metrics
|
529
|
-
|
536
|
+
DistributedTraceMetrics.record_metrics_for_transaction self
|
530
537
|
|
531
538
|
record_exceptions
|
532
539
|
record_transaction_event
|
@@ -578,8 +585,8 @@ module NewRelic
|
|
578
585
|
attributes.add_intrinsic_attribute(:synthetics_monitor_id, synthetics_monitor_id)
|
579
586
|
end
|
580
587
|
|
581
|
-
if Agent.config[:'distributed_tracing.enabled']
|
582
|
-
|
588
|
+
if Agent.config[:'distributed_tracing.enabled'] || trace_context_enabled?
|
589
|
+
DistributedTraceIntrinsics.copy_to_attributes @payload, attributes
|
583
590
|
elsif is_cross_app?
|
584
591
|
assign_cross_app_intrinsics
|
585
592
|
end
|
@@ -590,6 +597,16 @@ module NewRelic
|
|
590
597
|
NewRelic::Agent::StatsEngine::GCProfiler.record_delta(gc_start_snapshot, gc_stop_snapshot)
|
591
598
|
end
|
592
599
|
|
600
|
+
# This method returns transport_duration in seconds. Transport duration
|
601
|
+
# is stored in milliseconds on the payload, but it's needed in seconds
|
602
|
+
# for metrics and intrinsics.
|
603
|
+
def calculate_transport_duration distributed_trace_payload
|
604
|
+
return unless distributed_trace_payload
|
605
|
+
|
606
|
+
duration = (start_time.to_f * 1000 - distributed_trace_payload.timestamp) / 1000
|
607
|
+
duration < 0 ? 0 : duration
|
608
|
+
end
|
609
|
+
|
593
610
|
# The summary metrics recorded by this method all end up with a duration
|
594
611
|
# equal to the transaction itself, and an exclusive time of zero.
|
595
612
|
def record_summary_metrics(outermost_node_name)
|
@@ -618,6 +635,7 @@ module NewRelic
|
|
618
635
|
|
619
636
|
append_cat_info(@payload)
|
620
637
|
append_distributed_trace_info(@payload)
|
638
|
+
append_trace_context_info(@payload)
|
621
639
|
append_apdex_perf_zone(@payload)
|
622
640
|
append_synthetics_to(@payload)
|
623
641
|
end
|
@@ -907,18 +925,6 @@ module NewRelic
|
|
907
925
|
def sql_sampler
|
908
926
|
agent.sql_sampler
|
909
927
|
end
|
910
|
-
|
911
|
-
HEX_DIGITS = (0..15).map{|i| i.to_s(16)}
|
912
|
-
GUID_LENGTH = 16
|
913
|
-
|
914
|
-
# generate a random 64 bit uuid
|
915
|
-
def generate_guid
|
916
|
-
guid = ''
|
917
|
-
GUID_LENGTH.times do |a|
|
918
|
-
guid << HEX_DIGITS[rand(16)]
|
919
|
-
end
|
920
|
-
guid
|
921
|
-
end
|
922
928
|
end
|
923
929
|
end
|
924
930
|
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/range_extensions'
|
6
|
-
require '
|
6
|
+
require 'new_relic/agent/guid_generator'
|
7
7
|
|
8
8
|
module NewRelic
|
9
9
|
module Agent
|
@@ -27,7 +27,7 @@ module NewRelic
|
|
27
27
|
def initialize name=nil, start_time=nil
|
28
28
|
@name = name
|
29
29
|
@transaction = nil
|
30
|
-
@guid =
|
30
|
+
@guid = NewRelic::Agent::GuidGenerator.generate_guid
|
31
31
|
@parent = nil
|
32
32
|
@params = nil
|
33
33
|
@start_time = start_time if start_time
|
@@ -3,6 +3,8 @@
|
|
3
3
|
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.
|
4
4
|
|
5
5
|
require 'new_relic/agent/distributed_trace_payload'
|
6
|
+
require 'new_relic/agent/distributed_trace_intrinsics'
|
7
|
+
require 'new_relic/agent/distributed_trace_metrics'
|
6
8
|
|
7
9
|
module NewRelic
|
8
10
|
module Agent
|
@@ -10,15 +12,14 @@ module NewRelic
|
|
10
12
|
module DistributedTracing
|
11
13
|
attr_accessor :distributed_trace_payload
|
12
14
|
|
13
|
-
def distributed_trace?
|
14
|
-
!!distributed_trace_payload
|
15
|
-
end
|
16
|
-
|
17
15
|
SUPPORTABILITY_CREATE_PAYLOAD_SUCCESS = "Supportability/DistributedTrace/CreatePayload/Success".freeze
|
18
16
|
SUPPORTABILITY_CREATE_PAYLOAD_EXCEPTION = "Supportability/DistributedTrace/CreatePayload/Exception".freeze
|
19
17
|
|
20
18
|
def create_distributed_trace_payload
|
21
|
-
|
19
|
+
unless Agent.config[:'distributed_tracing.enabled'] && (Agent.config[:'distributed_tracing.format'] == NR_FORMAT)
|
20
|
+
NewRelic::Agent.logger.warn "Not configured to create New Relic distributed trace payload"
|
21
|
+
return
|
22
|
+
end
|
22
23
|
self.distributed_trace_payload_created = true
|
23
24
|
payload = DistributedTracePayload.for_transaction self
|
24
25
|
NewRelic::Agent.increment_metric SUPPORTABILITY_CREATE_PAYLOAD_SUCCESS
|
@@ -33,7 +34,10 @@ module NewRelic
|
|
33
34
|
SUPPORTABILITY_ACCEPT_PAYLOAD_EXCEPTION = "Supportability/DistributedTrace/AcceptPayload/Exception".freeze
|
34
35
|
|
35
36
|
def accept_distributed_trace_payload payload
|
36
|
-
|
37
|
+
unless Agent.config[:'distributed_tracing.enabled'] && (Agent.config[:'distributed_tracing.format'] == NR_FORMAT)
|
38
|
+
NewRelic::Agent.logger.warn "Not configured to accept New Relic distributed trace payload"
|
39
|
+
return
|
40
|
+
end
|
37
41
|
return false if check_payload_ignored(payload)
|
38
42
|
return false unless check_payload_present(payload)
|
39
43
|
return false unless payload = decode_payload(payload)
|
@@ -51,21 +55,6 @@ module NewRelic
|
|
51
55
|
false
|
52
56
|
end
|
53
57
|
|
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
58
|
def distributed_trace_payload_created?
|
70
59
|
@distributed_trace_payload_created ||= false
|
71
60
|
end
|
@@ -74,29 +63,16 @@ module NewRelic
|
|
74
63
|
|
75
64
|
def append_distributed_trace_info transaction_payload
|
76
65
|
return unless Agent.config[:'distributed_tracing.enabled']
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
66
|
+
DistributedTraceIntrinsics.copy_from_transaction \
|
67
|
+
self,
|
68
|
+
distributed_trace_payload,
|
69
|
+
transaction_payload
|
82
70
|
end
|
83
71
|
|
84
|
-
|
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
|
72
|
+
NR_FORMAT = "newrelic".freeze
|
92
73
|
|
93
|
-
|
94
|
-
|
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
|
74
|
+
def nr_distributed_tracing_enabled?
|
75
|
+
Agent.config[:'distributed_tracing.enabled'] && (Agent.config[:'distributed_tracing.format'] == NR_FORMAT) && Agent.instance.connected?
|
100
76
|
end
|
101
77
|
|
102
78
|
private
|
@@ -189,72 +165,15 @@ module NewRelic
|
|
189
165
|
|
190
166
|
def assign_payload_and_sampling_params(payload)
|
191
167
|
self.distributed_trace_payload = payload
|
168
|
+
@trace_id = payload.trace_id
|
169
|
+
@parent_transaction_id = payload.transaction_id
|
170
|
+
@parent_span_id = payload.id
|
192
171
|
|
193
172
|
unless payload.sampled.nil?
|
194
173
|
self.sampled = payload.sampled
|
195
174
|
self.priority = payload.priority if payload.priority
|
196
175
|
end
|
197
176
|
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
|
227
|
-
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
|
-
end
|
258
177
|
end
|
259
178
|
end
|
260
179
|
end
|