Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sentry-ruby/lib/sentry/cron/monitor_check_ins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def perform(*args, **opts)
:in_progress,
monitor_config: monitor_config)

start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
start = Metrics::Timing.duration_start

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

Sentry.capture_check_in(slug,
:ok,
Expand All @@ -29,7 +29,7 @@ def perform(*args, **opts)

ret
rescue Exception
duration = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
duration = Metrics::Timing.duration_end(start)

Sentry.capture_check_in(slug,
:error,
Expand Down
8 changes: 8 additions & 0 deletions sentry-ruby/lib/sentry/metrics/timing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def day
def week
Sentry.utc_now.to_i / (3600.0 * 24.0 * 7.0)
end

def duration_start
Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

def duration_end(start)
Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions sentry-ruby/spec/sentry/cron/monitor_check_ins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def perform(a, b = 42, c: 99)
expect(ok_event.monitor_slug).to eq('job')
expect(ok_event.status).to eq(:ok)
expect(ok_event.monitor_config).to be_nil
expect(ok_event.duration).to be > 0
end
end

Expand Down Expand Up @@ -162,6 +163,7 @@ def perform; work end
expect(ok_event.monitor_slug).to eq('job')
expect(ok_event.status).to eq(:ok)
expect(ok_event.monitor_config).to be_nil
expect(ok_event.duration).to be > 0
end
end

Expand Down
Loading