Module: NewRelic::Agent::Transaction::DistributedTracing

Defined in:
lib/new_relic/agent/transaction/distributed_tracing.rb

Constant Summary collapse

SUPPORTABILITY_DISTRIBUTED_TRACE =
'Supportability/DistributedTrace'
CREATE_PREFIX =
"#{SUPPORTABILITY_DISTRIBUTED_TRACE}/CreatePayload"
ACCEPT_PREFIX =
"#{SUPPORTABILITY_DISTRIBUTED_TRACE}/AcceptPayload"
IGNORE_PREFIX =
"#{ACCEPT_PREFIX}/Ignored"
CREATE_SUCCESS_METRIC =
"#{CREATE_PREFIX}/Success"
CREATE_EXCEPTION_METRIC =
"#{CREATE_PREFIX}/Exception"
ACCEPT_SUCCESS_METRIC =
"#{ACCEPT_PREFIX}/Success"
ACCEPT_EXCEPTION_METRIC =
"#{ACCEPT_PREFIX}/Exception"
ACCEPT_PARSE_EXCEPTION_METRIC =
"#{ACCEPT_PREFIX}/ParseException"
IGNORE_ACCEPT_AFTER_CREATE_METRIC =
"#{IGNORE_PREFIX}/CreateBeforeAccept"
IGNORE_MULTIPLE_ACCEPT_METRIC =
"#{IGNORE_PREFIX}/Multiple"
IGNORE_ACCEPT_NULL_METRIC =
"#{IGNORE_PREFIX}/Null"
IGNORE_ACCEPT_MAJOR_VERSION_METRIC =
"#{IGNORE_PREFIX}/MajorVersion"
IGNORE_ACCEPT_UNTRUSTED_ACCOUNT_METRIC =
"#{IGNORE_PREFIX}/UntrustedAccount"
LBRACE =
'{'
NULL_PAYLOAD =
'null'
NEWRELIC_TRACE_KEY =
'HTTP_NEWRELIC'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#distributed_trace_payloadObject



13
14
15
# File 'lib/new_relic/agent/transaction/distributed_tracing.rb', line 13

def distributed_trace_payload
  @distributed_trace_payload
end

#distributed_trace_payload_created=(value) ⇒ Object (writeonly)



14
15
16
# File 'lib/new_relic/agent/transaction/distributed_tracing.rb', line 14

def distributed_trace_payload_created=(value)
  @distributed_trace_payload_created = value
end

Instance Method Details

#accept_distributed_trace_payload(payload) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/new_relic/agent/transaction/distributed_tracing.rb', line 62

def accept_distributed_trace_payload(payload)
  return unless Agent.config[:'distributed_tracing.enabled']

  return false if check_payload_ignored(payload)
  return false unless check_payload_present(payload)
  return false unless payload = decode_payload(payload)
  return false unless check_required_fields_present(payload)
  return false unless check_valid_version(payload)
  return false unless (payload)

  assign_payload_and_sampling_params(payload)

  NewRelic::Agent.increment_metric(ACCEPT_SUCCESS_METRIC)
  true
rescue => e
  NewRelic::Agent.increment_metric(ACCEPT_EXCEPTION_METRIC)
  NewRelic::Agent.logger.warn('Failed to accept distributed trace payload', e)
  false
end

#accept_distributed_tracing_incoming_request(request) ⇒ Object



38
39
40
41
42
43
# File 'lib/new_relic/agent/transaction/distributed_tracing.rb', line 38

def accept_distributed_tracing_incoming_request(request)
  return unless Agent.config[:'distributed_tracing.enabled']
  return unless payload = request[NEWRELIC_TRACE_KEY]

  accept_distributed_trace_payload(payload)
end

#create_distributed_trace_payloadObject



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

def create_distributed_trace_payload
  return unless Agent.config[:'distributed_tracing.enabled']

  @distributed_trace_payload_created = true
  payload = DistributedTracePayload.for_transaction(transaction)
  NewRelic::Agent.increment_metric(CREATE_SUCCESS_METRIC)
  payload
rescue => e
  NewRelic::Agent.increment_metric(CREATE_EXCEPTION_METRIC)
  NewRelic::Agent.logger.warn('Failed to create distributed trace payload', e)
  nil
end

#distributed_trace_payload_created?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/new_relic/agent/transaction/distributed_tracing.rb', line 45

def distributed_trace_payload_created?
  @distributed_trace_payload_created ||= false
end