lib/fluent/plugin/out_newrelic.rb in fluent-plugin-newrelic-0.2.7 vs lib/fluent/plugin/out_newrelic.rb in fluent-plugin-newrelic-0.2.8

- old
+ new

@@ -15,11 +15,10 @@ require 'fluent/plugin/output' require 'net/http' require 'uri' require 'zlib' -require 'json' require 'newrelic-fluentd-output/version' module Fluent module Plugin class NewrelicOutput < Fluent::Plugin::Output @@ -63,25 +62,20 @@ end def package_record(record, timestamp) packaged = { 'timestamp' => timestamp, - 'attributes' => {} + # non-intrinsic attributes get put into 'attributes' + 'attributes' => record } + # intrinsic attributes go at the top level if record.has_key?('message') - message = record['message'] - packaged['attributes'] = packaged['attributes'].merge(maybe_parse_json(message)) + packaged['message'] = record['message'] + packaged['attributes'].delete('message') end - - record.each do |key, value| - if key == 'message' - packaged['message'] = record['message'] - else - packaged['attributes'][key] = record[key] - end - end + packaged end def write(chunk) payload = { @@ -142,26 +136,8 @@ request = Net::HTTP::Post.new(@end_point.request_uri, @header) request.body = payload http.request(request) end - def maybe_parse_message_json(record) - if record.has_key?('message') - message = record['message'] - record = record.merge(maybe_parse_json(message)) - end - record - end - - def maybe_parse_json(message) - begin - parsed = JSON.parse(message) - if Hash === parsed - return parsed - end - rescue JSON::ParserError - end - return {} - end end end end