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_REQUEST_METHOD_KEY =
'http.request.method'
HTTP_STATUS_CODE_KEY =
'http.statusCode'
COMPONENT_KEY =
'component'
DB_INSTANCE_KEY =
'db.instance'
DB_STATEMENT_KEY =
'db.statement'
DB_SYSTEM_KEY =
'db.system'
PEER_ADDRESS_KEY =
'peer.address'
PEER_HOSTNAME_KEY =
'peer.hostname'
SERVER_ADDRESS_KEY =
'server.address'
SERVER_PORT_KEY =
'server.port'
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'
DB_STATEMENT_MAX_BYTES =
4096

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.

[View source]

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

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

rubocop:disable Metrics/AbcSize

[View source]

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/new_relic/agent/span_event_primitive.rb', line 93

def for_datastore_segment(segment) # rubocop:disable Metrics/AbcSize
  intrinsics = intrinsics_for(segment)

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

  agent_attributes = {}

  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
    [PEER_HOSTNAME_KEY, SERVER_ADDRESS_KEY].each do |key|
      agent_attributes[key] = truncate(segment.host) if allowed?(key)
    end
  end
  if segment.port_path_or_id&.match?(/^\d+$/) && allowed?(SERVER_PORT_KEY)
    agent_attributes[SERVER_PORT_KEY] = segment.port_path_or_id
  end
  agent_attributes[DB_SYSTEM_KEY] = segment.product if allowed?(DB_SYSTEM_KEY)

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

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

#for_external_request_segment(segment) ⇒ Object

[View source]

73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/new_relic/agent/span_event_primitive.rb', line 73

def for_external_request_segment(segment)
  intrinsics = intrinsics_for(segment)

  intrinsics[COMPONENT_KEY] = segment.library
  intrinsics[HTTP_METHOD_KEY] = segment.procedure
  intrinsics[HTTP_REQUEST_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
  intrinsics[SERVER_ADDRESS_KEY] = segment.uri.host
  intrinsics[SERVER_PORT_KEY] = segment.uri.port
  agent_attributes = {}

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

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

#for_segment(segment) ⇒ Object

[View source]

66
67
68
69
70
71
# File 'lib/new_relic/agent/span_event_primitive.rb', line 66

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

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