Sha256: a0742ba953bb79f3cfd6861c19701ba19b19d342ced16fb762d861ab629278cd

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

class Fluent::RavenDecoderOutput < Fluent::Output
  Fluent::Plugin.register_output('raven_decoder', self)

  unless method_defined?(:log)
    define_method('log') { $log }
  end

  unless method_defined?(:router)
    define_method('router') { Fluent::Engine }
  end

  config_param :data_field, :string, :default => 'data'
  config_param :ignore_fields, :array, :default => ['modules', 'exception']
  config_param :prefix, :string

  def initialize
    super
    require 'base64'
    require 'zlib'
    require 'multi_json'
  end

  def start
    super
  end

  def shutdown
    super
  end

  def configure(conf)
    super
  end

  def emit(tag, es, chain)
    new_tag = @prefix + '.' + tag

    es.each do |time, record|
      data = record[@data_field]

      if data
        data = decode(data)
        router.emit(new_tag, time, data)
      else
        log.warn("Raven data is not included: tag:#{new_tag} record:#{record.inspect}")
      end
    end

    chain.next
  rescue => e
    log.error(e.message + "\n" + e.backtrace.first)
  end

  private

  def decode(data)
    data = Base64.strict_decode64(data)
    data = Zlib::Inflate.inflate(data)
    data = MultiJson.load(data)

    @ignore_fields.each do |field|
      data.delete(field)
    end

    data
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-raven-decoder-0.1.1 lib/fluent/plugin/out_raven_decoder.rb