Skip to content

Commit 43cb138

Browse files
runningcodeclaude
andcommitted
feat(android): Enable standalone app start tracing by default
App start is now sent as its own App Start transaction instead of an app.start.* child span of the first ui.load transaction. The option and its manifest key stay so apps can opt out, and the option is no longer experimental. AppStartMetrics.clear() now also drops the extend-app-start listener, which otherwise leaks from one ActivityLifecycleIntegrationTest into the next now that most tests register it. Fixes JAVA-503 Fixes #5376 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9582f69 commit 43cb138

8 files changed

Lines changed: 41 additions & 20 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public interface BeforeCaptureCallback {
303303
*/
304304
private boolean attachRawTombstone = false;
305305

306-
private boolean enableStandaloneAppStartTracing = false;
306+
private boolean enableStandaloneAppStartTracing = true;
307307

308308
private @Nullable SentryFrameMetricsCollector frameMetricsCollector;
309309

@@ -874,16 +874,17 @@ public void setReportHistoricalMemoryLimiterExits(
874874
* Returns true if standalone app start tracing is enabled. See {@link
875875
* #setEnableStandaloneAppStartTracing(boolean)} for more details.
876876
*/
877-
@ApiStatus.Experimental
878877
public boolean isEnableStandaloneAppStartTracing() {
879878
return enableStandaloneAppStartTracing;
880879
}
881880

882881
/**
883-
* Enables or disables standalone app start tracing.
882+
* Enables or disables standalone app start tracing. Enabled by default.
884883
*
885884
* <p>When enabled, app start is sent as its own transaction instead of an {@code app.start.*}
886-
* child span on the first Activity transaction.
885+
* child span on the first Activity transaction. To attach app start to the first Activity
886+
* transaction instead, set this to false, or set the {@code
887+
* io.sentry.standalone-app-start-tracing.enable} manifest metadata to false.
887888
*
888889
* <p>The SDK reports app start through these paths:
889890
*
@@ -912,7 +913,6 @@ public boolean isEnableStandaloneAppStartTracing() {
912913
*
913914
* @param enableStandaloneAppStartTracing true if enabled or false otherwise
914915
*/
915-
@ApiStatus.Experimental
916916
public void setEnableStandaloneAppStartTracing(final boolean enableStandaloneAppStartTracing) {
917917
this.enableStandaloneAppStartTracing = enableStandaloneAppStartTracing;
918918
}

‎sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ public void clear() {
422422
appStartEndTime = null;
423423
cachedStartInfo = null;
424424
appStartExtension.clear();
425+
appStartExtension.setExtendAppStartListener(null);
425426
}
426427

427428
public @Nullable ITransactionProfiler getAppStartProfiler() {

‎sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,10 @@ class ActivityLifecycleIntegrationTest {
555555

556556
@Test
557557
fun `extendAppStart is a no-op when standalone tracing is disabled`() {
558-
val sut = fixture.getSut { it.tracesSampleRate = 1.0 }
558+
val sut = fixture.getSut {
559+
it.tracesSampleRate = 1.0
560+
it.isEnableStandaloneAppStartTracing = false
561+
}
559562
sut.register(fixture.scopes, fixture.options)
560563

561564
setAppStartTime()
@@ -627,7 +630,10 @@ class ActivityLifecycleIntegrationTest {
627630

628631
@Test
629632
fun `HeadlessAppStartListener is not registered when standalone flag is off`() {
630-
val sut = fixture.getSut { it.tracesSampleRate = 1.0 }
633+
val sut = fixture.getSut {
634+
it.tracesSampleRate = 1.0
635+
it.isEnableStandaloneAppStartTracing = false
636+
}
631637
sut.register(fixture.scopes, fixture.options)
632638
prepareHeadlessAppStart()
633639

@@ -1004,6 +1010,7 @@ class ActivityLifecycleIntegrationTest {
10041010
fun `When Activity is destroyed, sets appStartSpan status to cancelled and finish it`() {
10051011
val sut = fixture.getSut()
10061012
fixture.options.tracesSampleRate = 1.0
1013+
fixture.options.isEnableStandaloneAppStartTracing = false
10071014
sut.register(fixture.scopes, fixture.options)
10081015

10091016
setAppStartTime()
@@ -1220,6 +1227,7 @@ class ActivityLifecycleIntegrationTest {
12201227
fun `When firstActivityCreated is false, start transaction with given appStartTime`() {
12211228
val sut = fixture.getSut()
12221229
fixture.options.tracesSampleRate = 1.0
1230+
fixture.options.isEnableStandaloneAppStartTracing = false
12231231
sut.register(fixture.scopes, fixture.options)
12241232
sut.setFirstActivityCreated(false)
12251233

@@ -1244,7 +1252,10 @@ class ActivityLifecycleIntegrationTest {
12441252
@Test
12451253
fun `When firstActivityCreated is false and app start sampling decision is set, start transaction with isAppStart true`() {
12461254
AppStartMetrics.getInstance().appStartSamplingDecision = mock()
1247-
val sut = fixture.getSut { it.tracesSampleRate = 1.0 }
1255+
val sut = fixture.getSut {
1256+
it.tracesSampleRate = 1.0
1257+
it.isEnableStandaloneAppStartTracing = false
1258+
}
12481259
sut.register(fixture.scopes, fixture.options)
12491260
sut.setFirstActivityCreated(false)
12501261

@@ -1267,7 +1278,10 @@ class ActivityLifecycleIntegrationTest {
12671278

12681279
@Test
12691280
fun `When firstActivityCreated is false and app start sampling decision is not set, start transaction with isAppStart false`() {
1270-
val sut = fixture.getSut { it.tracesSampleRate = 1.0 }
1281+
val sut = fixture.getSut {
1282+
it.tracesSampleRate = 1.0
1283+
it.isEnableStandaloneAppStartTracing = false
1284+
}
12711285
sut.register(fixture.scopes, fixture.options)
12721286
sut.setFirstActivityCreated(false)
12731287

@@ -1641,7 +1655,10 @@ class ActivityLifecycleIntegrationTest {
16411655

16421656
@Test
16431657
fun `standalone flag off launcher activity emits single ui load with nested app start cold child`() {
1644-
val sut = fixture.getSut { it.tracesSampleRate = 1.0 }
1658+
val sut = fixture.getSut {
1659+
it.tracesSampleRate = 1.0
1660+
it.isEnableStandaloneAppStartTracing = false
1661+
}
16451662
sut.register(fixture.scopes, fixture.options)
16461663
setAppStartTime()
16471664

@@ -2402,6 +2419,7 @@ class ActivityLifecycleIntegrationTest {
24022419
fun `Creates activity lifecycle spans on API lower than 29`() {
24032420
val sut = fixture.getSut(apiVersion = Build.VERSION_CODES.P)
24042421
fixture.options.tracesSampleRate = 1.0
2422+
fixture.options.isEnableStandaloneAppStartTracing = false
24052423
val appStartDate = SentryNanotimeDate(1, 0)
24062424
val startDate = SentryNanotimeDate(2, 0)
24072425
val appStartMetrics = AppStartMetrics.getInstance()

‎sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ class ManifestMetadataReaderTest {
18031803

18041804
@Test
18051805
fun `applyMetadata reads standalone app start tracing flag to options`() {
1806+
fixture.options.isEnableStandaloneAppStartTracing = false
18061807
val bundle = bundleOf(ManifestMetadataReader.ENABLE_STANDALONE_APP_START_TRACING to true)
18071808
val context = fixture.getContext(metaData = bundle)
18081809

@@ -1813,7 +1814,6 @@ class ManifestMetadataReaderTest {
18131814

18141815
@Test
18151816
fun `applyMetadata reads standalone app start tracing false to options`() {
1816-
fixture.options.isEnableStandaloneAppStartTracing = true
18171817
val bundle = bundleOf(ManifestMetadataReader.ENABLE_STANDALONE_APP_START_TRACING to false)
18181818
val context = fixture.getContext(metaData = bundle)
18191819

@@ -1828,7 +1828,7 @@ class ManifestMetadataReaderTest {
18281828

18291829
ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)
18301830

1831-
assertFalse(fixture.options.isEnableStandaloneAppStartTracing)
1831+
assertTrue(fixture.options.isEnableStandaloneAppStartTracing)
18321832
}
18331833

18341834
@Test

‎sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidOptionsTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ class SentryAndroidOptionsTest {
173173
}
174174

175175
@Test
176-
fun `standalone app start tracing is disabled by default`() {
176+
fun `standalone app start tracing is enabled by default`() {
177177
val sentryOptions = SentryAndroidOptions()
178-
assertFalse(sentryOptions.isEnableStandaloneAppStartTracing)
178+
assertTrue(sentryOptions.isEnableStandaloneAppStartTracing)
179179
}
180180

181181
fun `when options is initialized, enableScopeSync is enabled by default`() {

‎sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/BaseUiTest.kt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ abstract class BaseUiTest {
114114
// actually be sent.
115115
// To avoid any interference between tests we can just disable them by default.
116116
it.isEnableAutoSessionTracking = false
117+
// Whichever test launches the first activity of the process would otherwise also get a
118+
// standalone app start transaction, which these tests don't expect.
119+
it.isEnableStandaloneAppStartTracing = false
117120
optionsConfiguration?.invoke(it)
118121
}
119122
}

‎sentry-samples/sentry-samples-android/src/main/AndroidManifest.xml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,8 @@
326326
<!-- how to disable sentry -->
327327
<!-- <meta-data android:name="io.sentry.enabled" android:value="false" /> -->
328328

329-
<meta-data
330-
android:name="io.sentry.standalone-app-start-tracing.enable"
331-
android:value="true" />
329+
<!-- how to attach app start to the first Activity transaction instead of sending it standalone-->
330+
<!-- <meta-data android:name="io.sentry.standalone-app-start-tracing.enable" android:value="false" />-->
332331

333332
<meta-data
334333
android:name="io.sentry.session-replay.screenshot-strategy"

‎sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MyApplication.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public void onCreate() {
4040
}
4141

4242
// Example of extending the app start: launch-time work done here (after the SDK auto-inits) is
43-
// included in the app start measurement. Requires standalone app start tracing
44-
// (io.sentry.standalone-app-start-tracing.enable in the manifest). The artificial delays stand in
45-
// for real launch work, e.g. loading remote config or feature flags before the first screen.
43+
// included in the app start measurement. Requires standalone app start tracing, which is on by
44+
// default. The artificial delays stand in for real launch work, e.g. loading remote config or
45+
// feature flags before the first screen.
4646
private void extendAppStartExample() {
4747
Sentry.extendAppStart();
4848

0 commit comments

Comments
 (0)