docs(time): Steer new measurements at the io.sentry.time clock APIs - #6088
Draft
runningcode wants to merge 1 commit into
Draft
docs(time): Steer new measurements at the io.sentry.time clock APIs#6088runningcode wants to merge 1 commit into
runningcode wants to merge 1 commit into
Conversation
Document on each singleton clock's getInstance() that callers should read the ticker or wall clock off the options object instead, so they get the per-platform implementation rather than pinning themselves to one. Calling JavaMonotonicTicker.getInstance() on Android is the trap worth naming: it stops counting through a device suspend, so intervals spanning a deep sleep come out short. Add an AGENTS.md section so new measurement code reaches for io.sentry.time rather than DateUtils.getCurrentDateTime() or a SentryDateProvider, picks the abstraction by what the number is for, and treats adding a new abstraction as a deliberate step rather than a way around an awkward call site. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
📲 Install BuildsAndroid
|
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.
📜 Description
Documentation only — no behavior change.
1. On the singleton clocks.
JavaMonotonicTicker,SystemEpochClockandAndroidMonotonicTickereach expose agetInstance(). Each one now carries a Javadoc note on that method pointing callers atSentryOptions#getMonotonicTicker()/SentryOptions#getEpochClock()instead, so they resolve the per-platform implementation rather than pinning themselves to one, and says which callers legitimately still callgetInstance()directly (theSentryOptions/SentryAndroidOptionsaccessors that supply the default, and tests that mean a specific implementation).2. In
AGENTS.md. A new "Measuring Time" section under Development Guidelines tells agents that new code reading a clock usesio.sentry.time, and notDateUtils.getCurrentDateTime(),System.currentTimeMillis(),System.nanoTime(),SystemClockor anySentryDateProviderimplementation. It maps the intent of the measurement onto the type that enforces it (EpochClock/Timestamp,Stopwatch,Deadline,AnchoredClock,MonotonicTicker), repeats the "get it from the options object" rule, and asks that adding a new abstraction be a deliberate step — re-read the existing types first, then name the invariant the new one exists to enforce and propose it — rather than a way around an awkward call site or an excuse to inline raw tick arithmetic.💡 Motivation and Context
The
io.sentry.timepackage landed over #6028, #6045 and #6030. Nothing so far records how it is meant to be used, and the two ways to get it wrong are both easy and quiet:JavaMonotonicTicker.getInstance()compiles and works on Android, but it isSystem.nanoTime(), which stops counting while the device is suspended. Any interval measured across a deep sleep silently comes out short.SentryAndroidOptionsoverrides the accessor with aCLOCK_BOOTTIME-backed ticker precisely to avoid that, and reading the accessor is the only thing that picks it up.io.sentry.timeclock reads are still all over the repository, so the nearest example an agent finds is usually the one it should not copy.💚 How did you test it?
No tests — comments and a Markdown file. Verified
./gradlew spotlessApply apiDumpis a no-op beyond the edits (no.apichanges), and that:sentry:javadocand:sentry-android-core:javaDocReleaseGenerationboth build clean, which confirms the new{@link}targets resolve.📝 Checklist
sendDefaultPIIis enabled.@ApiStatus.Internal🔮 Next steps
The
AGENTS.mdsection is deliberately about new code only. Migrating the existingSentryDateProviderand rawSystem.nanoTime()call sites is the remaining work in the clock series and stays out of this PR.#skip-changelog