Skip to content

feat(android): Add trace markers to SentryAndroid.init - #5901

Merged
runningcode merged 5 commits into
mainfrom
claude/sentryandroid-init-trace-markers-90340a
Aug 6, 2026
Merged

feat(android): Add trace markers to SentryAndroid.init#5901
runningcode merged 5 commits into
mainfrom
claude/sentryandroid-init-trace-markers-90340a

Conversation

@runningcode

@runningcode runningcode commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

📜 Description

Adds a android.os.Trace section around SentryAndroid.init, so we can benchmark this in a Perfetto trace / Macrobenchmark.

Cost: negligible. When no trace is recording (i.e. essentially always, in production), Trace.beginSection/endSection is a cached in-process flag check — no JNI, no allocation, and the section name is a constant. It's one begin/end pair on the existing try/catch: no new try blocks and no API change.

💡 Motivation and Context

So we can add a Macrobenchmark that measures the SentryAndroid.init slice and tracks SDK startup cost across releases, letting us catch regressions. Resolves JAVA-685.

💚 How did you test it?

./gradlew :sentry-android-core:testReleaseUnitTest --tests "*SentryAndroidTest*" passes (Robolectric no-ops android.os.Trace, so init still succeeds). The SentryAndroid.init slice still needs to be confirmed in a Perfetto capture.

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

#skip-changelog

Wrap SentryAndroid.init and the user OptionsConfiguration callback in
android.os.Trace sections so SDK startup cost shows up as named slices
in a Perfetto trace or a CI TraceSectionMetric.

Sections use constant names and allocate nothing when no trace is
recording. Kept intentionally minimal as the SDK's first shipped Trace
instrumentation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Aug 6, 2026

Copy link
Copy Markdown

JAVA-685

@github-actions

github-actions Bot commented Aug 6, 2026

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 de19349

@sentry

sentry Bot commented Aug 6, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 301.00 ms 361.94 ms 60.94 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
455eb6e 341.51 ms 428.96 ms 87.45 ms
d15471f 343.13 ms 361.47 ms 18.34 ms
b193867 331.08 ms 397.06 ms 65.98 ms
5b1a06b 315.40 ms 353.33 ms 37.94 ms
62b579c 312.88 ms 361.57 ms 48.70 ms
85d7417 347.21 ms 394.35 ms 47.15 ms
6dff1c9 298.04 ms 327.43 ms 29.39 ms
5b1a06b 310.56 ms 362.79 ms 52.22 ms
ee747ae 386.94 ms 431.43 ms 44.49 ms
462dea2 322.40 ms 370.06 ms 47.66 ms

App size

Revision Plain With Sentry Diff
455eb6e 0 B 0 B 0 B
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
b193867 1.58 MiB 2.19 MiB 620.00 KiB
5b1a06b 0 B 0 B 0 B
62b579c 0 B 0 B 0 B
85d7417 1.58 MiB 2.10 MiB 533.44 KiB
6dff1c9 0 B 0 B 0 B
5b1a06b 0 B 0 B 0 B
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
462dea2 0 B 0 B 0 B

Previous results on branch: claude/sentryandroid-init-trace-markers-90340a

Startup times

Revision Plain With Sentry Diff
637262c 351.33 ms 428.96 ms 77.63 ms
180fcb9 320.44 ms 365.84 ms 45.40 ms

App size

Revision Plain With Sentry Diff
637262c 0 B 0 B 0 B
180fcb9 0 B 0 B 0 B

runningcode and others added 2 commits August 6, 2026 12:34
Drop the SentryAndroid.init.configure section to keep the SDK's first
shipped android.os.Trace instrumentation minimal and easy to review.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@runningcode
runningcode marked this pull request as ready for review August 6, 2026 10:48
@runningcode runningcode added the sanity-check PR needs a lightweight review for obvious issues label Aug 6, 2026

@0xadam-brown 0xadam-brown 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.

Macrobenchmarks ftw 💯

My vote would be to move the trace call before lock acquisition, like SentryBot suggests; otherwise lgtm 👍

Move Trace.beginSection above the try-with-resources so it always
pairs with the endSection() in the finally. If staticLock.acquire()
threw (e.g. OOM allocating the lock), the body was skipped but the
finally still ran, popping an unrelated systrace section.

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

Copy link
Copy Markdown
Contributor Author

Good idea! pushed

@runningcode
runningcode merged commit 19a5688 into main Aug 6, 2026
35 checks passed
@runningcode
runningcode deleted the claude/sentryandroid-init-trace-markers-90340a branch August 6, 2026 14:27
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.

2 participants