Class: NewRelic::Agent::LogEventAggregator
Constant Summary
collapse
- LEVEL_KEY =
'level'.freeze
- MESSAGE_KEY =
'message'.freeze
- TIMESTAMP_KEY =
'timestamp'.freeze
- PRIORITY_KEY =
'priority'.freeze
- LINES =
'Logging/lines'.freeze
- DROPPED_METRIC =
'Logging/Forwarding/Dropped'.freeze
- SEEN_METRIC =
'Supportability/Logging/Forwarding/Seen'.freeze
- SENT_METRIC =
'Supportability/Logging/Forwarding/Sent'.freeze
- LOGGER_SUPPORTABILITY_FORMAT =
'Supportability/Logging/Ruby/Logger/%s'.freeze
- LOGSTASHER_SUPPORTABILITY_FORMAT =
'Supportability/Logging/Ruby/LogStasher/%s'.freeze
- METRICS_SUPPORTABILITY_FORMAT =
'Supportability/Logging/Metrics/Ruby/%s'.freeze
- FORWARDING_SUPPORTABILITY_FORMAT =
'Supportability/Logging/Forwarding/Ruby/%s'.freeze
- DECORATING_SUPPORTABILITY_FORMAT =
'Supportability/Logging/LocalDecorating/Ruby/%s'.freeze
- MAX_BYTES =
32 * 1024 bytes (32 kibibytes)
32768
- OVERALL_ENABLED_KEY =
:'application_logging.enabled'
- METRICS_ENABLED_KEY =
:'application_logging.metrics.enabled'
- FORWARDING_ENABLED_KEY =
:'application_logging.forwarding.enabled'
- DECORATING_ENABLED_KEY =
:'application_logging.local_decorating.enabled'
- LOG_LEVEL_KEY =
:'application_logging.forwarding.log_level'
- CUSTOM_ATTRIBUTES_KEY =
:'application_logging.forwarding.custom_attributes'
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.payload_to_melt_format(data) ⇒ Object
Because our transmission format (MELT) is different than historical agent payloads, extract the munging here to keep the service focused on the general harvest + transmit instead of the format.
Instance Method Summary
collapse
#after_initialize, buffer_class, capacity_key, #enabled?, enabled_fn, enabled_keys, #has_metadata?, #merge!, named
Constructor Details
Returns a new instance of LogEventAggregator.
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
44
45
46
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 44
def attributes
@attributes
end
|
Class Method Details
Because our transmission format (MELT) is different than historical agent payloads, extract the munging here to keep the service focused on the general harvest + transmit instead of the format.
Payload shape matches the publicly documented MELT format. docs.newrelic.com/docs/logs/log-api/introduction-log-api
We have to keep the aggregated payloads in a separate shape, though, to work with the priority sampling buffers
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 198
def self.payload_to_melt_format(data)
common_attributes = LinkingMetadata.append_service_linking_metadata({})
common_attributes.delete(ENTITY_TYPE_KEY)
common_attributes.merge!(NewRelic::Agent.agent.log_event_aggregator.attributes.custom_attributes)
_, items = data
payload = [{
common: {attributes: common_attributes},
logs: items.map(&:last)
}]
return [payload, items.size]
end
|
Instance Method Details
#add_custom_attributes(custom_attributes) ⇒ Object
185
186
187
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 185
def add_custom_attributes(custom_attributes)
attributes.add_custom_attributes(custom_attributes)
end
|
141
142
143
144
145
146
147
148
149
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 141
def add_event_metadata(formatted_message, severity)
metadata = {
LEVEL_KEY => severity,
TIMESTAMP_KEY => Process.clock_gettime(Process::CLOCK_REALTIME) * 1000
}
metadata[MESSAGE_KEY] = formatted_message unless formatted_message.nil?
LinkingMetadata.append_trace_linking_metadata(metadata)
end
|
#add_logstasher_event_attributes(event, log) ⇒ Object
175
176
177
178
179
180
181
182
183
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 175
def add_logstasher_event_attributes(event, log)
log_copy = log.dup
log_copy.delete('message')
log_copy.delete('level')
log_copy.delete('@timestamp')
event['attributes'] = log_copy
end
|
#capacity ⇒ Object
57
58
59
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 57
def capacity
@buffer.capacity
end
|
#create_event(priority, formatted_message, severity) ⇒ Object
160
161
162
163
164
165
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 160
def create_event(priority, formatted_message, severity)
formatted_message = truncate_message(formatted_message)
event = add_event_metadata(formatted_message, severity)
create_prioritized_event(priority, event)
end
|
#create_logstasher_event(priority, severity, log) ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 167
def create_logstasher_event(priority, severity, log)
formatted_message = log['message'] ? truncate_message(log['message']) : nil
event = add_event_metadata(formatted_message, severity)
add_logstasher_event_attributes(event, log)
create_prioritized_event(priority, event)
end
|
#create_prioritized_event(priority, event) ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 151
def create_prioritized_event(priority, event)
[
{
PrioritySampledBuffer::PRIORITY_KEY => priority
},
event
]
end
|
#determine_severity(log) ⇒ Object
114
115
116
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 114
def determine_severity(log)
log['level'] ? log['level'].to_s.upcase : 'UNKNOWN'
end
|
#harvest! ⇒ Object
216
217
218
219
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 216
def harvest!
record_customer_metrics()
super
end
|
#increment_event_counters(severity) ⇒ Object
118
119
120
121
122
123
124
125
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 118
def increment_event_counters(severity)
return unless NewRelic::Agent.config[METRICS_ENABLED_KEY]
@counter_lock.synchronize do
@seen += 1
@seen_by_severity[severity] += 1
end
end
|
#logger_enabled? ⇒ Boolean
230
231
232
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 230
def logger_enabled?
@enabled && @instrumentation_logger_enabled
end
|
#logstasher_enabled? ⇒ Boolean
#monitoring_conditions_met?(severity) ⇒ Boolean
110
111
112
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 110
def monitoring_conditions_met?(severity)
!severity_too_low?(severity) && NewRelic::Agent.config[FORWARDING_ENABLED_KEY] && !@high_security
end
|
#record(formatted_message, severity) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 61
def record(formatted_message, severity)
return unless logger_enabled?
severity = 'UNKNOWN' if severity.nil? || severity.empty?
increment_event_counters(severity)
return if formatted_message.nil? || formatted_message.empty?
return unless monitoring_conditions_met?(severity)
txn = NewRelic::Agent::Transaction.tl_current
priority = LogPriority.priority_for(txn)
return txn.add_log_event(create_event(priority, formatted_message, severity)) if txn
@lock.synchronize do
@buffer.append(priority: priority) do
create_event(priority, formatted_message, severity)
end
end
rescue
nil
end
|
#record_batch(txn, logs) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 127
def record_batch(txn, logs)
priority = LogPriority.priority_for(txn)
logs.each do |log|
log.first[PRIORITY_KEY] = priority
end
@lock.synchronize do
logs.each do |log|
@buffer.append(event: log)
end
end
end
|
#record_logstasher_event(log) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 84
def record_logstasher_event(log)
return unless logstasher_enabled?
return if log.key?('message') && (log['message'].nil? || log['message'].empty?)
severity = determine_severity(log)
increment_event_counters(severity)
return unless monitoring_conditions_met?(severity)
txn = NewRelic::Agent::Transaction.tl_current
priority = LogPriority.priority_for(txn)
return txn.add_log_event(create_logstasher_event(priority, severity, log)) if txn
@lock.synchronize do
@buffer.append(priority: priority) do
create_logstasher_event(priority, severity, log)
end
end
rescue
nil
end
|
#reset! ⇒ Object
221
222
223
224
225
226
227
228
|
# File 'lib/new_relic/agent/log_event_aggregator.rb', line 221
def reset!
@counter_lock.synchronize do
@seen = 0
@seen_by_severity.clear
end
super
end
|