Skip to content

fix(android): Prevent Relay from rejecting single-sample ANR profiles - #5872

Merged
0xadam-brown merged 3 commits into
mainfrom
fix/anr-single-stack-trace
Jul 30, 2026
Merged

fix(android): Prevent Relay from rejecting single-sample ANR profiles #5872
0xadam-brown merged 3 commits into
mainfrom
fix/anr-single-stack-trace

Conversation

@0xadam-brown

@0xadam-brown 0xadam-brown commented Jul 30, 2026

Copy link
Copy Markdown
Member

📜 Description

Relay currently rejects ANR profiles with a single sample, even though they're still useful to customers. This PR updates our StackTraceConverter to add a second, synthetic sample whenever an ANR profile would otherwise only contain one.

The synthetic sample duplicates the original, save for a minor offset to its timestamp. (Lets us avoid misleading the user about the ANRs cause or duration.)

💡 Motivation and Context

Customers occasionally see ANR events with no attached profile despite having sufficient quota and ANR profiling enabled. That's because Relay drops any profile chunk with fewer than two samples, and an ANR chunk can have exactly one sample if the main thread is caught on the very first poll after the 1-second suspicion threshold.

Relay's policy was developed with continuous profiles in mind, where a one-point series has no meaningful time axis. But for ANR profiles a single sample is highly actionable, as it shows exactly where the main thread was stuck when the ANR began.

Resolves: JAVA-550

Options considered

[A] Make it more likely that the SDK satisfies Relay's requirements -> In particular, narrow the polling interval used with ANRs. Would only reduce the risk of single-sample ANRs but not eliminate it + requires more resources from host app.

[B] Guarantee the SDK satisfies Relay's requirements -> The approach this PR takes.

[C] Relax Relay's requirements -> Too big of a lift to implement and would require substantial input by the Relay folks.

💚 How did you test it?

Unit tests + integration test + had my LLM check E2E against Relay and entire backend pipeline.

📝 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.

🔮 Next steps

@linear-code

linear-code Bot commented Jul 30, 2026

Copy link
Copy Markdown

JAVA-550

@0xadam-brown
0xadam-brown force-pushed the fix/anr-single-stack-trace branch from 9f6dad9 to c4436f7 Compare July 30, 2026 08:50
@sentry

sentry Bot commented Jul 30, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@0xadam-brown 0xadam-brown added the sanity-check PR needs a lightweight review for obvious issues label Jul 30, 2026
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 321.30 ms 358.69 ms 37.40 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
6b019b7 343.31 ms 417.23 ms 73.91 ms
d15471f 342.08 ms 415.44 ms 73.35 ms
8687935 332.52 ms 362.23 ms 29.71 ms
5b1a06b 352.27 ms 413.70 ms 61.43 ms
91bb874 314.47 ms 440.00 ms 125.53 ms
0ee65e9 321.06 ms 361.24 ms 40.18 ms
e63ad34 323.67 ms 390.33 ms 66.67 ms
33a08cc 267.08 ms 340.45 ms 73.37 ms
27d7cf8 397.90 ms 498.65 ms 100.75 ms
ee747ae 405.43 ms 485.70 ms 80.28 ms

App size

Revision Plain With Sentry Diff
6b019b7 0 B 0 B 0 B
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
8687935 1.58 MiB 2.19 MiB 619.17 KiB
5b1a06b 0 B 0 B 0 B
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
0ee65e9 0 B 0 B 0 B
e63ad34 0 B 0 B 0 B
33a08cc 1.58 MiB 2.12 MiB 555.28 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB

Previous results on branch: fix/anr-single-stack-trace

Startup times

Revision Plain With Sentry Diff
a25e5f3 314.71 ms 366.82 ms 52.11 ms
b8ab5da 314.16 ms 358.29 ms 44.13 ms
c8211a6 319.65 ms 367.65 ms 48.01 ms

App size

Revision Plain With Sentry Diff
a25e5f3 0 B 0 B 0 B
b8ab5da 0 B 0 B 0 B
c8211a6 0 B 0 B 0 B

… (JAVA-550)

Relay currently rejects ANR profiles with a single sample, even though they're still useful to customers. (Relay's policy was developed with continuous profiles in mind, before ANR profiles were a thing.) Commit updates our StackTraceConverter to add a second, synthetic sample whenever an ANR profile would otherwise only contain one.

The synthetic sample duplicates the original, save for a minor offset to its timestamp (to avoid misleading the user about the ANRs cause or duration).

# Conflicts:
#	CHANGELOG.md
@0xadam-brown
0xadam-brown force-pushed the fix/anr-single-stack-trace branch from c4436f7 to f7f9f2a Compare July 30, 2026 09:53
@0xadam-brown
0xadam-brown marked this pull request as ready for review July 30, 2026 10:10
@runningcode

Copy link
Copy Markdown
Contributor

This seems to me like a server side problem, can we fix this in Relay or would that break other SDKs?

@0xadam-brown

Copy link
Copy Markdown
Member Author

This seems to me like a server side problem, can we fix this in Relay or would that break other SDKs?

Good callout, and agreed that'd be ideal. As mentioned in the PR description, it'd be a big lift implementation-wise and it'd require a lot of coordination with the Relay folks. We could certainly do it at some point, but this gets us 90% of the way there at super low cost 👍

@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.

Awesome, LGTM!

@0xadam-brown
0xadam-brown enabled auto-merge (squash) July 30, 2026 14:55
@0xadam-brown
0xadam-brown merged commit 934244e into main Jul 30, 2026
71 checks passed
@0xadam-brown
0xadam-brown deleted the fix/anr-single-stack-trace branch July 30, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants