Skip to content

ref(checkin): Measure check-in durations with Stopwatch (JAVA-576) - #6032

Draft
runningcode wants to merge 1 commit into
no/java-574-ratelimiter-deadlinefrom
no/java-576-checkin-stopwatch
Draft

ref(checkin): Measure check-in durations with Stopwatch (JAVA-576)#6032
runningcode wants to merge 1 commit into
no/java-574-ratelimiter-deadlinefrom
no/java-576-checkin-stopwatch

Conversation

@runningcode

@runningcode runningcode commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

PR Stack (Clock semantics hardening)


📜 Description

All four check-in paths kept a start tick and subtracted it in a finally:

// before
final long startTime = System.nanoTime();
...
checkIn.setDuration(DateUtils.nanosToSeconds(System.nanoTime() - startTime));

// after
final @NotNull Stopwatch stopwatch = Stopwatch.started(scopes.getOptions().getMonotonicClock());
...
checkIn.setDuration(DateUtils.nanosToSeconds(stopwatch.elapsedNanos()));

CheckInUtils plus SentryCheckInAdvice in sentry-spring, sentry-spring-jakarta and sentry-spring-7.

Stacked on #6030#6029#6028.

💡 Motivation and Context

A check-in duration is meant to say how long the job took, which is what a cron monitor's alerting thresholds are set against. Reading the clock from the options gives that meaning on both platforms:

  • JVM: unchanged, to the bit. MonotonicClock there is System.nanoTime(), the same reading the code took before. This is the same arithmetic behind a name.
  • Android: deep sleep now counts. MonotonicClock is SystemClock.elapsedRealtimeNanos(), so a job that spans a suspend reports the duration a user would measure rather than the time the CPU happened to be awake.

The Android half is a change to a serialized value, which the rest of this series holds for v9 — so it is called out under Behavioral Changes in the changelog rather than slipped in. It is the correct value for the field, the affected surface is cron check-ins on Android, and deferring it would mean shipping the wrong number for another major just to keep the diff inert.

An uninitialised SDK still reaches a clock: NoOpScopes.getOptions() returns empty options, whose clock is the JVM one.

  • resolves: JAVA-576

💚 How did you test it?

No new tests. The conversion is mechanical and the existing check-in tests already assert the emitted duration; a test that Stopwatch.started(...) measures elapsed time would be testing StopwatchTest a second time. One existing CheckInUtilsTest case needed scopes.options stubbed, now that the clock is read from there.

.api has no diff. sentry's check-in tests pass, and all four modules compile.

A pre-existing failure you should know about, since it is in the files this PR touches: SentryCheckInAdviceTest fails locally for me in all three Spring modules — 14 failures, expected:<1> but was:<0> on the captureCheckIn verifications. I confirmed it is not caused by this change by running the same tests on a clean origin/main worktree: the same failures, with none of this stack applied. It looks like a local environment problem rather than a repo one, but I could not rule that out from here, so CI on this PR is the real check.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

@linear-code

linear-code Bot commented Aug 31, 2026

Copy link
Copy Markdown

JAVA-576

@sentry

sentry Bot commented Aug 31, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.55.0 (1) release

⚙️ sentry-android Build Distribution Settings

All four check-in paths kept a `long startTime = System.nanoTime()` and
subtracted it in a finally block: CheckInUtils and the SentryCheckInAdvice
in sentry-spring, sentry-spring-jakarta and sentry-spring-7.

The clock now comes from the options, so a check-in measures on whatever
the SDK measures on: System.nanoTime() on the JVM, unchanged to the bit,
and SystemClock.elapsedRealtimeNanos() on Android. A cron job that spans a
suspend therefore reports the duration a user would measure rather than the
time the CPU happened to be awake, which is what a check-in duration is
meant to mean.

An uninitialised SDK still reaches a clock: NoOpScopes.getOptions() hands
back empty options, whose clock is the JVM one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch from 8bb8665 to fc85c12 Compare September 3, 2026 15:41
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from c11fec4 to 0d1d4c9 Compare September 3, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant