class Fluent::SentryOutput

Constants

DEFAULT_HOSTNAME_COMMAND
EVENT_KEYS
LOG_LEVEL

Public Class Methods

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

  super
end

Public Instance Methods

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

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

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

  hostname_command = @hostname_command || DEFAULT_HOSTNAME_COMMAND
  @hostname = `#{hostname_command}`.chomp

  @configuration = Raven::Configuration.new
  @configuration.server = @endpoint_url
  @configuration.server_name = @hostname
  @client = Raven::Client.new(@configuration)
end
format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_sentry.rb, line 47
def format(tag, time, record)
  [tag, time, record].to_msgpack
end
notify_sentry(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_sentry.rb, line 65
def notify_sentry(tag, time, record)
  event = Raven::Event.new(
    :configuration => @configuration, 
    :context => Raven::Context.new, 
    :message => record['message']
  )
  event.timestamp = record['timestamp'] || Time.at(time).utc.strftime('%Y-%m-%dT%H:%M:%S')
  event.time_spent = record['time_spent'] || nil
  event.level = record['level'] || @default_level
  event.logger = record['logger'] || @default_logger
  event.server_name = record['server_name'] || @hostname
  event.release = record['release'] if record['release']
  event.tags = event.tags.merge({ :tag => tag }.merge(record['tags'] || {}))
  event.extra = record.reject{ |key| EVENT_KEYS.include?(key) }
  @client.send_event(event)
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_sentry.rb, line 51
def shutdown
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_sentry.rb, line 43
def start
  super
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_sentry.rb, line 55
def write(chunk)
  chunk.msgpack_each do |tag, time, record|
    begin
      notify_sentry(tag, time, record)
    rescue => e
      $log.error("Sentry Error:", :error_class => e.class, :error => e.message)
    end
  end
end