Class: Promenade::Client::Rack::ExceptionHandler

Inherits:
Object
  • Object
show all
Extended by:
SingletonCaller
Defined in:
lib/promenade/client/rack/exception_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SingletonCaller

initialize_singleton, singleton

Constructor Details

#initialize(histogram_name:, requests_counter_name:, exceptions_counter_name:, registry:) ⇒ ExceptionHandler

Returns a new instance of ExceptionHandler.



13
14
15
16
17
18
# File 'lib/promenade/client/rack/exception_handler.rb', line 13

def initialize(histogram_name:, requests_counter_name:, exceptions_counter_name:, registry:)
  @histogram_name = histogram_name
  @requests_counter_name = requests_counter_name
  @exceptions_counter_name = exceptions_counter_name
  @registry = registry
end

Instance Attribute Details

#exceptions_counter_nameObject (readonly)

Returns the value of attribute exceptions_counter_name.



11
12
13
# File 'lib/promenade/client/rack/exception_handler.rb', line 11

def exceptions_counter_name
  @exceptions_counter_name
end

#histogram_nameObject (readonly)

Returns the value of attribute histogram_name.



11
12
13
# File 'lib/promenade/client/rack/exception_handler.rb', line 11

def histogram_name
  @histogram_name
end

#registryObject (readonly)

Returns the value of attribute registry.



11
12
13
# File 'lib/promenade/client/rack/exception_handler.rb', line 11

def registry
  @registry
end

#requests_counter_nameObject (readonly)

Returns the value of attribute requests_counter_name.



11
12
13
# File 'lib/promenade/client/rack/exception_handler.rb', line 11

def requests_counter_name
  @requests_counter_name
end

Instance Method Details

#call(exception, env_hash, duration) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/promenade/client/rack/exception_handler.rb', line 20

def call(exception, env_hash, duration)
  labels = RequestControllerActionLabeler.call(env_hash)
  labels.merge!(code: status_code_for_exception(exception))

  histogram.observe(labels, duration.to_f)
  requests_counter.increment(labels)
  exceptions_counter.increment(exception: exception.class.name)

  raise exception
end