Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 6f2806b

Browse files
committed
Merge pull request #36 from codeclimate/time_service_calls
Time service call time.
2 parents 008716a + 697f225 commit 6f2806b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/cc/service/invocation/with_metrics.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,27 @@ def initialize(invocation, statsd, prefix = nil)
77
end
88

99
def call
10+
start_time = Time.now
11+
1012
result = @invocation.call
1113
@statsd.increment(success_key)
1214

1315
result
1416
rescue => ex
1517
@statsd.increment(error_key(ex))
1618
raise ex
19+
ensure
20+
duration = ((Time.now - start_time) * 1_000)
21+
@statsd.timing(timing_key, duration)
1722
end
1823

1924
def success_key
2025
["services.invocations", @prefix].compact.join('.')
2126
end
27+
28+
def timing_key
29+
["services.timing", @prefix].compact.join('.')
30+
end
2231

2332
def error_key(ex)
2433
["services.errors", @prefix, "#{ex.class.name.underscore}"].compact.join('.')

0 commit comments

Comments
 (0)