class Fluent::RaygunOutput

Constants

DEFAULT_HOSTNAME_COMMAND
EVENT_KEYS
LOG_LEVEL

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_raygun.rb, line 18
def initialize
  require 'time'

  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_raygun.rb, line 24
def configure(conf)
  super

  if @endpoint_url.nil?
    raise Fluent::ConfigError, "Raygun: missing parameter for 'endpoint_url'"
  end

  unless LOG_LEVEL.include?(@default_level)
    raise Fluent::ConfigError, "Raygun: unsupported default reporting log level for 'default_level'"
  end

  hostname_command = @hostname_command || DEFAULT_HOSTNAME_COMMAND
  @hostname = `#{hostname_command}`.chomp
end
default_payload_format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_raygun.rb, line 87
def default_payload_format(tag, time, record)
  {
    occurredOn: Time.at(time).utc.iso8601,
    details: {
      machineName: @hostname,
      error: {
        message: record['messages']
      },
      tags: [tag]
    }
  }
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_raygun.rb, line 55
def format(tag, time, record)
  [tag, time, record].to_msgpack
end
notify_raygun(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_raygun.rb, line 69
def notify_raygun(tag, time, record)
  payload =
    if @record_already_formatted
      # Setting @record_already_formatted = true, means you
      # are already happy with the formatting of 'record'
      record
    else
      default_payload_format(tag, time, record)
    end

  post = Net::HTTP::Post.new(
    "#{@endpoint_url}/entries?apikey=#{URI.encode(@api_key)}"
  )
  post.body = JSON.generate(payload)

  @http.request(@uri, post)
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_raygun.rb, line 39
def start
  super

  require 'net/http/persistent'
  require 'uri'

  @uri = URI @endpoint_url
  @http = Net::HTTP::Persistent.new
  @http.headers['Content-Type'] = 'text/json'
  @http.headers['X-ApiKey'] = @api_key
  @http.idle_timeout = 10
  @http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]

  log.debug 'Started Raygun fluent shipper..'
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_raygun.rb, line 59
def write(chunk)
  chunk.msgpack_each do |tag, time, record|
    begin
      notify_raygun(tag, time, record)
    rescue StandardError => e
      $log.error('Raygun Error:', error_class: e.class, error: e.message)
    end
  end
end