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

Inherits:
Object
  • Object
show all
Includes:
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

Instance Attribute Summary collapse

Attributes included from TraceContext

#trace_context_header_data, #trace_state_payload

Instance Method Summary collapse

Methods included from TraceContext

#accept_trace_context, #assign_trace_state_payload, #create_trace_state, #create_trace_state_payload, #determine_sampling_decision, #ignore_trace_context?, #insert_trace_context_header, #set_priority_and_sampled, #trace_context_inserted?, #trace_parent_header_present?, #use_nr_tracestate_sampled

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?

Constructor Details

#initialize(transaction) ⇒ DistributedTracer

Returns a new instance of DistributedTracer.



51
52
53
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 51

def initialize(transaction)
  @transaction = transaction
end

Instance Attribute Details

#parent_transaction_idObject



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

def parent_transaction_id
  @parent_transaction_id
end

#transactionObject (readonly)



15
16
17
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 15

def transaction
  @transaction
end

Instance Method Details

#accept_incoming_request(request, transport_type = nil) ⇒ Object



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

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



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

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



39
40
41
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 39

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

#append_payload(payload) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 59

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

#assign_intrinsicsObject



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

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

#caller_transport_typeObject



35
36
37
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 35

def caller_transport_type
  @caller_transport_type ||= NewRelic::UNKNOWN
end

#consume_message_headers(headers, tracer_state, transport_type) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 80

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

#insert_distributed_trace_header(headers) ⇒ Object



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

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



72
73
74
75
76
77
78
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 72

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

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

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



67
68
69
70
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 67

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



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

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



55
56
57
# File 'lib/new_relic/agent/transaction/distributed_tracer.rb', line 55

def record_metrics
  DistributedTraceMetrics.record_metrics_for_transaction(transaction)
end