Class: Fluent::TraceAccumulator
- Inherits:
-
Object
- Object
- Fluent::TraceAccumulator
- Defined in:
- lib/fluent/plugin/exception_detector.rb
Overview
Buffers and groups log records if they contain exception stack traces.
Instance Attribute Summary collapse
-
#buffer_start_time ⇒ Object
readonly
Returns the value of attribute buffer_start_time.
Instance Method Summary collapse
- #flush ⇒ Object
- #force_flush ⇒ Object
-
#initialize(message_field, languages, **options, &emit_callback) ⇒ TraceAccumulator
constructor
If message_field is nil, the instance is set up to accumulate records that are plain strings (i.e. the whole record is concatenated).
- #push(time_sec, record) ⇒ Object
Constructor Details
#initialize(message_field, languages, **options, &emit_callback) ⇒ TraceAccumulator
If message_field is nil, the instance is set up to accumulate records that are plain strings (i.e. the whole record is concatenated). Otherwise, the instance accepts records that are dictionaries (usually originating from structured JSON logs) and accumulates just the content of the given message field. message_field may contain the empty string. In this case, the TraceAccumulator ‘learns’ the field name from the first record by checking for some pre-defined common field names of text logs. The option parameter can be used to pass the following parameters: force_line_breaks adds line breaks when combining exception stacks max_lines and max_bytes limit the maximum amount of data to be buffered. The default value 0 indicates ‘no limit’.
315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/fluent/plugin/exception_detector.rb', line 315 def initialize(, languages, **, &emit_callback) @exception_detector = Fluent::ExceptionDetector.new(*languages) @message_field = @force_line_breaks = [:force_line_breaks] || false @max_lines = [:max_lines] || 0 @max_bytes = [:max_bytes] || 0 @emit = emit_callback @messages = [] @buffer_start_time = Time.now @buffer_size = 0 @first_record = nil @first_timestamp = nil end |
Instance Attribute Details
#buffer_start_time ⇒ Object (readonly)
Returns the value of attribute buffer_start_time.
301 302 303 |
# File 'lib/fluent/plugin/exception_detector.rb', line 301 def buffer_start_time @buffer_start_time end |
Instance Method Details
#flush ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/fluent/plugin/exception_detector.rb', line 345 def flush case @messages.length when 0 return when 1 @emit.call(@first_timestamp, @first_record) else = @messages.join if @message_field.nil? output_record = else output_record = @first_record output_record[@message_field] = end @emit.call(@first_timestamp, output_record) end @messages = [] @first_record = nil @first_timestamp = nil @buffer_size = 0 end |
#force_flush ⇒ Object
367 368 369 370 |
# File 'lib/fluent/plugin/exception_detector.rb', line 367 def force_flush flush @exception_detector.reset end |
#push(time_sec, record) ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/fluent/plugin/exception_detector.rb', line 329 def push(time_sec, record) = (record) if .nil? @exception_detector.reset detection_status = :no_trace else force_flush if @max_bytes > 0 && @buffer_size + .length > @max_bytes detection_status = @exception_detector.update() end update_buffer(detection_status, time_sec, record, ) force_flush if @max_lines > 0 && @messages.length == @max_lines end |