Class: Eventoverse::BaseReporter

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/eventoverse/base_reporter.rb

Direct Known Subclasses

AmqpReporterJRuby, AmqpReporterMri, UdpReporter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.publish_message(*args) ⇒ Object

publish_message



33
34
35
# File 'lib/eventoverse/base_reporter.rb', line 33

def self.publish_message(*args)
  self.instance.publish_message(args)
end

Instance Method Details

#publish_exception(exception, additional_info = {}) ⇒ Object

self.publish_message(*args)



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/eventoverse/base_reporter.rb', line 37

def publish_exception(exception, additional_info = {})
  backtrace = exception.backtrace
  backtrace_first_line = backtrace.first || ""
  md5_digest = Digest::MD5.hexdigest(backtrace_first_line)
  self.publish_message("exception", additional_info.merge({:backtrace_first_line => backtrace_first_line,
                                                           :message => exception.message,
                                                           :backtrace => backtrace.join("\n").slice(0..7000),
                                                           :md5_digest => md5_digest }))
rescue Exception => e
  puts "#{Time.now}: Can't publish exception, because of #{e.message} \n #{e.backtrace.join}"
end

#publish_message(event_type, attributes = {}, tags = []) ⇒ Object

API



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/eventoverse/base_reporter.rb', line 18

def publish_message(event_type, attributes = {}, tags = [])
  payload = {:environment => Config.get_in(Eventoverse.config, [:env]),
             :application => Config.get_in(Eventoverse.config, [:application_name]),
             :hostname => Socket.gethostname,
             :tags => tags,
             :emitted_at => Time.now.to_i * 1000,
             :type => event_type || "exception"}

  payload.merge!(:additional_info => attributes) unless attributes.nil?

  backend_publish_message(payload)
rescue Exception => e
  puts "#{Time.now}: Can't publish the message (\n\tType: #{event_type}\n\tBody: #{payload.inspect}). \n\tDetails:#{e.inspect} \n\tBacktrace: #{e.backtrace}"
end