Class: NewRelic::Agent::Transaction::DistributedTracer

Inherits:
Object
  • Object
show all
Includes:
CrossAppTracing, DistributedTracing, TraceContext
Defined in:
lib/new_relic/agent/transaction/distributed_tracer.rb

Constant Summary

Constants included from TraceContext

TraceContext::ACCEPT_EXCEPTION_METRIC, TraceContext::ACCEPT_PREFIX, TraceContext::ACCEPT_SUCCESS_METRIC, TraceContext::CREATE_EXCEPTION_METRIC, TraceContext::CREATE_PREFIX, TraceContext::CREATE_SUCCESS_METRIC, TraceContext::IGNORE_ACCEPT_AFTER_CREATE_METRIC, TraceContext::IGNORE_MULTIPLE_ACCEPT_METRIC, TraceContext::INVALID_TRACESTATE_PAYLOAD_METRIC, TraceContext::NO_NR_ENTRY_TRACESTATE_METRIC, TraceContext::SUPPORTABILITY_PREFIX, TraceContext::TRACESTATE_PREFIX

Constants included from SupportabilityHelper

SupportabilityHelper::API_SUPPORTABILITY_METRICS, SupportabilityHelper::API_SUPPORTABILITY_PREFIX

Constants included from CrossAppTracing

CrossAppTracing::NR_APPDATA_HEADER, CrossAppTracing::NR_ID_HEADER, CrossAppTracing::NR_MESSAGE_BROKER_ID_HEADER, CrossAppTracing::NR_MESSAGE_BROKER_SYNTHETICS_HEADER, CrossAppTracing::NR_MESSAGE_BROKER_TXN_HEADER, CrossAppTracing::NR_TXN_HEADER

Instance Attribute Summary collapse

Attributes included from TraceContext

#trace_context_header_data, #trace_state_payload

Attributes included from CrossAppTracing

#cat_path_hashes, #cross_app_payload, #is_cross_app_caller

Instance Method Summary collapse

Methods included from TraceContext

#accept_trace_context, #assign_trace_state_payload, #create_trace_state, #create_trace_state_payload, #ignore_trace_context?, #insert_trace_context_header, #trace_context_inserted?, #trace_parent_header_present?

Methods included from Coerce

boolean_int!, float, float!, int, int!, int_or_nil, log_failure, scalar, string, value_or_nil

Methods included from DistributedTracing

#accept_distributed_trace_headers, #insert_distributed_trace_headers

Methods included from SupportabilityHelper

#record_api_supportability_metric, #valid_api_argument_class?

Methods included from CrossAppTracing

#add_message_cat_headers, #assign_cross_app_intrinsics, #cat_path_hash, #cat_trip_id, #cross_app_monitor, #insert_cross_app_header, #is_cross_app?, #is_cross_app_callee?, #is_cross_app_caller?, #record_cross_app_metrics

Constructor Details

#initialize(transaction) ⇒ DistributedTracer

Returns a new instance of DistributedTracer.



53
54
55
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 53

def initialize(transaction)
  @transaction = transaction
end

Instance Attribute Details

#parent_transaction_idObject



18
19
20
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 18

def parent_transaction_id
  @parent_transaction_id
end

#transactionObject (readonly)



17
18
19
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 17

def transaction
  @transaction
end

Instance Method Details

#accept_incoming_request(request, transport_type = nil) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 28

def accept_incoming_request(request, transport_type = nil)
  accept_incoming_transport_type(request, transport_type)
  if trace_parent_header_present?(request)
    accept_trace_context_incoming_request(request)
  else
    accept_distributed_tracing_incoming_request(request)
  end
end

#accept_incoming_transport_type(request, transport_type) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 45

def accept_incoming_transport_type(request, transport_type)
  if transport_type.to_s == NewRelic::EMPTY_STR
    @caller_transport_type = DistributedTraceTransportType.for_rack_request(request)
  else
    @caller_transport_type = DistributedTraceTransportType.from(transport_type)
  end
end

#accept_transport_type_from_api(value) ⇒ Object



41
42
43
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 41

def accept_transport_type_from_api(value)
  @caller_transport_type = DistributedTraceTransportType.from(value)
end

#append_payload(payload) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 62

def append_payload(payload)
  append_cat_info(payload)
  DistributedTraceAttributes.copy_from_transaction( \
    transaction,
    trace_state_payload || distributed_trace_payload,
    payload
  )
end

#assign_intrinsicsObject



94
95
96
97
98
99
100
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 94

def assign_intrinsics
  if dt_enabled?
    DistributedTraceAttributes.copy_to_attributes(transaction.payload, transaction.attributes)
  elsif is_cross_app?
    assign_cross_app_intrinsics
  end
end

#caller_transport_typeObject



37
38
39
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 37

def caller_transport_type
  @caller_transport_type ||= 'Unknown'
end

#consume_message_headers(headers, tracer_state, transport_type) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 85

def consume_message_headers(headers, tracer_state, transport_type)
  log_request_headers(headers, 'INCOMING')
  consume_message_distributed_tracing_headers(headers, transport_type)
  consume_message_cross_app_tracing_headers(headers, tracer_state)
  consume_message_synthetics_headers(headers)
rescue => e
  NewRelic::Agent.logger.error('Error in consume_message_headers', e)
end

#insert_cat_headers(headers) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 110

def insert_cat_headers(headers)
  return unless CrossAppTracing.cross_app_enabled?

  @is_cross_app_caller = true
  insert_message_headers(headers,
    transaction.guid,
    cat_trip_id,
    cat_path_hash,
    transaction.raw_synthetics_header)
end

#insert_distributed_trace_header(headers) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 102

def insert_distributed_trace_header(headers)
  return unless dt_enabled?
  return if Agent.config[:'exclude_newrelic_header']

  payload = create_distributed_trace_payload
  headers[NewRelic::NEWRELIC_KEY] = payload.http_safe if payload
end

#insert_headers(headers) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 76

def insert_headers(headers)
  return unless NewRelic::Agent.agent.connected?

  insert_trace_context_header(headers)
  insert_distributed_trace_header(headers)
  insert_cross_app_header(headers)
  log_request_headers(headers)
end

#log_request_headers(headers, direction = 'OUTGOING') ⇒ Object



71
72
73
74
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 71

def log_request_headers(headers, direction = 'OUTGOING')
  printed_headers = headers.is_a?(NewRelic::Agent::HTTPClients::AbstractRequest) ? headers.headers : headers
  NewRelic::Agent.logger.debug("#{direction} REQUEST HEADERS: #{printed_headers}")
end

#parent_guidObject



20
21
22
23
24
25
26
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 20

def parent_guid
  if trace_context_header_data
    trace_context_header_data.parent_id
  elsif distributed_trace_payload
    distributed_trace_payload.id
  end
end

#record_metricsObject



57
58
59
60
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 57

def record_metrics
  record_cross_app_metrics
  DistributedTraceMetrics.record_metrics_for_transaction(transaction)
end