Module: NewRelic::Agent::TransactionErrorPrimitive

Extended by:
TransactionErrorPrimitive
Included in:
TransactionErrorPrimitive
Defined in:
lib/new_relic/agent/transaction_error_primitive.rb

Constant Summary collapse

SAMPLE_TYPE =
'TransactionError'.freeze
TYPE_KEY =
'type'.freeze
ERROR_CLASS_KEY =
'error.class'.freeze
ERROR_MESSAGE_KEY =
'error.message'.freeze
ERROR_EXPECTED_KEY =
'error.expected'.freeze
TIMESTAMP_KEY =
'timestamp'.freeze
PORT_KEY =
'port'.freeze
NAME_KEY =
'transactionName'.freeze
DURATION_KEY =
'duration'.freeze
SAMPLED_KEY =
'sampled'.freeze
GUID_KEY =
'nr.transactionGuid'.freeze
REFERRING_TRANSACTION_GUID_KEY =
'nr.referringTransactionGuid'.freeze
SYNTHETICS_RESOURCE_ID_KEY =
'nr.syntheticsResourceId'.freeze
SYNTHETICS_JOB_ID_KEY =
'nr.syntheticsJobId'.freeze
SYNTHETICS_MONITOR_ID_KEY =
'nr.syntheticsMonitorId'.freeze
SYNTHETICS_TYPE_KEY =
'nr.syntheticsType'
SYNTHETICS_INITIATOR_KEY =
'nr.syntheticsInitiator'
SYNTHETICS_KEY_PREFIX =
'nr.synthetics'
PRIORITY_KEY =
'priority'.freeze
SPAN_ID_KEY =
'spanId'.freeze
SYNTHETICS_PAYLOAD_EXPECTED =
[:synthetics_resource_id, :synthetics_job_id, :synthetics_monitor_id, :synthetics_type, :synthetics_initiator]

Instance Method Summary collapse

Instance Method Details

#append_cat(payload, sample) ⇒ Object



95
96
97
98
# File 'lib/new_relic/agent/transaction_error_primitive.rb', line 95

def append_cat(payload, sample)
  sample[GUID_KEY] = payload[:guid] if payload[:guid]
  sample[REFERRING_TRANSACTION_GUID_KEY] = payload[:referring_transaction_guid] if payload[:referring_transaction_guid]
end

#append_synthetics(payload, sample) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/new_relic/agent/transaction_error_primitive.rb', line 78

def append_synthetics(payload, sample)
  return unless payload[:synthetics_job_id]

  sample[SYNTHETICS_RESOURCE_ID_KEY] = payload[:synthetics_resource_id] if payload[:synthetics_resource_id]
  sample[SYNTHETICS_JOB_ID_KEY] = payload[:synthetics_job_id] if payload[:synthetics_job_id]
  sample[SYNTHETICS_MONITOR_ID_KEY] = payload[:synthetics_monitor_id] if payload[:synthetics_monitor_id]
  sample[SYNTHETICS_TYPE_KEY] = payload[:synthetics_type] if payload[:synthetics_type]
  sample[SYNTHETICS_INITIATOR_KEY] = payload[:synthetics_initiator] if payload[:synthetics_initiator]

  payload.each do |k, v|
    next unless k.to_s.start_with?('synthetics_') && !SYNTHETICS_PAYLOAD_EXPECTED.include?(k)

    new_key = SYNTHETICS_KEY_PREFIX + NewRelic::LanguageSupport.camelize(k.to_s.gsub('synthetics_', ''))
    sample[new_key] = v
  end
end

#create(noticed_error, payload, span_id) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/new_relic/agent/transaction_error_primitive.rb', line 42

def create(noticed_error, payload, span_id)
  [
    intrinsic_attributes_for(noticed_error, payload, span_id),
    noticed_error.custom_attributes,
    noticed_error.agent_attributes
  ]
end

#intrinsic_attributes_for(noticed_error, payload, span_id) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/new_relic/agent/transaction_error_primitive.rb', line 50

def intrinsic_attributes_for(noticed_error, payload, span_id)
  attrs = {
    TYPE_KEY => SAMPLE_TYPE,
    ERROR_CLASS_KEY => noticed_error.exception_class_name,
    ERROR_MESSAGE_KEY => noticed_error.message,
    ERROR_EXPECTED_KEY => noticed_error.expected,
    TIMESTAMP_KEY => noticed_error.timestamp.to_f
  }

  attrs[SPAN_ID_KEY] = span_id if span_id
  attrs[PORT_KEY] = noticed_error.request_port if noticed_error.request_port

  if payload
    attrs[NAME_KEY] = payload[:name]
    attrs[DURATION_KEY] = payload[:duration]
    attrs[SAMPLED_KEY] = payload[:sampled] if payload.key?(:sampled)
    attrs[PRIORITY_KEY] = payload[:priority]
    append_synthetics(payload, attrs)
    append_cat(payload, attrs)
    DistributedTraceAttributes.copy_to_hash(payload, attrs)
    PayloadMetricMapping.append_mapped_metrics(payload[:metrics], attrs)
  else
    attrs[PRIORITY_KEY] = rand.round(NewRelic::PRIORITY_PRECISION)
  end

  attrs
end