18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/kirei/services/runner.rb', line 18
def self.call(class_name, log_tags: {}, &block)
start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
service = yield
service
ensure
stop = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
latency_in_ms = stop - T.must(start)
result = service_result(service)
metric_tags = Logging::Metric.inject_defaults({ "service.result" => result })
::StatsD.measure(class_name, latency_in_ms, tags: metric_tags)
logtags = {
"service.name" => class_name.to_s,
"service.latency_in_ms" => latency_in_ms,
"service.result" => result,
"service.source_location" => source_location(block),
}
logtags.merge!(log_tags)
Logging::Logger.call(level: log_level(result), label: "Service Finished", meta: logtags)
end
|