54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/railscope/subscribers/command_subscriber.rb', line 54
def record(task, args)
return yield unless Railscope.enabled?
return yield unless Railscope.ready?
setup_command_context(task)
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
exit_code = 0
exception_info = nil
caught_exception = nil
begin
result = yield
result
rescue SystemExit => e
exit_code = e.status
raise
rescue Exception => e
exit_code = 1
caught_exception = e
exception_info = {
class: e.class.name,
message: e.message,
backtrace: e.backtrace&.first(20)
}
raise
ensure
duration = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round(2)
create_entry!(
entry_type: "command",
payload: build_payload(task, args, duration, exit_code, exception_info),
tags: build_tags(task, exit_code),
family_hash: generate_family_hash("command", task.name),
should_display_on_index: true
)
create_exception_entry!(task, caught_exception) if caught_exception
Railscope::Context.clear!
end
end
|