Skip to content

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

Open
runningcode wants to merge 2 commits into
mainfrom
no/java-576-checkin-stopwatch
Open

ref(checkin): Measure check-in durations with Stopwatch (JAVA-576)#6032
runningcode wants to merge 2 commits into
mainfrom
no/java-576-checkin-stopwatch

Conversation

@runningcode

@runningcode runningcode commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

📜 Description

Switch CheckIns to use Stopwatch to measure durations. This makes the code easier to reason about and makes the code more testable. This has no logical changes since this is only used in Java and the monotonic clock uses the same System.nanoTime() under the hood.

💡 Motivation and Context

This is a pure refactor to make the code easier to reason about and easier to test.

  • resolves: JAVA-576

💚 How did you test it?

Existing tests pass and added new ones.

📝 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.

🤖 Generated with Claude Code

@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.56.0 (1) release

⚙️ sentry-android Build Distribution Settings

@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from de557be to edd22f0 Compare September 2, 2026 08:23
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch from eb4c4ad to 0a21879 Compare September 2, 2026 08:23
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from edd22f0 to fef63c7 Compare September 2, 2026 13:35
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch from 0a21879 to 074890f Compare September 2, 2026 13:35
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from fef63c7 to 9829cc8 Compare September 2, 2026 13:37
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch 2 times, most recently from 781c864 to 8bb8665 Compare September 3, 2026 15:11
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from 9829cc8 to c11fec4 Compare September 3, 2026 15:11
@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
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch from fc85c12 to be5eaeb Compare September 4, 2026 08:33
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from 0d1d4c9 to 6861150 Compare September 4, 2026 08:57
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch from be5eaeb to 2168b35 Compare September 4, 2026 15:11
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from 6861150 to b35959c Compare September 4, 2026 15:11
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch 2 times, most recently from d40fd82 to da479f2 Compare September 8, 2026 13:26
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from b35959c to 1eb13ab Compare September 8, 2026 13:27
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch from da479f2 to 7de7107 Compare September 8, 2026 15:10
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from 1eb13ab to 5b8105e Compare September 8, 2026 15:10
@runningcode
runningcode force-pushed the no/java-574-ratelimiter-deadline branch 2 times, most recently from 62c2029 to 258eedb Compare September 9, 2026 14:56
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from 5b8105e to 67379d3 Compare September 9, 2026 15:44
@runningcode
runningcode changed the base branch from no/java-574-ratelimiter-deadline to main September 9, 2026 15:44
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from 67379d3 to f540ce2 Compare September 9, 2026 16:37
runningcode and others added 2 commits September 10, 2026 09:14
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. They now share one
Stopwatch, which takes its clock from the options.

Inert on every path that ships. The options hand the check-in path a
JavaMonotonicTicker, whose tickNanos() is System.nanoTime(), so the serialized
duration is unchanged to the bit. A new test brackets a tick between two
nanoTime readings, pinning the source rather than merely the resolution.

SentryAndroidOptions does override the ticker with a boottime one, but nothing
reaches it from here: check-ins have no Android integration -- no WorkManager,
JobScheduler or AlarmManager wrapper, no manifest option, no Android docs.
Measuring a check-in across device sleep is a change for the next major.

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

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…576)

The duration was measured off System.nanoTime() directly, so a test could
only assert it was some nonzero float. Now that the clock arrives through
SentryOptions.getMonotonicTicker(), a test can hand the check-in path a
ticker it controls and assert an exact value.

Two paths are worth pinning: the callable returning normally, where only the
terminal check-in carries a duration and the IN_PROGRESS one does not, and
the callable throwing, where the finally block still has to report the time
that passed. Both fail against the pre-refactor code.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@runningcode
runningcode force-pushed the no/java-576-checkin-stopwatch branch from 0c4b606 to bab2fcd Compare September 10, 2026 07:17
@runningcode
runningcode marked this pull request as ready for review September 10, 2026 07:20
@runningcode runningcode added the sanity-check PR needs a lightweight review for obvious issues label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant