Skip to content

Commit 7178358

Browse files
authored
Merge pull request #6716 from getsentry/no/java-503-standalone-app-start-default
feat(android): Enable standalone app start tracing by default
2 parents 9582f69 + 23ad47f commit 7178358

13 files changed

Lines changed: 95 additions & 23 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
- Remove the Android `enablePerformanceV2` option and its `io.sentry.performance-v2.enable` manifest metadata. Performance V2 is always on ([#6458](https://github.com/getsentry/sentry-java/pull/6458))
109109
- App starts are measured from process start on Android 7.0+ (API 24), and slow and frozen frames are measured per span
110110
- `ActivityFramesTracker` is removed, and the `ActivityLifecycleIntegration` constructor no longer takes it
111+
- Enable standalone app start tracing on Android by default. App start is sent as its own `App Start` transaction instead of an `app.start.*` child span of the first `ui.load` transaction. More accurate app launch tracking, resulting in higher span quota consumption on Android. To keep the previous behavior, set `options.isEnableStandaloneAppStartTracing = false` or the `io.sentry.standalone-app-start-tracing.enable` manifest metadata to `false` ([#6716](https://github.com/getsentry/sentry-java/pull/6716))
111112
- Screenshots attached to errors and user feedback now mask all text and images by default. Turn it off with `options.screenshot.setMaskAllText(false)` and `setMaskAllImages(false)`, or the `io.sentry.screenshot.mask-all-text` and `io.sentry.screenshot.mask-all-images` manifest options. Masking needs `sentry-android-replay`, so apps that depend on `sentry-android-core` alone get no screenshot until they add it or turn masking off ([#6437](https://github.com/getsentry/sentry-java/pull/6437))
112113
- Non-recoverable errors such as `OutOfMemoryError` and `StackOverflowError` are no longer swallowed by the SDK. This means that callbacks into app code will now rethrow these exceptions instead of silently swallowing them since they are not recoverable ([#6665](https://github.com/getsentry/sentry-java/pull/6665), [#6666](https://github.com/getsentry/sentry-java/pull/6666), [#6667](https://github.com/getsentry/sentry-java/pull/6667), [#6668](https://github.com/getsentry/sentry-java/pull/6668), [#6669](https://github.com/getsentry/sentry-java/pull/6669), [#6670](https://github.com/getsentry/sentry-java/pull/6670), [#6678](https://github.com/getsentry/sentry-java/pull/6678))
113114

‎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/AutomaticSpansTest.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class AutomaticSpansTest : BaseUiTest() {
4141
activity.moveToState(Lifecycle.State.DESTROYED)
4242

4343
relay.assert {
44+
assertAppStartTransaction()
4445
assertFirstEnvelope {
4546
val transactionItem: SentryTransaction = it.assertTransaction()
4647
assertTrue("TTID span missing") {
@@ -89,6 +90,7 @@ class AutomaticSpansTest : BaseUiTest() {
8990
"Expected total frames ($totalFrames) to be higher than the sum of slow ($slowFrames) and frozen ($frozenFrames) frames.",
9091
)
9192
}
93+
assertAppStartTransaction()
9294
assertNoOtherEnvelopes()
9395
}
9496
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class EnvelopeTests : BaseUiTest() {
6161

6262
transaction.finish()
6363
relay.assert {
64+
assertAppStartTransaction()
6465
findEnvelope {
6566
assertEnvelopeTransaction(it.items.toList(), AndroidLogger()).transaction ==
6667
"ProfilingSampleActivity"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import kotlin.test.assertEquals
1818
import kotlin.test.assertTrue
1919
import leakcanary.LeakAssertions
2020
import leakcanary.LeakCanary
21+
import org.junit.Ignore
2122
import org.junit.runner.RunWith
2223
import shark.AndroidReferenceMatchers
2324
import shark.IgnoredReferenceMatcher
@@ -74,6 +75,7 @@ class SdkInitTests : BaseUiTest() {
7475
transaction2.finish()
7576

7677
relay.assert {
78+
assertAppStartTransaction()
7779
findEnvelope {
7880
assertEnvelopeTransaction(it.items.toList(), AndroidLogger()).transaction == "e2etests"
7981
}
@@ -109,6 +111,10 @@ class SdkInitTests : BaseUiTest() {
109111
}
110112
}
111113

114+
// The headless app start sent after the second init can take the transaction profiler from
115+
// afterRestart. Re-enable without the profile assertion once transaction-based profiling is
116+
// dropped.
117+
@Ignore("https://github.com/getsentry/sentry-java/issues/5094")
112118
@Test
113119
fun doubleInitDoesNotWait() {
114120
initSentry(true)

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class MockRelay(
2424
/** List of unasserted requests sent to the [envelopePath]. */
2525
private val unassertedEnvelopes = mutableListOf<RelayAsserter.RelayResponse>()
2626

27+
/** Standalone app start transactions, kept out of [unassertedEnvelopes]. */
28+
private val appStartEnvelopes = mutableListOf<RelayAsserter.RelayResponse>()
29+
2730
/** List of responses to return when a request is sent. */
2831
private val responses = mutableListOf<(RecordedRequest) -> MockResponse?>()
2932

@@ -34,6 +37,21 @@ class MockRelay(
3437
relay.dispatcher =
3538
object : Dispatcher() {
3639
override fun dispatch(request: RecordedRequest): MockResponse {
40+
// Whether a headless app start is sent depends on the process importance, which tests
41+
// can't control. So app start transactions aren't counted as requests and don't use up
42+
// custom responses.
43+
if (request.path == envelopePath) {
44+
val appStart = RelayAsserter.RelayResponse(request, MockResponse())
45+
if (appStart.isAppStartTransaction()) {
46+
// The app start is sent right after init, while the cached envelopes are being sent,
47+
// which can send it a second time from the disk cache
48+
if (receivedEnvelopes.add(appStart.envelope!!.header.eventId.toString())) {
49+
appStartEnvelopes.add(appStart)
50+
}
51+
return appStart.response
52+
}
53+
}
54+
3755
// We check if there is any custom response previously set to return to this request,
3856
// otherwise we return a successful MockResponse.
3957
val response = responses.removeFirstOrNull()?.let { it(request) } ?: MockResponse()
@@ -133,6 +151,6 @@ class MockRelay(
133151
}
134152
}
135153
}
136-
assertion(RelayAsserter(unassertedEnvelopes))
154+
assertion(RelayAsserter(unassertedEnvelopes, appStartEnvelopes))
137155
}
138156
}

0 commit comments

Comments
 (0)