class Fluent::SentryOutput
Constants
- DEFAULT_ENVIRONMENT
- 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 18 def initialize require 'time' require 'sentry-ruby' require 'fluent/plugin/output' super end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_sentry.rb, line 26 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 @default_environment = DEFAULT_ENVIRONMENT @configuration = Sentry::Configuration.new @configuration.send_modules = false @configuration.debug = true @configuration.dsn = @endpoint_url @configuration.server_name = @hostname @client = Sentry::Client.new(@configuration) end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_sentry.rb, line 53 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 73 def notify_sentry(tag, time, record) event = Sentry::Event.new( :configuration => @configuration, :message => record['message'] ) event.timestamp = record['timestamp'] || Time.at(time).utc.strftime('%Y-%m-%dT%H:%M:%S') event.level = record['level'] || @default_level event.environment = record['clustername'] || @default_environment event.tags = event.tags.merge({ :tag => tag }.merge(record['kubernetes'] || {})) event.contexts[:Fields] = record['fields'] || {} @client.send_event(event) end
shutdown()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_sentry.rb, line 57 def shutdown super end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_sentry.rb, line 49 def start super end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_sentry.rb, line 61 def write(chunk) chunk.msgpack_each do |tag, time, record| begin if record.key?('level') and record['level'] == 'error' notify_sentry(tag, time, record) end rescue => e $log.error("Sentry Error:", :error_class => e.class, :error => e.message) end end end