Skip to content

feat(anr): add anrStackTraceProvider option to SentryAndroidOptions#5490

Draft
sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/anr-stack-trace-provider
Draft

feat(anr): add anrStackTraceProvider option to SentryAndroidOptions#5490
sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/anr-stack-trace-provider

Conversation

@sentry-junior
Copy link
Copy Markdown

@sentry-junior sentry-junior Bot commented Jun 2, 2026

Summary

Adds @Nullable Supplier<StackTraceElement[]> anrStackTraceProvider to SentryAndroidOptions. When non-null, AnrProfilingIntegration calls this supplier to obtain the stack trace instead of mainThread.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 field anrStackTraceProvider (nullable Supplier<StackTraceElement[]>) with getter and setter; defaults to null.
  • AnrProfilingIntegrationcheckMainThread now resolves the stack trace via the provider when set, falling back to mainThread.getStackTrace().

Tests

  • AnrProfilingIntegrationTest — two new tests:
    • custom provider is invoked and its frames land in the collected profile
    • null provider falls back to the default JVM stack trace path
  • 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.

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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

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 #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 30828c9

@sentry
Copy link
Copy Markdown

sentry Bot commented Jun 2, 2026

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 350.43 ms 408.54 ms 58.11 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

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

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.

1 participant