diff --git a/lib/rackstash/flow.rb b/lib/rackstash/flow.rb index 6526f39..5fe67d3 100644 --- a/lib/rackstash/flow.rb +++ b/lib/rackstash/flow.rb @@ -235,15 +235,16 @@ module Rackstash private def log_error(message, exception) + message = Rackstash::Message.new(message, severity: ERROR) + error_event = { FIELD_ERROR => exception.class.name, FIELD_ERROR_MESSAGE => exception.message, FIELD_ERROR_TRACE => (exception.backtrace || []).join("\n"), FIELD_TAGS => [], - FIELD_MESSAGE => message, - FIELD_TIMESTAMP => Time.now.utc.iso8601(ISO8601_PRECISION).freeze, - FIELD_VERSION => '1'.freeze + FIELD_MESSAGE => [message], + FIELD_TIMESTAMP => message.time } error_flow.write!(error_event) rescue diff --git a/spec/rackstash/flow_spec.rb b/spec/rackstash/flow_spec.rb index 836f3f7..1b17cff 100644 --- a/spec/rackstash/flow_spec.rb +++ b/spec/rackstash/flow_spec.rb @@ -83,10 +83,15 @@ describe Rackstash::Flow do it 'rescues any exception thrown by the adapter' do error_flow = instance_double(described_class) expect(error_flow).to receive(:write!) - .with hash_including( - 'message' => /^close failed for adapter/, + .with( 'error' => 'RuntimeError', - 'error_message' => 'ERROR' + 'error_message' => 'ERROR', + 'error_trace' => instance_of(String), + + 'tags' => [], + 'message' => [instance_of(Rackstash::Message)], + + '@timestamp' => instance_of(Time) ) expect(flow).to receive(:error_flow).and_return(error_flow) @@ -242,10 +247,15 @@ describe Rackstash::Flow do it 'rescues any exception thrown by the adapter' do error_flow = instance_double(described_class) expect(error_flow).to receive(:write!) - .with hash_including( - 'message' => /^reopen failed for adapter/, + .with( 'error' => 'RuntimeError', - 'error_message' => 'ERROR' + 'error_message' => 'ERROR', + 'error_trace' => instance_of(String), + + 'tags' => [], + 'message' => [instance_of(Rackstash::Message)], + + '@timestamp' => instance_of(Time) ) expect(flow).to receive(:error_flow).and_return(error_flow) @@ -306,10 +316,15 @@ describe Rackstash::Flow do it 'rescues any exception thrown by the adapter' do error_flow = instance_double(described_class) expect(error_flow).to receive(:write!) - .with hash_including( - 'message' => /^write failed for adapter/, + .with( 'error' => 'RuntimeError', - 'error_message' => 'ERROR' + 'error_message' => 'ERROR', + 'error_trace' => instance_of(String), + + 'tags' => [], + 'message' => [instance_of(Rackstash::Message)], + + '@timestamp' => instance_of(Time) ) expect(flow).to receive(:error_flow).and_return(error_flow)