feat(anr): add anrStackTraceProvider option to SentryAndroidOptions#5490
Draft
sentry-junior[bot] wants to merge 2 commits into
Draft
feat(anr): add anrStackTraceProvider option to SentryAndroidOptions#5490sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
Adds a nullable Supplier<StackTraceElement[]> anrStackTraceProvider field to SentryAndroidOptions. When non-null, AnrProfilingIntegration uses it to obtain the stack trace instead of calling mainThread.getStackTrace() directly. This lets hybrid SDKs (Flutter, React Native, etc.) inject a custom provider that returns combined or natively-enriched frames alongside JVM frames, fixing ANR profiling for architectures where Thread.getStackTrace() only sees the JVM side of the call stack. Default is null, preserving existing behaviour. Co-authored-by: Markus Hintersteiner <markus.hintersteiner@sentry.io>
Contributor
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- add anrStackTraceProvider option to SentryAndroidOptions ([#5490](https://github.com/getsentry/sentry-java/pull/5490))If none of the above apply, you can opt out of this check by adding |
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 62b579c | 318.48 ms | 367.71 ms | 49.24 ms |
| b6702b0 | 395.86 ms | 409.98 ms | 14.12 ms |
| f064536 | 327.04 ms | 405.35 ms | 78.31 ms |
| 6b019b7 | 403.90 ms | 546.09 ms | 142.19 ms |
| 2195398 | 344.65 ms | 403.96 ms | 59.30 ms |
| ce0a49e | 532.00 ms | 609.96 ms | 77.96 ms |
| 27d7cf8 | 306.76 ms | 366.66 ms | 59.90 ms |
| 22f4345 | 307.87 ms | 354.51 ms | 46.64 ms |
| ad8da22 | 314.52 ms | 352.47 ms | 37.95 ms |
| e59e22a | 374.68 ms | 442.14 ms | 67.46 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 62b579c | 0 B | 0 B | 0 B |
| b6702b0 | 1.58 MiB | 2.12 MiB | 551.79 KiB |
| f064536 | 1.58 MiB | 2.20 MiB | 633.90 KiB |
| 6b019b7 | 0 B | 0 B | 0 B |
| 2195398 | 0 B | 0 B | 0 B |
| ce0a49e | 1.58 MiB | 2.10 MiB | 532.94 KiB |
| 27d7cf8 | 1.58 MiB | 2.12 MiB | 549.42 KiB |
| 22f4345 | 1.58 MiB | 2.29 MiB | 719.83 KiB |
| ad8da22 | 1.58 MiB | 2.29 MiB | 719.83 KiB |
| e59e22a | 1.58 MiB | 2.20 MiB | 635.34 KiB |
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.
Summary
Adds
@Nullable Supplier<StackTraceElement[]> anrStackTraceProvidertoSentryAndroidOptions. When non-null,AnrProfilingIntegrationcalls this supplier to obtain the stack trace instead ofmainThread.getStackTrace(). When null (default), existing behaviour is preserved.Why
ANR profiling currently samples stack traces via
Thread.getStackTrace(), which only sees JVM frames. For hybrid SDKs like Flutter (Dart/native AOT) or React Native, the interesting frames live outside the JVM and are invisible to this call. This extension point lets hybrid SDKs inject a custom provider that returns combined or natively-enriched frames alongside JVM frames.Changes
SentryAndroidOptions— new fieldanrStackTraceProvider(nullableSupplier<StackTraceElement[]>) with getter and setter; defaults tonull.AnrProfilingIntegration—checkMainThreadnow resolves the stack trace via the provider when set, falling back tomainThread.getStackTrace().Tests
AnrProfilingIntegrationTest— two new tests:SentryAndroidOptionsTest— three new tests covering null default, set/get round-trip, and clearing back to null.Verified
Compilation and test logic reviewed against
AnrStackTrace.stack(field name),AnrProfile.stacks(list), and the existing test patterns in the file. No automated build run (Android Gradle environment unavailable in sandbox).View Session in Sentry
Action taken on behalf of Markus Hintersteiner.