Module: NewRelic::Agent::SpanEventPrimitive

Extended by:
SpanEventPrimitive
Includes:
Coerce
Included in:
SpanEventPrimitive
Defined in:
lib/new_relic/agent/span_event_primitive.rb

Constant Summary collapse

ELLIPSIS =

Strings for static keys of the event structure

'...'
TYPE_KEY =
'type'
TRACE_ID_KEY =
'traceId'
GUID_KEY =
'guid'
PARENT_ID_KEY =
'parentId'
TRANSACTION_ID_KEY =
'transactionId'
SAMPLED_KEY =
'sampled'
PRIORITY_KEY =
'priority'
TIMESTAMP_KEY =
'timestamp'
DURATION_KEY =
'duration'
NAME_KEY =
'name'
CATEGORY_KEY =
'category'
HTTP_URL_KEY =
'http.url'
HTTP_METHOD_KEY =
'http.method'
HTTP_STATUS_CODE_KEY =
'http.statusCode'
COMPONENT_KEY =
'component'
DB_INSTANCE_KEY =
'db.instance'
DB_STATEMENT_KEY =
'db.statement'
PEER_ADDRESS_KEY =
'peer.address'
PEER_HOSTNAME_KEY =
'peer.hostname'
SPAN_KIND_KEY =
'span.kind'
ENTRY_POINT_KEY =
'nr.entryPoint'
TRUSTED_PARENT_KEY =
'trustedParentId'
TRACING_VENDORS_KEY =
'tracingVendors'
TRANSACTION_NAME_KEY =
'transaction.name'
EVENT_TYPE =

Strings for static values of the event structure

'Span'
GENERIC_CATEGORY =
'generic'
HTTP_CATEGORY =
'http'
DATASTORE_CATEGORY =
'datastore'
CLIENT =
'client'

Instance Method Summary collapse

Methods included from Coerce

boolean_int!, float, float!, int, int!, int_or_nil, log_failure, scalar, string, value_or_nil

Instance Method Details

#error_attributes(segment) ⇒ Object

Builds a Hash of error attributes as well as the Span ID when an error is present. Otherwise, returns nil when no error present.



53
54
55
56
57
58
# File 'lib/new_relic/agent/span_event_primitive.rb', line 53

def error_attributes(segment)
  return if Agent.config[:high_security] || !segment.noticed_error

  segment.noticed_error.build_error_attributes
  segment.noticed_error_attributes
end

#for_datastore_segment(segment) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/new_relic/agent/span_event_primitive.rb', line 89

def for_datastore_segment(segment)
  intrinsics = intrinsics_for(segment)

  intrinsics[COMPONENT_KEY] = segment.product
  intrinsics[SPAN_KIND_KEY] = CLIENT
  intrinsics[CATEGORY_KEY] = DATASTORE_CATEGORY

  agent_attributes = error_attributes(segment) || {}

  if segment.database_name && allowed?(DB_INSTANCE_KEY)
    agent_attributes[DB_INSTANCE_KEY] = truncate(segment.database_name)
  end
  if segment.host && segment.port_path_or_id && allowed?(PEER_ADDRESS_KEY)
    agent_attributes[PEER_ADDRESS_KEY] = truncate("#{segment.host}:#{segment.port_path_or_id}")
  end
  if segment.host && allowed?(PEER_HOSTNAME_KEY)
    agent_attributes[PEER_HOSTNAME_KEY] = truncate(segment.host)
  end

  if segment.sql_statement && allowed?(DB_STATEMENT_KEY)
    agent_attributes[DB_STATEMENT_KEY] = truncate(segment.sql_statement.safe_sql, 2000)
  elsif segment.nosql_statement && allowed?(DB_STATEMENT_KEY)
    agent_attributes[DB_STATEMENT_KEY] = truncate(segment.nosql_statement, 2000)
  end

  [intrinsics, custom_attributes(segment), agent_attributes]
end

#for_external_request_segment(segment) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/new_relic/agent/span_event_primitive.rb', line 67

def for_external_request_segment(segment)
  intrinsics = intrinsics_for(segment)

  intrinsics[COMPONENT_KEY] = segment.library
  intrinsics[HTTP_METHOD_KEY] = segment.procedure
  intrinsics[HTTP_STATUS_CODE_KEY] = segment.http_status_code if segment.http_status_code
  intrinsics[CATEGORY_KEY] = HTTP_CATEGORY
  intrinsics[SPAN_KIND_KEY] = CLIENT

  agent_attributes = error_attributes(segment) || {}

  if allowed?(HTTP_URL_KEY)
    agent_attributes[HTTP_URL_KEY] = truncate(segment.uri)
  end

  if segment.respond_to?(:record_agent_attributes?) && segment.record_agent_attributes?
    agent_attributes.merge!(agent_attributes(segment))
  end

  [intrinsics, custom_attributes(segment), agent_attributes]
end

#for_segment(segment) ⇒ Object



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

def for_segment(segment)
  intrinsics = intrinsics_for(segment)
  intrinsics[CATEGORY_KEY] = GENERIC_CATEGORY

  [intrinsics, custom_attributes(segment), agent_attributes(segment)]
end