Skip to content

Replace ANR profiling boolean flag with sample-rate#5156

Merged
markushi merged 1 commit intomarkushi/feat/anr-profilingfrom
markushi/feat/anr-profiling-sampling
Mar 6, 2026
Merged

Replace ANR profiling boolean flag with sample-rate#5156
markushi merged 1 commit intomarkushi/feat/anr-profilingfrom
markushi/feat/anr-profiling-sampling

Conversation

@markushi
Copy link
Member

@markushi markushi commented Mar 5, 2026

📜 Description

Replaces the boolean flag with a sample-rate.

#skip-changelog

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

}

if (options.isEnableAnrProfiling() && hasOnlySystemFrames(event)) {
if (options.isAnrProfilingEnabled() && hasOnlySystemFrames(event)) {
Copy link

Choose a reason for hiding this comment

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

Bug: Unsampled ANR events are incorrectly fingerprinted as "system-frames-only-anr" because the check isAnrProfilingEnabled() doesn't confirm if the specific event was actually profiled.
Severity: MEDIUM

Suggested Fix

The setDefaultAnrFingerprint() method should only apply the "system-frames-only-anr" fingerprint if the ANR event was actually profiled. This can be achieved by having applyAnrProfile() set a flag on the event to indicate a profile was applied. The fingerprinting logic should then check this flag instead of relying on the general isAnrProfilingEnabled() setting.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location:
sentry-android-core/src/main/java/io/sentry/android/core/ApplicationExitInfoEventProcessor.java#L737

Potential issue: When ANR profiling is enabled with a sample rate less than 1.0, ANR
events that are not sampled are incorrectly fingerprinted. The logic in
`setDefaultAnrFingerprint` checks if profiling is enabled via `isAnrProfilingEnabled()`,
but does not check if the specific ANR event was actually profiled. If an unsampled ANR
event happens to only contain system frames, it will be assigned the
`"system-frames-only-anr"` fingerprint. This fingerprint is intended for cases where
profiling was performed but found no application frames, leading to incorrect issue
grouping in Sentry for unsampled ANRs.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member

Choose a reason for hiding this comment

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

sounds legit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, let me create a follow-up PR for this.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 337.96 ms 412.98 ms 75.02 ms
Size 1.58 MiB 2.29 MiB 728.81 KiB

Baseline results on branch: markushi/feat/anr-profiling

Startup times

Revision Plain With Sentry Diff
83a9ec4 333.84 ms 390.30 ms 56.47 ms
00299fd 359.87 ms 424.85 ms 64.98 ms
eb02e45 362.67 ms 431.71 ms 69.04 ms
edecf31 310.80 ms 367.02 ms 56.22 ms
8c4e7d6 309.15 ms 359.27 ms 50.12 ms
8d7c3bb 304.55 ms 377.88 ms 73.33 ms
4c0ffee 314.94 ms 377.79 ms 62.86 ms
ddbbe91 289.51 ms 359.74 ms 70.23 ms
fca8df8 326.79 ms 379.69 ms 52.90 ms
c10e603 367.92 ms 393.50 ms 25.58 ms

App size

Revision Plain With Sentry Diff
83a9ec4 1.58 MiB 2.29 MiB 723.99 KiB
00299fd 1.58 MiB 2.29 MiB 723.50 KiB
eb02e45 1.58 MiB 2.29 MiB 725.26 KiB
edecf31 1.58 MiB 2.29 MiB 726.95 KiB
8c4e7d6 1.58 MiB 2.29 MiB 727.03 KiB
8d7c3bb 1.58 MiB 2.29 MiB 727.01 KiB
4c0ffee 1.58 MiB 2.29 MiB 723.67 KiB
ddbbe91 1.58 MiB 2.29 MiB 724.15 KiB
fca8df8 1.58 MiB 2.29 MiB 723.68 KiB
c10e603 1.58 MiB 2.29 MiB 723.72 KiB

Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

LGTM

@markushi markushi merged commit 034445f into markushi/feat/anr-profiling Mar 6, 2026
70 of 71 checks passed
@markushi markushi deleted the markushi/feat/anr-profiling-sampling branch March 6, 2026 07:12
markushi added a commit that referenced this pull request Mar 6, 2026
…ntry (#4899)

* Profile main thread when ANR and report ANR profiles to sentry

* docs(changelog): Add ANR profiling integration entry

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix api dump file

* Address PR feedback

* refactor(anr): Implement lazy file rotation for ANR profiling

* Update Changelog

* Address PR feedback

* Improve folding logic, cleanup tests

* Add more tests and address feedback

* Update CHANGELOG.md

* Address PR feedcback

* Move logic to event processor

* Update changelog

* Ensure integration is tracked

* Address PR feedback

* Fix tests

* Match manifest property to convention, enable profiling in sample app

* Add more bound checks and null guards

* Remove outdated meta-data

* Properly handle foreground transitions

* Address PR comments

* Address PR feedback

* Address PR feedback

* Address PR feedback

* Re-use thread

* Update Changelop

* Address review

* Address PR feedback

* Replace ANR profiling boolean flag with sample-rate (#5156)

* feat(android): Add enableAnrFingerprinting option (#5168)

* feat(android): Add enableAnrFingerprinting option

Decouple ANR fingerprinting from ANR profiling into a standalone
opt-in option. This allows static fingerprinting of system-frame-only
ANRs regardless of whether profiling is enabled.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(android): Mark enableAnrFingerprinting as experimental

Also enable the option in the sample app.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat(android): Default enableAnrFingerprinting to true

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor(android): Remove experimental flag from enableAnrFingerprinting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix api dump

* Address PR feedback

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* Fix tests

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Roman Zavarnitsyn <rom4ek93@gmail.com>
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.

2 participants