Class: Fluent::SentryOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::SentryOutput
- Includes:
- HandleTagNameMixin
- Defined in:
- lib/fluent/plugin/out_sentry.rb
Constant Summary collapse
- LOG_LEVEL =
%w(fatal error warning info debug)
- EVENT_KEYS =
%w(message timestamp time_spent level logger culprit server_name release tags)
- DEFAULT_HOSTNAME_COMMAND =
'hostname'
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ SentryOutput
constructor
A new instance of SentryOutput.
- #notify_sentry(tag, time, record) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ SentryOutput
Returns a new instance of SentryOutput.
16 17 18 19 20 21 22 23 |
# File 'lib/fluent/plugin/out_sentry.rb', line 16 def initialize require 'time' require 'json' require 'sentry-ruby' require 'fluent/plugin/output' super end |
Instance Method Details
#configure(conf) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fluent/plugin/out_sentry.rb', line 25 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 = 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) ⇒ Object
51 52 53 |
# File 'lib/fluent/plugin/out_sentry.rb', line 51 def format(tag, time, record) [tag, time, record].to_msgpack end |
#notify_sentry(tag, time, record) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/fluent/plugin/out_sentry.rb', line 69 def notify_sentry(tag, time, record) #$log.warning("Message: ",:error => record['message']) $log.error 'writing data', record.to_json event = Sentry::Event.new( :configuration => @configuration, :message => record['message'] ) event. = record['timestamp'] || Time.at(time).utc.strftime('%Y-%m-%dT%H:%M:%S') event.level = record['level'] || @default_level #event.logger = record['logger'] || @default_logger #event.culprit = record['culprit'] || nil #event.server_name = record['server_name'] || @hostname #event.release = record['release'] if record['release'] event. = event..merge({ :tag => tag }.merge(record['tags'] || {})) #event.extra = record.reject{ |key| EVENT_KEYS.include?(key) } @client.send_event(event) end |
#shutdown ⇒ Object
55 56 57 |
# File 'lib/fluent/plugin/out_sentry.rb', line 55 def shutdown super end |
#start ⇒ Object
47 48 49 |
# File 'lib/fluent/plugin/out_sentry.rb', line 47 def start super end |
#write(chunk) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/fluent/plugin/out_sentry.rb', line 59 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.) end end end |