Skip to content

Commit 19a5688

Browse files
runningcodeclaude
andauthored
feat(android): Add trace markers to SentryAndroid.init (#5901)
* feat(android): Add trace markers to SentryAndroid.init (JAVA-685) 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> * changelog * feat(android): Keep only the SentryAndroid.init trace section (JAVA-685) 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> * Remove changelog entry in favor of #skip-changelog * fix(android): Balance init trace section on lock failure (JAVA-685) 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> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8a8d947 commit 19a5688

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroid.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.Context;
66
import android.os.Process;
77
import android.os.SystemClock;
8+
import android.os.Trace;
89
import io.sentry.ILogger;
910
import io.sentry.IScopes;
1011
import io.sentry.ISentryLifecycleToken;
@@ -95,6 +96,9 @@ public static void init(
9596
@NotNull final Context context,
9697
@NotNull ILogger logger,
9798
@NotNull Sentry.OptionsConfiguration<SentryAndroidOptions> configuration) {
99+
// Started before acquiring the lock so it stays balanced with the endSection() in the finally
100+
// even if acquire() throws.
101+
Trace.beginSection("SentryAndroid.init");
98102
try (final @NotNull ISentryLifecycleToken ignored = staticLock.acquire()) {
99103
Sentry.init(
100104
new SentryAndroidOptionsContainer(),
@@ -219,6 +223,8 @@ public static void init(
219223
logger.log(SentryLevel.FATAL, "Fatal error during SentryAndroid.init(...)", e);
220224

221225
throw new RuntimeException("Failed to initialize Sentry's SDK", e);
226+
} finally {
227+
Trace.endSection();
222228
}
223229
}
224230

0 commit comments

Comments
 (0)