diff --git a/lib/logstash/plugin_mixins/elasticsearch/common.rb b/lib/logstash/plugin_mixins/elasticsearch/common.rb index 8e7f92408..130428232 100644 --- a/lib/logstash/plugin_mixins/elasticsearch/common.rb +++ b/lib/logstash/plugin_mixins/elasticsearch/common.rb @@ -1,4 +1,5 @@ require "logstash/outputs/elasticsearch/template_manager" +require "logstash/json" module LogStash; module PluginMixins; module ElasticSearch module Common @@ -237,8 +238,8 @@ def handle_dlq_response(message, action, status, response) if @dlq_writer # TODO: Change this to send a map with { :status => status, :action => action } in the future - detailed_message = "#{message} status: #{status}, action: #{action_params}, response: #{response}" - @dlq_writer.write(event, "#{detailed_message}") + detailed_message = "#{message} status: #{status}, action: #{LogStash::Json.dump(action_params)}, response: #{LogStash::Json.dump(response)}" + @dlq_writer.write(event, detailed_message) else log_level = dig_value(response, 'index', 'error', 'type') == 'invalid_index_name_exception' ? :error : :warn diff --git a/spec/unit/outputs/elasticsearch_spec.rb b/spec/unit/outputs/elasticsearch_spec.rb index 7a71e2e8c..cca42cdb9 100644 --- a/spec/unit/outputs/elasticsearch_spec.rb +++ b/spec/unit/outputs/elasticsearch_spec.rb @@ -1475,7 +1475,9 @@ expect( event ).to be_a LogStash::Event expect( event ).to be events.first expect( reason ).to start_with "Could not index event to Elasticsearch. status: #{error_code}, action: [\"index\"" - expect( reason ).to match /_id=>"bar".*"foo"=>"bar".*response:.*"reason"=>"TEST"/ + expect( reason ).to include '"_id":"bar"' + expect( reason ).to include '"foo":"bar"' + expect( reason ).to include '"reason":"TEST"' method.call(*args) # won't hurt to call LogStash::Util::DummyDeadLetterQueueWriter end.once