feat(android): Add trace markers to SentryAndroid.init - #5901
Merged
Conversation
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>
Contributor
|
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
| 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 |
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
marked this pull request as ready for review
August 6, 2026 10:48
runningcode
requested review from
0xadam-brown,
adinauer,
markushi and
romtsn
as code owners
August 6, 2026 10:48
0xadam-brown
approved these changes
Aug 6, 2026
0xadam-brown
left a comment
Member
There was a problem hiding this comment.
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>
Contributor
Author
|
Good idea! pushed |
8 tasks
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.
📜 Description
Adds a
android.os.Tracesection aroundSentryAndroid.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/endSectionis 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 newtryblocks and no API change.💡 Motivation and Context
So we can add a Macrobenchmark that measures the
SentryAndroid.initslice 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-opsandroid.os.Trace, so init still succeeds). TheSentryAndroid.initslice still needs to be confirmed in a Perfetto capture.📝 Checklist
sendDefaultPIIis enabled.#skip-changelog