Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ The plugin supports the following parameters:
This parameter is only applicable to structured (JSON) log streams.
Default: ''.

[join_separator] String used when joining multiple lines of the stack trace.
Default: ''.

Example configuration:

<match **>
Expand Down
5 changes: 3 additions & 2 deletions lib/fluent/plugin/exception_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ class TraceAccumulator
# The named parameters max_lines and max_bytes limit the maximum amount
# of data to be buffered. The default value 0 indicates 'no limit'.
def initialize(message_field, languages, max_lines: 0, max_bytes: 0,
&emit_callback)
join_separator: '', &emit_callback)
@exception_detector = Fluent::ExceptionDetector.new(*languages)
@max_lines = max_lines
@max_bytes = max_bytes
@join_separator = join_separator
@message_field = message_field
@messages = []
@buffer_start_time = Time.now
Expand Down Expand Up @@ -230,7 +231,7 @@ def flush
when 1
@emit.call(@first_timestamp, @first_record)
else
combined_message = @messages.join
combined_message = @messages.join(@join_separator)
if @message_field.nil?
output_record = combined_message
else
Expand Down
5 changes: 4 additions & 1 deletion lib/fluent/plugin/out_detect_exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class DetectExceptionsOutput < Output
config_param :max_bytes, :integer, default: 0
desc 'Separate log streams by this field in the input JSON data.'
config_param :stream, :string, default: ''
desc 'String used when joining multiple lines of the stack trace'
config_param :join_separator, :string, default: ''

Fluent::Plugin.register_output('detect_exceptions', self)

Expand Down Expand Up @@ -93,7 +95,8 @@ def process_record(tag, time_sec, record)
@accumulators[log_id] =
Fluent::TraceAccumulator.new(@message, @languages,
max_lines: @max_lines,
max_bytes: @max_bytes) do |t, r|
max_bytes: @max_bytes,
join_separator: @join_separator) do |t, r|
router.emit(out_tag, t, r)
end
end
Expand Down
13 changes: 13 additions & 0 deletions test/plugin/test_exception_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,17 @@ def test_low_max_bytes_limit
# Check that the trace is flushed after the first part.
assert_equal([JAVA_EXC_PART1] + JAVA_EXC_PART2.lines, out)
end

def test_join_separator
# Custom join separator is used to join accumulated output
join_separator = ';'
out = []
buffer = Fluent::TraceAccumulator.new(nil,
[:all],
join_separator: join_separator) do |_, m|
out << m
end
feed_lines(buffer, JAVA_EXC)
assert_equal(JAVA_EXC.lines.length - 1, out[0].count(join_separator))
end
end