fix: use System.nanoTime() for cron check-in duration measurement#5611
Merged
adinauer merged 2 commits intoJun 24, 2026
Merged
Conversation
runningcode
approved these changes
Jun 24, 2026
runningcode
left a comment
Contributor
There was a problem hiding this comment.
Thank you for the contribution. This looks great!
6a8d264 to
0b1ba59
Compare
adinauer
approved these changes
Jun 24, 2026
adinauer
left a comment
Member
There was a problem hiding this comment.
LGTM, thank you for the help!
System.currentTimeMillis() is a wall-clock value and is subject to NTP adjustments and DST transitions. For long-running cron jobs this can produce incorrect or even negative durations in the check-in payload. Switch the start/end capture in CheckInUtils.withCheckIn() and the three SentryCheckInAdvice implementations (sentry-spring, sentry-spring-jakarta, sentry-spring-7) to System.nanoTime(), which is guaranteed monotonic. Use DateUtils.nanosToSeconds() (already present) to convert the delta. Fixes getsentry#5579
0b1ba59 to
200b1c8
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5579
Problem
Cron check-in durations were computed by subtracting two
System.currentTimeMillis()values. The wall clock is not monotonic — it is subject to NTP steps, leap-second smearing, and DST transitions. For long-running cron jobs this gives wide exposure to clock jumps, which can produce incorrect or negative duration values in the check-in payload.Fix
Switch the start/end capture to
System.nanoTime(), which is guaranteed monotonic and is the correct choice for measuring elapsed time.DateUtils.nanosToSeconds()(already present in the SDK) is used to convert the nanosecond delta to the seconds value expected bysetDuration().Changed files:
sentry/src/main/java/io/sentry/util/CheckInUtils.javasentry-spring/src/main/java/io/sentry/spring/checkin/SentryCheckInAdvice.javasentry-spring-jakarta/src/main/java/io/sentry/spring/jakarta/checkin/SentryCheckInAdvice.javasentry-spring-7/src/main/java/io/sentry/spring7/checkin/SentryCheckInAdvice.javaExisting duration tests (
assertNotNull(doneCheckIn.duration)) continue to pass unchanged; the delta of twonanoTime()calls is always non-negative and non-zero for any real workload