Skip to content

feat(anr): [Non-Fatal ANR 3] Add ThreadSampleCollector - #6724

Open
markushi wants to merge 1 commit into
markushi/feat/non-fatal-anr-2-thread-hang-signalfrom
markushi/feat/non-fatal-anr-3-thread-sample-collector
Open

markushi wants to merge 1 commit into
markushi/feat/non-fatal-anr-2-thread-hang-signalfrom
markushi/feat/non-fatal-anr-3-thread-sample-collector

Conversation

@markushi

Copy link
Copy Markdown
Member

Adds ThreadSampleCollector: it samples the stack of the watched thread during a hang interval and writes the samples to the ANR profile file after 700 ms. Not wired yet.

Design: Non-Fatal ANR Architecture (JAVA-777)

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

🤖 Generated with Claude Code

#skip-changelog

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit a19a7c8.

Main concerns: public contract, data sent to Sentry, host performance.

Rules that block low also fired:

  • R4: a public API record changed: sentry-android-core/api/sentry-android-core.api

This label is a hint for reviewers, not an approval.

@github-actions

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against a19a7c8

@markushi
markushi added this pull request to stack #6730 November 20, 2026 17:55
@sentry

sentry Bot commented Nov 20, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@markushi
markushi marked this pull request as ready for review November 20, 2026 18:01
@markushi
markushi requested review from a team and adinauer as code owners November 20, 2026 18:01
@markushi
markushi requested review from 0xadam-brown and romtsn and removed request for a team November 20, 2026 18:01
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 20, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a19a7c8. Configure here.

try {
if (!onDisk) {
onDisk = true;
startDiskRecording(manager);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Failed flush skips buffered samples

Medium Severity

onDisk is set before startDiskRecording finishes, so an IOException from clear or a later add still marks the hang as flushed. Later ticks then append only the new sample. If clear failed, that appends onto the previous hang; if clear succeeded, the in-memory buffer never reaches the file. The fatal ANR path can then load mixed or truncated stacks.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a19a7c8. Configure here.


final long epochMs = NANOSECONDS.toMillis(epochClock.now().epochNanos());
final @NotNull AnrStackTrace sample =
new AnrStackTrace(epochMs, thread.getStackTrace(), thread.getState());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sample timestamps use wall clock

Low Severity

Each sample stamps itself with a fresh epochClock.now() reading. Those timestamps are later sorted and turned into profile sample times, so they are related instants. A wall-clock jump during the hang can reorder stacks or stretch the profile. AnchoredClock is the type for this: one epoch read, then monotonic ticks for the rest.

Fix in Cursor Fix in Web

Triggered by learned rule: AnchoredClock for related instants, not EpochClock math

Reviewed by Cursor Bugbot for commit a19a7c8. Configure here.

This branch has not been deployed

No deployments
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.

1 participant