Module: NewRelic::Agent::DistributedTraceAttributes

Extended by:
DistributedTraceAttributes
Included in:
DistributedTraceAttributes
Defined in:
lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb

Constant Summary collapse

INTRINSIC_KEYS =

Intrinsic Keys

[
  PARENT_TYPE_KEY = 'parent.type',
  PARENT_APP_KEY = 'parent.app',
  PARENT_ACCOUNT_ID_KEY = 'parent.account',
  PARENT_TRANSPORT_TYPE_KEY = 'parent.transportType',
  PARENT_TRANSPORT_DURATION_KEY = 'parent.transportDuration',
  GUID_KEY = 'guid',
  TRACE_ID_KEY = 'traceId',
  PARENT_TRANSACTION_ID_KEY = 'parentId',
  PARENT_SPAN_ID_KEY = 'parentSpanId',
  SAMPLED_KEY = 'sampled'
].freeze

Instance Method Summary collapse

Instance Method Details

#copy_from_transaction(transaction, trace_payload, destination) ⇒ Object

This method takes all distributed tracing intrinsics from the transaction and the trace_payload, and populates them into the destination



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb', line 49

def copy_from_transaction(transaction, trace_payload, destination)
  destination[GUID_KEY] = transaction.guid
  destination[SAMPLED_KEY] = transaction.sampled?
  destination[TRACE_ID_KEY] = transaction.trace_id

  if transaction.parent_span_id
    destination[PARENT_SPAN_ID_KEY] = transaction.parent_span_id
  end

  copy_parent_attributes(transaction, trace_payload, destination)
end

#copy_parent_attributes(transaction, trace_payload, destination) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb', line 61

def copy_parent_attributes(transaction, trace_payload, destination)
  transport_type = transaction.distributed_tracer.caller_transport_type
  destination[PARENT_TRANSPORT_TYPE_KEY] = DistributedTraceTransportType.from(transport_type)

  if trace_payload
    destination[PARENT_TYPE_KEY] = trace_payload.parent_type
    destination[PARENT_APP_KEY] = trace_payload.parent_app_id
    destination[PARENT_ACCOUNT_ID_KEY] = trace_payload.
    destination[PARENT_TRANSPORT_DURATION_KEY] = transaction.calculate_transport_duration(trace_payload)

    if parent_transaction_id = transaction.distributed_tracer.parent_transaction_id
      destination[PARENT_TRANSACTION_ID_KEY] = parent_transaction_id
    end
  end
end

#copy_to_attributes(transaction_payload, destination) ⇒ Object

This method extracts intrinsics from the transaction_payload and inserts them as intrinsics in the specified transaction_attributes



37
38
39
40
41
42
43
44
45
# File 'lib/new_relic/agent/distributed_tracing/distributed_trace_attributes.rb', line 37

def copy_to_attributes(transaction_payload, destination)
  return unless enabled?

  INTRINSIC_KEYS.each do |key|
    next unless transaction_payload.key?(key)

    destination.add_intrinsic_attribute(key, transaction_payload[key])
  end
end

#copy_to_hash(transaction_payload, destination) ⇒ Object

This method extracts intrinsics from the transaction_payload and inserts them into the specified destination.



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

def copy_to_hash(transaction_payload, destination)
  return unless enabled?

  INTRINSIC_KEYS.each do |key|
    value = transaction_payload[key]
    destination[key] = value unless value.nil?
  end
end