Module: NewRelic::Agent::CrossAppTracing

Included in:
Transaction::DistributedTracer
Defined in:
lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb

Constant Summary collapse

NR_APPDATA_HEADER =

The cross app response header for “outgoing” calls

'X-NewRelic-App-Data'
NR_ID_HEADER =

The cross app id header for “outgoing” calls

'X-NewRelic-ID'
NR_TXN_HEADER =

The cross app transaction header for “outgoing” calls

'X-NewRelic-Transaction'
NR_MESSAGE_BROKER_ID_HEADER =
'NewRelicID'
NR_MESSAGE_BROKER_TXN_HEADER =
'NewRelicTransaction'
NR_MESSAGE_BROKER_SYNTHETICS_HEADER =
'NewRelicSynthetics'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cat_path_hashesObject

Returns the value of attribute cat_path_hashes.



23
24
25
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 23

def cat_path_hashes
  @cat_path_hashes
end

#cross_app_payloadObject

Returns the value of attribute cross_app_payload.



23
24
25
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 23

def cross_app_payload
  @cross_app_payload
end

#is_cross_app_callerObject

Returns the value of attribute is_cross_app_caller.



23
24
25
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 23

def is_cross_app_caller
  @is_cross_app_caller
end

Instance Method Details

#add_message_cat_headers(headers) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 64

def add_message_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

#assign_cross_app_intrinsicsObject



85
86
87
88
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 85

def assign_cross_app_intrinsics
  transaction.attributes.add_intrinsic_attribute(:trip_id, cat_trip_id)
  transaction.attributes.add_intrinsic_attribute(:path_hash, cat_path_hash)
end

#cat_path_hashObject



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

def cat_path_hash
  referring_path_hash = cat_referring_path_hash || '0'
  seed = referring_path_hash.to_i(16)
  result = cross_app_monitor.path_hash(transaction.best_name, seed)
  record_cat_path_hash(result)
  result
end

#cat_trip_idObject



37
38
39
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 37

def cat_trip_id
  cross_app_payload&.referring_trip_id || transaction.guid
end

#cross_app_monitorObject



41
42
43
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 41

def cross_app_monitor
  NewRelic::Agent.instance.monitors.cross_app_monitor
end

#insert_cross_app_header(headers) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 53

def insert_cross_app_header(headers)
  return unless CrossAppTracing.cross_app_enabled?

  @is_cross_app_caller = true
  txn_guid = transaction.guid
  trip_id = cat_trip_id
  path_hash = cat_path_hash

  insert_request_headers(headers, txn_guid, trip_id, path_hash)
end

#is_cross_app?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 33

def is_cross_app?
  is_cross_app_caller? || is_cross_app_callee?
end

#is_cross_app_callee?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 29

def is_cross_app_callee?
  !cross_app_payload.nil?
end

#is_cross_app_caller?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 25

def is_cross_app_caller?
  @is_cross_app_caller ||= false
end

#record_cross_app_metricsObject



75
76
77
78
79
80
81
82
83
# File 'lib/new_relic/agent/distributed_tracing/cross_app_tracing.rb', line 75

def record_cross_app_metrics
  if (id = cross_app_payload&.id)
    app_time_in_seconds = [
      Process.clock_gettime(Process::CLOCK_REALTIME) - transaction.start_time,
      0.0
    ].max
    NewRelic::Agent.record_metric("ClientApplication/#{id}/all", app_time_in_seconds)
  end
end