newrelic_rpm 6.8.0.360 → 6.9.0.363

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +16 -16
  3. data/CHANGELOG.md +64 -0
  4. data/lib/new_relic/agent.rb +6 -5
  5. data/lib/new_relic/agent/agent.rb +43 -36
  6. data/lib/new_relic/agent/attributes.rb +2 -4
  7. data/lib/new_relic/agent/configuration/default_source.rb +23 -22
  8. data/lib/new_relic/agent/configuration/server_source.rb +1 -1
  9. data/lib/new_relic/agent/configuration/yaml_source.rb +1 -1
  10. data/lib/new_relic/agent/database.rb +1 -2
  11. data/lib/new_relic/agent/distributed_tracing.rb +155 -6
  12. data/lib/new_relic/agent/{cross_app_payload.rb → distributed_tracing/cross_app_payload.rb} +0 -0
  13. data/lib/new_relic/agent/{cross_app_tracing.rb → distributed_tracing/cross_app_tracing.rb} +60 -45
  14. data/lib/new_relic/agent/distributed_tracing/distributed_trace_intrinsics.rb +80 -0
  15. data/lib/new_relic/agent/distributed_tracing/distributed_trace_metrics.rb +75 -0
  16. data/lib/new_relic/agent/{distributed_trace_payload.rb → distributed_tracing/distributed_trace_payload.rb} +19 -28
  17. data/lib/new_relic/agent/distributed_tracing/distributed_trace_transport_type.rb +39 -0
  18. data/lib/new_relic/agent/distributed_tracing/trace_context.rb +246 -0
  19. data/lib/new_relic/agent/{trace_context_payload.rb → distributed_tracing/trace_context_payload.rb} +3 -11
  20. data/lib/new_relic/agent/error_collector.rb +3 -5
  21. data/lib/new_relic/agent/error_event_aggregator.rb +3 -1
  22. data/lib/new_relic/agent/external.rb +7 -7
  23. data/lib/new_relic/agent/instrumentation/action_cable_subscriber.rb +1 -2
  24. data/lib/new_relic/agent/instrumentation/bunny.rb +1 -1
  25. data/lib/new_relic/agent/instrumentation/curb.rb +1 -1
  26. data/lib/new_relic/agent/instrumentation/excon.rb +1 -1
  27. data/lib/new_relic/agent/instrumentation/grape.rb +5 -10
  28. data/lib/new_relic/agent/instrumentation/http.rb +1 -1
  29. data/lib/new_relic/agent/instrumentation/httpclient.rb +1 -1
  30. data/lib/new_relic/agent/instrumentation/net.rb +1 -1
  31. data/lib/new_relic/agent/instrumentation/resque.rb +3 -0
  32. data/lib/new_relic/agent/instrumentation/typhoeus.rb +1 -1
  33. data/lib/new_relic/agent/logging.rb +13 -3
  34. data/lib/new_relic/agent/messaging.rb +5 -73
  35. data/lib/new_relic/agent/method_tracer.rb +3 -2
  36. data/lib/new_relic/agent/method_tracer_helpers.rb +1 -1
  37. data/lib/new_relic/agent/monitors.rb +27 -0
  38. data/lib/new_relic/agent/monitors/cross_app_monitor.rb +110 -0
  39. data/lib/new_relic/agent/monitors/distributed_tracing_monitor.rb +27 -0
  40. data/lib/new_relic/agent/{inbound_request_monitor.rb → monitors/inbound_request_monitor.rb} +1 -1
  41. data/lib/new_relic/agent/{synthetics_monitor.rb → monitors/synthetics_monitor.rb} +2 -4
  42. data/lib/new_relic/agent/span_event_primitive.rb +25 -29
  43. data/lib/new_relic/agent/sql_sampler.rb +2 -2
  44. data/lib/new_relic/agent/supported_versions.rb +2 -2
  45. data/lib/new_relic/agent/tracer.rb +3 -3
  46. data/lib/new_relic/agent/transaction.rb +21 -28
  47. data/lib/new_relic/agent/transaction/distributed_tracer.rb +171 -0
  48. data/lib/new_relic/agent/transaction/distributed_tracing.rb +61 -69
  49. data/lib/new_relic/agent/transaction/external_request_segment.rb +8 -44
  50. data/lib/new_relic/agent/transaction/message_broker_segment.rb +3 -11
  51. data/lib/new_relic/agent/transaction/trace.rb +2 -4
  52. data/lib/new_relic/agent/transaction/trace_context.rb +88 -79
  53. data/lib/new_relic/agent/transaction/trace_node.rb +2 -5
  54. data/lib/new_relic/agent/transaction_error_primitive.rb +2 -2
  55. data/lib/new_relic/agent/transaction_event_primitive.rb +26 -29
  56. data/lib/new_relic/coerce.rb +5 -3
  57. data/lib/new_relic/constants.rb +34 -0
  58. data/lib/new_relic/noticed_error.rb +2 -4
  59. data/lib/new_relic/rack/browser_monitoring.rb +4 -0
  60. data/lib/new_relic/supportability_helper.rb +14 -0
  61. data/lib/new_relic/version.rb +1 -1
  62. data/lib/tasks/tests.rake +6 -1
  63. data/newrelic_rpm.gemspec +4 -2
  64. data/test/agent_helper.rb +21 -1
  65. metadata +49 -19
  66. data/lib/new_relic/agent/cross_app_monitor.rb +0 -110
  67. data/lib/new_relic/agent/distributed_trace_intrinsics.rb +0 -90
  68. data/lib/new_relic/agent/distributed_trace_metrics.rb +0 -74
  69. data/lib/new_relic/agent/distributed_trace_monitor.rb +0 -30
  70. data/lib/new_relic/agent/distributed_trace_transport_type.rb +0 -43
  71. data/lib/new_relic/agent/trace_context.rb +0 -244
  72. data/lib/new_relic/agent/trace_context_request_monitor.rb +0 -42
@@ -0,0 +1,27 @@
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
+ module NewRelic
6
+ module Agent
7
+ module DistributedTracing
8
+ class Monitor < InboundRequestMonitor
9
+ def on_finished_configuring(events)
10
+ return unless NewRelic::Agent.config[:'distributed_tracing.enabled']
11
+ events.subscribe(:before_call, &method(:on_before_call))
12
+ end
13
+
14
+ def on_before_call(request)
15
+ unless NewRelic::Agent.config[:'distributed_tracing.enabled']
16
+ NewRelic::Agent.logger.warn "Not configured to accept distributed trace headers"
17
+ return
18
+ end
19
+
20
+ return unless txn = Tracer.current_transaction
21
+
22
+ txn.distributed_tracer.accept_incoming_request request
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -28,7 +28,7 @@ module NewRelic
28
28
  end
29
29
 
30
30
  def setup_obfuscator
31
- @obfuscator = NewRelic::Agent::Obfuscator.new(NewRelic::Agent.config[:encoding_key])
31
+ @obfuscator = Obfuscator.new(Agent.config[:encoding_key])
32
32
  end
33
33
 
34
34
  def deserialize_header(encoded_header, key)
@@ -2,8 +2,6 @@
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
4
 
5
- require 'new_relic/agent/inbound_request_monitor'
6
-
7
5
  module NewRelic
8
6
  module Agent
9
7
  class SyntheticsMonitor < InboundRequestMonitor
@@ -40,7 +38,7 @@ module NewRelic
40
38
 
41
39
  def is_trusted?(incoming_payload)
42
40
  account_id = incoming_payload[1]
43
- NewRelic::Agent.config[:trusted_account_ids].include?(account_id)
41
+ Agent.config[:trusted_account_ids].include?(account_id)
44
42
  end
45
43
 
46
44
  def is_valid_payload?(incoming_payload)
@@ -48,7 +46,7 @@ module NewRelic
48
46
  end
49
47
 
50
48
  def reject_messaging_synthetics_header headers
51
- headers.reject {|k,_| k == NewRelic::Agent::CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER}
49
+ headers.reject {|k,_| k == CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER}
52
50
  end
53
51
 
54
52
  end
@@ -6,7 +6,7 @@
6
6
  # event for a segment.
7
7
 
8
8
  require 'new_relic/agent/payload_metric_mapping'
9
- require 'new_relic/agent/distributed_trace_payload'
9
+ require 'new_relic/agent/distributed_tracing/distributed_trace_payload'
10
10
 
11
11
  module NewRelic
12
12
  module Agent
@@ -15,6 +15,7 @@ module NewRelic
15
15
  extend self
16
16
 
17
17
  # Strings for static keys of the event structure
18
+ ELLIPSIS = '...'.freeze
18
19
  TYPE_KEY = 'type'.freeze
19
20
  TRACE_ID_KEY = 'traceId'.freeze
20
21
  GUID_KEY = 'guid'.freeze
@@ -46,17 +47,14 @@ module NewRelic
46
47
  DATASTORE_CATEGORY = 'datastore'.freeze
47
48
  CLIENT = 'client'.freeze
48
49
 
49
- # To avoid allocations when we have empty custom or agent attributes
50
- EMPTY_HASH = {}.freeze
51
-
52
- def for_segment(segment)
50
+ def for_segment segment
53
51
  intrinsics = intrinsics_for(segment)
54
52
  intrinsics[CATEGORY_KEY] = GENERIC_CATEGORY
55
53
 
56
- [intrinsics, custom_attributes(segment.attributes), EMPTY_HASH]
54
+ [intrinsics, custom_attributes(segment.attributes), NewRelic::EMPTY_HASH]
57
55
  end
58
56
 
59
- def for_external_request_segment(segment)
57
+ def for_external_request_segment segment
60
58
  intrinsics = intrinsics_for(segment)
61
59
 
62
60
  intrinsics[COMPONENT_KEY] = segment.library
@@ -73,7 +71,7 @@ module NewRelic
73
71
  [intrinsics, custom_attributes(segment.attributes), agent_attributes]
74
72
  end
75
73
 
76
- def for_datastore_segment(segment)
74
+ def for_datastore_segment segment
77
75
  intrinsics = intrinsics_for(segment)
78
76
 
79
77
  intrinsics[COMPONENT_KEY] = segment.product
@@ -103,9 +101,8 @@ module NewRelic
103
101
 
104
102
  private
105
103
 
106
- def intrinsics_for(segment)
107
- intrinsics =
108
- {
104
+ def intrinsics_for segment
105
+ intrinsics = {
109
106
  TYPE_KEY => EVENT_TYPE,
110
107
  TRACE_ID_KEY => segment.transaction.trace_id,
111
108
  GUID_KEY => segment.guid,
@@ -119,18 +116,21 @@ module NewRelic
119
116
 
120
117
  if segment.parent.nil?
121
118
  intrinsics[ENTRY_POINT_KEY] = true
122
- if segment.transaction
123
- if segment.transaction.trace_context_header_data
124
- intrinsics[TRACING_VENDORS_KEY] = segment.transaction.trace_context_header_data.trace_state_vendors
119
+ if txn = segment.transaction
120
+ if header_data = txn.distributed_tracer.trace_context_header_data
121
+ if trace_state_vendors = header_data.trace_state_vendors
122
+ intrinsics[TRACING_VENDORS_KEY] = trace_state_vendors unless trace_state_vendors == NewRelic::EMPTY_STR
123
+ end
125
124
  end
126
- if segment.transaction.trace_state_payload
127
- intrinsics[TRUSTED_PARENT_KEY] = segment.transaction.trace_state_payload.id
125
+ if trace_state_payload = txn.distributed_tracer.trace_state_payload
126
+ intrinsics[TRUSTED_PARENT_KEY] = trace_state_payload.id if trace_state_payload.id
128
127
  end
129
128
  end
130
129
  end
131
130
 
132
- parent_id = parent_guid(segment)
133
- intrinsics[PARENT_ID_KEY] = parent_id if parent_id
131
+ if parent_id = parent_guid(segment)
132
+ intrinsics[PARENT_ID_KEY] = parent_id
133
+ end
134
134
  intrinsics
135
135
  end
136
136
 
@@ -139,27 +139,23 @@ module NewRelic
139
139
  result = attributes.custom_attributes_for(NewRelic::Agent::AttributeFilter::DST_SPAN_EVENTS)
140
140
  result.freeze
141
141
  else
142
- EMPTY_HASH
142
+ NewRelic::EMPTY_HASH
143
143
  end
144
144
  end
145
145
 
146
- def parent_guid(segment)
146
+ def parent_guid segment
147
147
  if segment.parent
148
148
  segment.parent.guid
149
- elsif segment.transaction && segment.transaction.distributed_trace_payload
150
- segment.transaction.distributed_trace_payload.id
151
- elsif segment.transaction && segment.transaction.trace_context_header_data
152
- segment.transaction.trace_context_header_data.parent_id
149
+ elsif txn = segment.transaction
150
+ txn.distributed_tracer.parent_guid
153
151
  end
154
152
  end
155
153
 
156
- def milliseconds_since_epoch(segment)
154
+ def milliseconds_since_epoch segment
157
155
  Integer(segment.start_time.to_f * 1000.0)
158
156
  end
159
157
 
160
- ELLIPSIS = '...'.freeze
161
-
162
- def truncate(value, max_size=255)
158
+ def truncate value, max_size=255
163
159
  value = value.to_s
164
160
  if value.bytesize > max_size
165
161
  value.byteslice(0, max_size - 2).chop! << ELLIPSIS
@@ -168,7 +164,7 @@ module NewRelic
168
164
  end
169
165
  end
170
166
 
171
- def allowed?(key)
167
+ def allowed? key
172
168
  NewRelic::Agent.instance.attribute_filter.allows_key?(key, AttributeFilter::DST_SPAN_EVENTS)
173
169
  end
174
170
  end
@@ -159,9 +159,9 @@ module NewRelic
159
159
  def distributed_trace_intrinsics(state)
160
160
  transaction = state.current_transaction
161
161
  params = nil
162
- if transaction && transaction.distributed_trace_payload
162
+ if transaction && transaction.distributed_tracer.distributed_trace_payload
163
163
  params = {}
164
- payload = transaction.distributed_trace_payload
164
+ payload = transaction.distributed_tracer.distributed_trace_payload
165
165
  DistributedTraceIntrinsics.copy_from_transaction transaction, payload, params
166
166
  params[PRIORITY] = transaction.priority
167
167
  end
@@ -11,7 +11,7 @@ module NewRelic
11
11
  {
12
12
  :type => :ruby,
13
13
  :name => "MRI",
14
- :supported => ["2.0.0", "~>2.1.0", "~>2.2.0", "~>2.3.0", "~>2.4.0", "~>2.5.0"],
14
+ :supported => ["2.0.0", "~>2.1.0", "~>2.2.0", "~>2.3.0", "~>2.4.0", "~>2.5.0", "~>2.6.0", "~>2.7.0"],
15
15
  :deprecated => ["1.8.6", "1.8.7", "1.9.2", "1.9.3"],
16
16
  :url => "https://www.ruby-lang.org",
17
17
  :feed => "https://www.ruby-lang.org/en/feeds/news.rss",
@@ -119,7 +119,7 @@ module NewRelic
119
119
  :activerecord =>
120
120
  {
121
121
  :type => :database,
122
- :supported => ["~>3.0.0", "~>3.1.0", "~>3.2.0", "~>4.0.0", "~>4.1.0", "~>4.2.0", "~>5.0.0", "~>5.1.0"],
122
+ :supported => ["~>3.0.0", "~>3.1.0", "~>3.2.0", "~>4.0.0", "~>4.1.0", "~>4.2.0", "~>5.0.0", "~>5.1.0", "~>6.0.0"],
123
123
  :deprecated => ["~>2.0.0", "~>2.1.0", "~>2.2.0", "~>2.3.0",],
124
124
  :url => "https://rubygems.org/gems/activerecord",
125
125
  :feed => "https://rubygems.org/gems/activerecord/versions.atom",
@@ -120,7 +120,7 @@ module NewRelic
120
120
  # New-Relic-specific prefix
121
121
  #
122
122
  # @param [Symbol] category +:web+ for web transactions or
123
- # +:background+ for background transactions
123
+ # +:task+ for background transactions
124
124
  #
125
125
  # @param [Hash] options reserved for New Relic internal use
126
126
  #
@@ -196,12 +196,12 @@ module NewRelic
196
196
 
197
197
  def create_distributed_trace_payload
198
198
  return unless txn = current_transaction
199
- txn.create_distributed_trace_payload
199
+ txn.distributed_tracer.create_distributed_trace_payload
200
200
  end
201
201
 
202
202
  def accept_distributed_trace_payload(payload)
203
203
  return unless txn = current_transaction
204
- txn.accept_distributed_trace_payload(payload)
204
+ txn.distributed_tracer.accept_distributed_trace_payload(payload)
205
205
  end
206
206
 
207
207
  # Returns the currently active segment in the transaction in
@@ -8,9 +8,7 @@ require 'new_relic/agent/method_tracer_helpers'
8
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'
12
- require 'new_relic/agent/transaction/distributed_tracing'
13
- require 'new_relic/agent/cross_app_tracing'
11
+ require 'new_relic/agent/transaction/distributed_tracer'
14
12
  require 'new_relic/agent/transaction_time_aggregator'
15
13
  require 'new_relic/agent/deprecator'
16
14
  require 'new_relic/agent/guid_generator'
@@ -23,9 +21,6 @@ module NewRelic
23
21
  # @api public
24
22
  class Transaction
25
23
  include Tracing
26
- include TraceContext
27
- include DistributedTracing
28
- include CrossAppTracing
29
24
 
30
25
  # for nested transactions
31
26
  SUBTRANSACTION_PREFIX = 'Nested/'.freeze
@@ -62,7 +57,8 @@ module NewRelic
62
57
  :process_cpu_start,
63
58
  :http_response_code,
64
59
  :response_content_length,
65
- :response_content_type
60
+ :response_content_type,
61
+ :parent_span_id
66
62
 
67
63
  attr_reader :guid,
68
64
  :metrics,
@@ -73,9 +69,7 @@ module NewRelic
73
69
  :nesting_max_depth,
74
70
  :segments,
75
71
  :end_time,
76
- :duration,
77
- :parent_transaction_id,
78
- :parent_span_id
72
+ :duration
79
73
 
80
74
  attr_writer :sampled,
81
75
  :priority
@@ -270,6 +264,10 @@ module NewRelic
270
264
  end
271
265
  end
272
266
 
267
+ def distributed_tracer
268
+ @distributed_tracer ||= DistributedTracer.new(self)
269
+ end
270
+
273
271
  def sampled?
274
272
  return unless Agent.config[:'distributed_tracing.enabled']
275
273
  if @sampled.nil?
@@ -282,12 +280,12 @@ module NewRelic
282
280
  @trace_id ||= NewRelic::Agent::GuidGenerator.generate_guid 32
283
281
  end
284
282
 
283
+ def trace_id=(value)
284
+ @trace_id = value
285
+ end
286
+
285
287
  def priority
286
- if @priority.nil?
287
- @priority = rand.round(6)
288
- @priority += 1 if sampled?
289
- end
290
- @priority
288
+ @priority ||= (sampled? ? 1.0 + rand : rand).round(NewRelic::PRIORITY_PRECISION)
291
289
  end
292
290
 
293
291
  def referer
@@ -358,8 +356,10 @@ module NewRelic
358
356
  end
359
357
 
360
358
  def best_name
361
- @frozen_name || @overridden_name ||
362
- @default_name || NewRelic::Agent::UNKNOWN_METRIC
359
+ @frozen_name ||
360
+ @overridden_name ||
361
+ @default_name ||
362
+ NewRelic::Agent::UNKNOWN_METRIC
363
363
  end
364
364
 
365
365
  # For common interface with Trace
@@ -532,8 +532,7 @@ module NewRelic
532
532
  record_total_time_metrics
533
533
  record_apdex unless ignore_apdex?
534
534
  record_queue_time
535
- record_cross_app_metrics
536
- DistributedTraceMetrics.record_metrics_for_transaction self
535
+ distributed_tracer.record_metrics
537
536
 
538
537
  record_exceptions
539
538
  record_transaction_event
@@ -585,11 +584,7 @@ module NewRelic
585
584
  attributes.add_intrinsic_attribute(:synthetics_monitor_id, synthetics_monitor_id)
586
585
  end
587
586
 
588
- if Agent.config[:'distributed_tracing.enabled'] || trace_context_enabled?
589
- DistributedTraceIntrinsics.copy_to_attributes @payload, attributes
590
- elsif is_cross_app?
591
- assign_cross_app_intrinsics
592
- end
587
+ distributed_tracer.assign_intrinsics
593
588
  end
594
589
 
595
590
  def calculate_gc_time
@@ -633,15 +628,13 @@ module NewRelic
633
628
  :priority => priority
634
629
  }
635
630
 
636
- append_cat_info(@payload)
637
- append_distributed_trace_info(@payload)
638
- append_trace_context_info(@payload)
631
+ distributed_tracer.append_payload(@payload)
639
632
  append_apdex_perf_zone(@payload)
640
633
  append_synthetics_to(@payload)
641
634
  end
642
635
 
643
636
  def include_guid?
644
- is_cross_app? || is_synthetics_request?
637
+ distributed_tracer.is_cross_app? || is_synthetics_request?
645
638
  end
646
639
 
647
640
  def is_synthetics_request?
@@ -0,0 +1,171 @@
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 'new_relic/agent/transaction/trace_context'
7
+ require 'new_relic/agent/transaction/distributed_tracing'
8
+ require 'new_relic/agent/distributed_tracing/cross_app_tracing'
9
+
10
+ module NewRelic
11
+ module Agent
12
+ class Transaction
13
+ class DistributedTracer
14
+ include NewRelic::Agent::CrossAppTracing
15
+ include DistributedTracing
16
+ include TraceContext
17
+
18
+ attr_reader :transaction
19
+ attr_accessor :parent_transaction_id
20
+
21
+ def parent_guid
22
+ if trace_context_header_data
23
+ trace_context_header_data.parent_id
24
+ elsif distributed_trace_payload
25
+ distributed_trace_payload.id
26
+ end
27
+ end
28
+
29
+ def accept_incoming_request request, transport_type=nil
30
+ accept_incoming_transport_type request, transport_type
31
+ if trace_parent_header_present? request
32
+ accept_trace_context_incoming_request request
33
+ else
34
+ accept_distributed_tracing_incoming_request request
35
+ end
36
+ end
37
+
38
+ def caller_transport_type
39
+ @caller_transport_type ||= "Unknown"
40
+ end
41
+
42
+ def accept_transport_type_from_api value
43
+ @caller_transport_type = DistributedTraceTransportType.from value
44
+ end
45
+
46
+ def accept_incoming_transport_type request, transport_type
47
+ if transport_type.to_s == NewRelic::EMPTY_STR
48
+ @caller_transport_type = DistributedTraceTransportType.for_rack_request request
49
+ else
50
+ @caller_transport_type = DistributedTraceTransportType.from transport_type
51
+ end
52
+ end
53
+
54
+ def initialize transaction
55
+ @transaction = transaction
56
+ end
57
+
58
+ def record_metrics
59
+ record_cross_app_metrics
60
+ DistributedTraceMetrics.record_metrics_for_transaction transaction
61
+ end
62
+
63
+ def append_payload payload
64
+ append_cat_info payload
65
+ DistributedTraceIntrinsics.copy_from_transaction \
66
+ transaction,
67
+ trace_state_payload || distributed_trace_payload,
68
+ payload
69
+ end
70
+
71
+ def insert_headers request
72
+ insert_trace_context_header request
73
+ insert_distributed_trace_header request
74
+ insert_cross_app_header request
75
+ end
76
+
77
+ def consume_message_headers headers, tracer_state, transport_type
78
+ consume_message_distributed_tracing_headers headers, transport_type
79
+ consume_message_cross_app_tracing_headers headers, tracer_state
80
+ consume_message_synthetics_headers headers
81
+ rescue => e
82
+ NewRelic::Agent.logger.error "Error in consume_message_headers", e
83
+ end
84
+
85
+ def assign_intrinsics
86
+ if Agent.config[:'distributed_tracing.enabled']
87
+ DistributedTraceIntrinsics.copy_to_attributes transaction.payload, transaction.attributes
88
+ elsif is_cross_app?
89
+ assign_cross_app_intrinsics
90
+ end
91
+ end
92
+
93
+ def insert_distributed_trace_header request
94
+ return unless Agent.config[:'distributed_tracing.enabled']
95
+ return if Agent.config[:'exclude_newrelic_header']
96
+ payload = create_distributed_trace_payload
97
+ request[NewRelic::NEWRELIC_KEY] = payload.http_safe if payload
98
+ end
99
+
100
+ def insert_cat_headers headers
101
+ return unless CrossAppTracing.cross_app_enabled?
102
+ @is_cross_app_caller = true
103
+ insert_message_headers headers,
104
+ transaction.guid,
105
+ cat_trip_id,
106
+ cat_path_hash,
107
+ transaction.raw_synthetics_header
108
+ end
109
+
110
+ private
111
+
112
+ def consume_message_synthetics_headers headers
113
+ synthetics_header = headers[CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER]
114
+ if synthetics_header and
115
+ incoming_payload = ::JSON.load(deobfuscate(synthetics_header)) and
116
+ SyntheticsMonitor.is_valid_payload?(incoming_payload) and
117
+ SyntheticsMonitor.is_supported_version?(incoming_payload) and
118
+ SyntheticsMonitor.is_trusted?(incoming_payload)
119
+
120
+ transaction.raw_synthetics_header = synthetics_header
121
+ transaction.synthetics_payload = incoming_payload
122
+ end
123
+ rescue => e
124
+ NewRelic::Agent.logger.error "Error in consume_message_synthetics_header", e
125
+ end
126
+
127
+ def consume_message_distributed_tracing_headers headers, transport_type
128
+ return unless Agent.config[:'distributed_tracing.enabled']
129
+
130
+ accept_incoming_transport_type headers, transport_type
131
+
132
+ newrelic_trace_key = NewRelic::CANDIDATE_NEWRELIC_KEYS.detect do |key|
133
+ headers.has_key?(key)
134
+ end
135
+ return unless newrelic_trace_key && (payload = headers[newrelic_trace_key])
136
+
137
+ accept_distributed_trace_payload payload
138
+ end
139
+
140
+ def consume_message_cross_app_tracing_headers headers, tracer_state
141
+ return unless CrossAppTracing.cross_app_enabled?
142
+ return unless CrossAppTracing.message_has_crossapp_request_header?(headers)
143
+
144
+ accept_cross_app_payload headers, tracer_state
145
+ CrossAppTracing.assign_intrinsic_transaction_attributes tracer_state
146
+ end
147
+
148
+ def accept_cross_app_payload headers, tracer_state
149
+ encoded_id = headers[CrossAppTracing::NR_MESSAGE_BROKER_ID_HEADER]
150
+ decoded_id = encoded_id.nil? ? EMPTY_STRING : deobfuscate(encoded_id)
151
+
152
+ return unless CrossAppTracing.trusted_valid_cross_app_id?(decoded_id)
153
+ txn_header = headers[CrossAppTracing::NR_MESSAGE_BROKER_TXN_HEADER]
154
+ txn_info = ::JSON.load(deobfuscate(txn_header))
155
+ payload = CrossAppPayload.new(decoded_id, transaction, txn_info)
156
+
157
+ @cross_app_payload = payload
158
+ rescue => e
159
+ NewRelic::Agent.logger.debug("Failure deserializing encoded header in #{self.class}, #{e.class}, #{e.message}")
160
+ nil
161
+ end
162
+
163
+ def deobfuscate message
164
+ CrossAppTracing.obfuscator.deobfuscate message
165
+ end
166
+
167
+ end
168
+ end
169
+ end
170
+ end
171
+