7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/roqua/support/instrumentation.rb', line 7
def with_instrumentation(message, options = {})
started_at = Time.now.to_f
Roqua.logger.info("#{message}:started", options)
value = yield
finished_at = Time.now.to_f
duration = finished_at - started_at
Roqua.logger.info("#{message}:finished", {duration: duration}.merge(options))
Roqua.stats.submit("#{message}.finished", 1)
Roqua.stats.submit("#{message}.duration", duration)
value
rescue => e
Roqua.logger.error("#{message}:failed", {exception: e.class.name, message: e.message}.merge(options))
Roqua.stats.submit("#{message}.failed", 1)
raise
end
|