Skip to content

Commit ad535cc

Browse files
authored
Add Metrics.duration_(start,end) (#2501)
1 parent e232255 commit ad535cc

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

sentry-ruby/lib/sentry/cron/monitor_check_ins.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ def perform(*args, **opts)
1414
:in_progress,
1515
monitor_config: monitor_config)
1616

17-
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
17+
start = Metrics::Timing.duration_start
1818

1919
begin
2020
# need to do this on ruby <= 2.6 sadly
2121
ret = method(:perform).super_method.arity == 0 ? super() : super
22-
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
22+
duration = Metrics::Timing.duration_end(start)
2323

2424
Sentry.capture_check_in(slug,
2525
:ok,
@@ -29,7 +29,7 @@ def perform(*args, **opts)
2929

3030
ret
3131
rescue Exception
32-
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
32+
duration = Metrics::Timing.duration_end(start)
3333

3434
Sentry.capture_check_in(slug,
3535
:error,

sentry-ruby/lib/sentry/metrics/timing.rb

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ def day
3737
def week
3838
Sentry.utc_now.to_i / (3600.0 * 24.0 * 7.0)
3939
end
40+
41+
def duration_start
42+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
43+
end
44+
45+
def duration_end(start)
46+
Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
47+
end
4048
end
4149
end
4250
end

sentry-ruby/spec/sentry/cron/monitor_check_ins_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def perform(a, b = 42, c: 99)
123123
expect(ok_event.monitor_slug).to eq('job')
124124
expect(ok_event.status).to eq(:ok)
125125
expect(ok_event.monitor_config).to be_nil
126+
expect(ok_event.duration).to be > 0
126127
end
127128
end
128129

@@ -162,6 +163,7 @@ def perform; work end
162163
expect(ok_event.monitor_slug).to eq('job')
163164
expect(ok_event.status).to eq(:ok)
164165
expect(ok_event.monitor_config).to be_nil
166+
expect(ok_event.duration).to be > 0
165167
end
166168
end
167169

0 commit comments

Comments
 (0)