Skip to content

fix(core): Mark transactions that outlive their deadline as deadline_exceeded (JAVA-642) - #6599

Merged
runningcode merged 7 commits into
mainfrom
no/java-642-deadline-after-sleep
Nov 17, 2026
Merged

runningcode merged 7 commits into
mainfrom
no/java-642-deadline-after-sleep

Conversation

@runningcode

@runningcode runningcode commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

📜 Description

(Description is hand-written ;) )

Issue: The deadline timer stops counting during sleep/doze. So when the device resumes from sleep, the TTID (onFirstFrameDrawn) and TTFD (onFullFrameDrawn) can fire before the deadline timer leading to hour or hours long TTID/TTFD. Normally these long transactions/spans are supposed to be marked with DEADLINE_EXCEEDED but they are not because the timer fires afterwards.

Fix: Add a separate Deadline to SentryTracer with a ticker that counts deep sleep. When the transaction or span finishes it checks this deadline and marks it as DEADLINE_EXCEEDED so they can be properly filtered out on dashboards. (Note this isn't the default filter, needs to be added)

We intentionally don't change the length of any transactions in this PR to avoid breaking timings.

Side effect: AppStartExtension.getExtendedEndTime() ignores an extended app start span with status DEADLINE_EXCEEDED, so the extended app start vital is suppressed when that span finishes after the deadline.

Note: my clanker found these two other issues that I'm intentionally leaving out of this PR:

  • The standalone app start transaction (enableStandaloneAppStartTracing) has no deadline, so we can have the hours long issue there too.
  • SentryTracer can capture a transaction twice when two threads finish it at the same moment, for example the deadline timer and onActivityDestroyed. That race is already on main.

💡 Motivation and Context

💚 How did you test it?

Unit tests. Not tested on a device.

📝 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

runningcode and others added 2 commits November 12, 2026 14:57
…JAVA-642)

The deadline timer counts on System.nanoTime(), which stops while an
Android device is suspended. It ran hours late, and after a process
freeze it raced the main thread, so ui.load transactions ended hours
after the deadline, or measured TTID, TTFD and the app start to a late
frame and finished as ok.

SentryTracer now measures the deadline on the monotonic ticker, which
counts suspend, and ends the transaction and its open spans at the wall
time the deadline was reached. Once it has passed, every way of
finishing the transaction takes that outcome. ActivityLifecycleIntegration
applies it before handling a late first frame, full display or destroy,
and PerformanceAndroidEventProcessor adds no app start measurement when
the app start span was cut short.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 12, 2026

Copy link
Copy Markdown

JAVA-642

@sentry

sentry Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

runningcode and others added 3 commits November 12, 2026 15:24
Starting a span after the deadline finished and captured the whole
transaction on the thread that started the span, which may hold a lock.
Return the no-op span only: the overdue deadline timer ends the
transaction at the deadline right after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…line

Timings now stay exactly as before: the deadline timer ends spans at
now() again, spans started after the deadline are recorded, and the
ActivityLifecycleIntegration and PerformanceAndroidEventProcessor
changes are reverted.

Instead, once the monotonic-ticker deadline has passed, Span.finish
gives the transaction and any span that finishes after it the status
the deadline timer gives: the transaction's own status, or
DEADLINE_EXCEEDED. Late frames after a device sleep then no longer
report ok, so span.status:ok filters them out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@runningcode runningcode changed the title fix(core): End transactions at the deadline after the device sleeps (JAVA-642) fix(core): Mark transactions that outlive their deadline as deadline_exceeded (JAVA-642) Nov 12, 2026
@runningcode
runningcode marked this pull request as ready for review November 13, 2026 09:06
@runningcode
runningcode requested review from a team and adinauer as code owners November 13, 2026 09:06
@runningcode
runningcode requested review from 0xadam-brown and romtsn and removed request for a team November 13, 2026 09:06
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 17, 2026
@romtsn
romtsn changed the base branch from main to 9.x.x November 17, 2026 10:44
@romtsn
romtsn changed the base branch from 9.x.x to main November 17, 2026 10:44

@markushi markushi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just one ergonomics concern, but that can be addressed later.

sentry-junior Bot and others added 2 commits November 17, 2026 13:30
Resolve CHANGELOG.md conflict by keeping both Unreleased Fixes entries. Apply Spotless 8.11.0 formatting (from main) to ActivityLifecycleIntegrationTest.kt.

Co-Authored-By: Markus Hintersteiner <markus.hintersteiner@sentry.io>
getDeadlineStatus() was only correct after a hasDeadlinePassed() check.
Fold the check in, so getDeadlineExceededStatus() returns null until the
deadline passes, and keep the timer callback as it is on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@runningcode
runningcode enabled auto-merge (squash) November 17, 2026 13:57
@runningcode
runningcode merged commit 23b4b90 into main Nov 17, 2026
51 of 52 checks passed
@runningcode
runningcode deleted the no/java-642-deadline-after-sleep branch November 17, 2026 14:12
sentry-junior Bot added a commit that referenced this pull request Nov 17, 2026
Resolve CHANGELOG.md conflict by keeping both Unreleased Fixes entries (#6542 and #6599).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect app start transaction duration when app goes in sleep

2 participants