Class: RailsRiemannMiddleware::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_riemann_middleware.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Notifier

Returns a new instance of Notifier.



11
12
13
14
15
16
# File 'lib/rails_riemann_middleware.rb', line 11

def initialize(app, options = {})
  @app, @options = app, options
  @send_durations  = options.fetch(:send_durations, true)
  @send_exceptions = options.fetch(:send_exceptions, true)
  @event = Event.new(options)
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



9
10
11
# File 'lib/rails_riemann_middleware.rb', line 9

def event
  @event
end

#send_durationsObject (readonly)

Returns the value of attribute send_durations.



9
10
11
# File 'lib/rails_riemann_middleware.rb', line 9

def send_durations
  @send_durations
end

#send_exceptionsObject (readonly)

Returns the value of attribute send_exceptions.



9
10
11
# File 'lib/rails_riemann_middleware.rb', line 9

def send_exceptions
  @send_exceptions
end

Class Method Details

.background_exception_notification(exception) ⇒ Object



33
34
35
36
37
# File 'lib/rails_riemann_middleware.rb', line 33

def self.background_exception_notification(exception)
  event = Event.new
  env = {}
  ExceptionNotification.new(event, env, exception)
end

.exception_notification(env, exception) ⇒ Object



28
29
30
31
# File 'lib/rails_riemann_middleware.rb', line 28

def self.exception_notification(env, exception)
  event = Event.new
  ExceptionNotification.new(event, env, exception)
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/rails_riemann_middleware.rb', line 18

def call(env)
  start_time = Time.now
  @app.call(env)
rescue Exception => exception
  ExceptionNotification.new(event, env, exception).send if send_exceptions
  raise exception
ensure
  Duration.new(event, env, start_time).send if send_durations
end