Class: CC::Service::Invocation::WithMetrics
- Inherits:
-
Object
- Object
- CC::Service::Invocation::WithMetrics
- Defined in:
- lib/cc/service/invocation/with_metrics.rb
Instance Method Summary collapse
- #call ⇒ Object
- #error_key(ex) ⇒ Object
-
#initialize(invocation, statsd, prefix = nil) ⇒ WithMetrics
constructor
A new instance of WithMetrics.
- #success_key ⇒ Object
- #timing_key ⇒ Object
Constructor Details
#initialize(invocation, statsd, prefix = nil) ⇒ WithMetrics
Returns a new instance of WithMetrics.
3 4 5 6 7 |
# File 'lib/cc/service/invocation/with_metrics.rb', line 3 def initialize(invocation, statsd, prefix = nil) @invocation = invocation @statsd = statsd @prefix = prefix end |
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cc/service/invocation/with_metrics.rb', line 9 def call start_time = Time.now result = @invocation.call @statsd.increment(success_key) result rescue => ex @statsd.increment(error_key(ex)) raise ex ensure duration = ((Time.now - start_time) * 1_000).round @statsd.timing(timing_key, duration) end |
#error_key(ex) ⇒ Object
32 33 34 35 |
# File 'lib/cc/service/invocation/with_metrics.rb', line 32 def error_key(ex) error_string = ex.class.name.underscore.tr("/", "-") ["services.errors", @prefix, error_string].compact.join(".") end |
#success_key ⇒ Object
24 25 26 |
# File 'lib/cc/service/invocation/with_metrics.rb', line 24 def success_key ["services.invocations", @prefix].compact.join(".") end |
#timing_key ⇒ Object
28 29 30 |
# File 'lib/cc/service/invocation/with_metrics.rb', line 28 def timing_key ["services.timing", @prefix].compact.join(".") end |