diff --git a/CHANGELOG.md b/CHANGELOG.md index 9132069930..74801634d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,7 @@ - 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)) - App starts are measured from process start on Android 7.0+ (API 24), and slow and frozen frames are measured per span - `ActivityFramesTracker` is removed, and the `ActivityLifecycleIntegration` constructor no longer takes it +- 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 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)) - 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)) - 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)) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java b/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java index 5b2e94eb83..5659791fa5 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/SentryAndroidOptions.java @@ -303,7 +303,7 @@ public interface BeforeCaptureCallback { */ private boolean attachRawTombstone = false; - private boolean enableStandaloneAppStartTracing = false; + private boolean enableStandaloneAppStartTracing = true; private @Nullable SentryFrameMetricsCollector frameMetricsCollector; @@ -874,16 +874,17 @@ public void setReportHistoricalMemoryLimiterExits( * Returns true if standalone app start tracing is enabled. See {@link * #setEnableStandaloneAppStartTracing(boolean)} for more details. */ - @ApiStatus.Experimental public boolean isEnableStandaloneAppStartTracing() { return enableStandaloneAppStartTracing; } /** - * Enables or disables standalone app start tracing. + * Enables or disables standalone app start tracing. Enabled by default. * *

When enabled, app start is sent as its own transaction instead of an {@code app.start.*} - * child span on the first Activity transaction. + * child span on the first Activity transaction. To attach app start to the first Activity + * transaction instead, set this to false, or set the {@code + * io.sentry.standalone-app-start-tracing.enable} manifest metadata to false. * *

The SDK reports app start through these paths: * @@ -912,7 +913,6 @@ public boolean isEnableStandaloneAppStartTracing() { * * @param enableStandaloneAppStartTracing true if enabled or false otherwise */ - @ApiStatus.Experimental public void setEnableStandaloneAppStartTracing(final boolean enableStandaloneAppStartTracing) { this.enableStandaloneAppStartTracing = enableStandaloneAppStartTracing; } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java b/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java index 50cb31d9fb..addecff58a 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/performance/AppStartMetrics.java @@ -422,6 +422,7 @@ public void clear() { appStartEndTime = null; cachedStartInfo = null; appStartExtension.clear(); + appStartExtension.setExtendAppStartListener(null); } public @Nullable ITransactionProfiler getAppStartProfiler() { diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt index 1e0d43f00d..e39877aa5c 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ActivityLifecycleIntegrationTest.kt @@ -555,7 +555,10 @@ class ActivityLifecycleIntegrationTest { @Test fun `extendAppStart is a no-op when standalone tracing is disabled`() { - val sut = fixture.getSut { it.tracesSampleRate = 1.0 } + val sut = fixture.getSut { + it.tracesSampleRate = 1.0 + it.isEnableStandaloneAppStartTracing = false + } sut.register(fixture.scopes, fixture.options) setAppStartTime() @@ -627,7 +630,10 @@ class ActivityLifecycleIntegrationTest { @Test fun `HeadlessAppStartListener is not registered when standalone flag is off`() { - val sut = fixture.getSut { it.tracesSampleRate = 1.0 } + val sut = fixture.getSut { + it.tracesSampleRate = 1.0 + it.isEnableStandaloneAppStartTracing = false + } sut.register(fixture.scopes, fixture.options) prepareHeadlessAppStart() @@ -1004,6 +1010,7 @@ class ActivityLifecycleIntegrationTest { fun `When Activity is destroyed, sets appStartSpan status to cancelled and finish it`() { val sut = fixture.getSut() fixture.options.tracesSampleRate = 1.0 + fixture.options.isEnableStandaloneAppStartTracing = false sut.register(fixture.scopes, fixture.options) setAppStartTime() @@ -1220,6 +1227,7 @@ class ActivityLifecycleIntegrationTest { fun `When firstActivityCreated is false, start transaction with given appStartTime`() { val sut = fixture.getSut() fixture.options.tracesSampleRate = 1.0 + fixture.options.isEnableStandaloneAppStartTracing = false sut.register(fixture.scopes, fixture.options) sut.setFirstActivityCreated(false) @@ -1244,7 +1252,10 @@ class ActivityLifecycleIntegrationTest { @Test fun `When firstActivityCreated is false and app start sampling decision is set, start transaction with isAppStart true`() { AppStartMetrics.getInstance().appStartSamplingDecision = mock() - val sut = fixture.getSut { it.tracesSampleRate = 1.0 } + val sut = fixture.getSut { + it.tracesSampleRate = 1.0 + it.isEnableStandaloneAppStartTracing = false + } sut.register(fixture.scopes, fixture.options) sut.setFirstActivityCreated(false) @@ -1267,7 +1278,10 @@ class ActivityLifecycleIntegrationTest { @Test fun `When firstActivityCreated is false and app start sampling decision is not set, start transaction with isAppStart false`() { - val sut = fixture.getSut { it.tracesSampleRate = 1.0 } + val sut = fixture.getSut { + it.tracesSampleRate = 1.0 + it.isEnableStandaloneAppStartTracing = false + } sut.register(fixture.scopes, fixture.options) sut.setFirstActivityCreated(false) @@ -1641,7 +1655,10 @@ class ActivityLifecycleIntegrationTest { @Test fun `standalone flag off launcher activity emits single ui load with nested app start cold child`() { - val sut = fixture.getSut { it.tracesSampleRate = 1.0 } + val sut = fixture.getSut { + it.tracesSampleRate = 1.0 + it.isEnableStandaloneAppStartTracing = false + } sut.register(fixture.scopes, fixture.options) setAppStartTime() @@ -2402,6 +2419,7 @@ class ActivityLifecycleIntegrationTest { fun `Creates activity lifecycle spans on API lower than 29`() { val sut = fixture.getSut(apiVersion = Build.VERSION_CODES.P) fixture.options.tracesSampleRate = 1.0 + fixture.options.isEnableStandaloneAppStartTracing = false val appStartDate = SentryNanotimeDate(1, 0) val startDate = SentryNanotimeDate(2, 0) val appStartMetrics = AppStartMetrics.getInstance() diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt index f9698cfdf2..f5aa9596f3 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ManifestMetadataReaderTest.kt @@ -1803,6 +1803,7 @@ class ManifestMetadataReaderTest { @Test fun `applyMetadata reads standalone app start tracing flag to options`() { + fixture.options.isEnableStandaloneAppStartTracing = false val bundle = bundleOf(ManifestMetadataReader.ENABLE_STANDALONE_APP_START_TRACING to true) val context = fixture.getContext(metaData = bundle) @@ -1813,7 +1814,6 @@ class ManifestMetadataReaderTest { @Test fun `applyMetadata reads standalone app start tracing false to options`() { - fixture.options.isEnableStandaloneAppStartTracing = true val bundle = bundleOf(ManifestMetadataReader.ENABLE_STANDALONE_APP_START_TRACING to false) val context = fixture.getContext(metaData = bundle) @@ -1828,7 +1828,7 @@ class ManifestMetadataReaderTest { ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider) - assertFalse(fixture.options.isEnableStandaloneAppStartTracing) + assertTrue(fixture.options.isEnableStandaloneAppStartTracing) } @Test diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidOptionsTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidOptionsTest.kt index 0ee138be14..836f8a78c9 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidOptionsTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidOptionsTest.kt @@ -173,9 +173,9 @@ class SentryAndroidOptionsTest { } @Test - fun `standalone app start tracing is disabled by default`() { + fun `standalone app start tracing is enabled by default`() { val sentryOptions = SentryAndroidOptions() - assertFalse(sentryOptions.isEnableStandaloneAppStartTracing) + assertTrue(sentryOptions.isEnableStandaloneAppStartTracing) } fun `when options is initialized, enableScopeSync is enabled by default`() { diff --git a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/AutomaticSpansTest.kt b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/AutomaticSpansTest.kt index 635ebf5a6c..7a84ead8eb 100644 --- a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/AutomaticSpansTest.kt +++ b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/AutomaticSpansTest.kt @@ -41,6 +41,7 @@ class AutomaticSpansTest : BaseUiTest() { activity.moveToState(Lifecycle.State.DESTROYED) relay.assert { + assertAppStartTransaction() assertFirstEnvelope { val transactionItem: SentryTransaction = it.assertTransaction() assertTrue("TTID span missing") { @@ -89,6 +90,7 @@ class AutomaticSpansTest : BaseUiTest() { "Expected total frames ($totalFrames) to be higher than the sum of slow ($slowFrames) and frozen ($frozenFrames) frames.", ) } + assertAppStartTransaction() assertNoOtherEnvelopes() } } diff --git a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/EnvelopeTests.kt b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/EnvelopeTests.kt index f036bbbbe0..c2b6c62dd3 100644 --- a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/EnvelopeTests.kt +++ b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/EnvelopeTests.kt @@ -61,6 +61,7 @@ class EnvelopeTests : BaseUiTest() { transaction.finish() relay.assert { + assertAppStartTransaction() findEnvelope { assertEnvelopeTransaction(it.items.toList(), AndroidLogger()).transaction == "ProfilingSampleActivity" diff --git a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/SdkInitTests.kt b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/SdkInitTests.kt index 6f71f15aed..85fd02029b 100644 --- a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/SdkInitTests.kt +++ b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/SdkInitTests.kt @@ -74,6 +74,7 @@ class SdkInitTests : BaseUiTest() { transaction2.finish() relay.assert { + assertAppStartTransaction() findEnvelope { assertEnvelopeTransaction(it.items.toList(), AndroidLogger()).transaction == "e2etests" } diff --git a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/mockservers/MockRelay.kt b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/mockservers/MockRelay.kt index dbe67740f4..3014167e93 100644 --- a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/mockservers/MockRelay.kt +++ b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/mockservers/MockRelay.kt @@ -24,6 +24,9 @@ class MockRelay( /** List of unasserted requests sent to the [envelopePath]. */ private val unassertedEnvelopes = mutableListOf() + /** Standalone app start transactions, kept out of [unassertedEnvelopes]. */ + private val appStartEnvelopes = mutableListOf() + /** List of responses to return when a request is sent. */ private val responses = mutableListOf<(RecordedRequest) -> MockResponse?>() @@ -34,6 +37,17 @@ class MockRelay( relay.dispatcher = object : Dispatcher() { override fun dispatch(request: RecordedRequest): MockResponse { + // Whether a headless app start is sent depends on the process importance, which tests + // can't control. So app start transactions aren't counted as requests and don't use up + // custom responses. + if (request.path == envelopePath) { + val appStart = RelayAsserter.RelayResponse(request, MockResponse()) + if (appStart.isAppStartTransaction()) { + appStartEnvelopes.add(appStart) + return appStart.response + } + } + // We check if there is any custom response previously set to return to this request, // otherwise we return a successful MockResponse. val response = responses.removeFirstOrNull()?.let { it(request) } ?: MockResponse() @@ -133,6 +147,6 @@ class MockRelay( } } } - assertion(RelayAsserter(unassertedEnvelopes)) + assertion(RelayAsserter(unassertedEnvelopes, appStartEnvelopes)) } } diff --git a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/mockservers/RelayAsserter.kt b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/mockservers/RelayAsserter.kt index 4d0ad2ab55..8b05102136 100644 --- a/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/mockservers/RelayAsserter.kt +++ b/sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/mockservers/RelayAsserter.kt @@ -3,16 +3,22 @@ package io.sentry.uitest.android.mockservers import io.sentry.EnvelopeReader import io.sentry.Sentry import io.sentry.SentryEnvelope +import io.sentry.SentryItemType +import io.sentry.assertEnvelopeTransaction import io.sentry.uitest.android.describeForTest import java.io.IOException import java.util.zip.GZIPInputStream +import kotlin.test.assertEquals import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.RecordedRequest import okio.GzipSource import okio.buffer /** Class used to assert requests sent to [MockRelay]. */ -class RelayAsserter(private val unassertedEnvelopes: MutableList) { +class RelayAsserter( + private val unassertedEnvelopes: MutableList, + private val appStartEnvelopes: List, +) { private val originalUnassertedEnvelopes: MutableList = ArrayList(unassertedEnvelopes) @@ -43,6 +49,19 @@ class RelayAsserter(private val unassertedEnvelopes: MutableList) return unassertedEnvelopes.removeAt(relayResponseIndex) } + /** + * Asserts exactly one standalone app start transaction was sent. Only for tests that launch an + * Activity: each test runs in a new process, so its first Activity is an app start. + */ + fun assertAppStartTransaction() { + val appStart = + appStartEnvelopes.singleOrNull() + ?: throw AssertionError( + "Expected one app start transaction, but got ${appStartEnvelopes.size}", + ) + appStart.assert { assertEquals("app.start", it.assertTransaction().contexts.trace?.operation) } + } + /** Asserts no other envelopes were sent. */ fun assertNoOtherEnvelopes() { if (unassertedEnvelopes.isNotEmpty()) { @@ -59,12 +78,19 @@ class RelayAsserter(private val unassertedEnvelopes: MutableList) val envelope: SentryEnvelope? by lazy { try { EnvelopeReader(Sentry.getCurrentScopes().options.serializer) - .read(GZIPInputStream(request.body.inputStream())) + // A copy, so that MockRelay can check for an app start before keeping the request + .read(GZIPInputStream(request.body.clone().inputStream())) } catch (e: IOException) { null } } + fun isAppStartTransaction(): Boolean { + val items = envelope?.items?.toList() ?: return false + return items.any { it.header.type == SentryItemType.Transaction } && + assertEnvelopeTransaction(items).transaction == "App Start" + } + /** Run [assertion] on this request parsed as an envelope. */ fun assert(assertion: (asserter: EnvelopeAsserter) -> Unit) { // Parse the request to rebuild the original envelope. If it fails we throw an assertion diff --git a/sentry-samples/sentry-samples-android/src/main/AndroidManifest.xml b/sentry-samples/sentry-samples-android/src/main/AndroidManifest.xml index ce4e62d7d1..fd97e54ac5 100644 --- a/sentry-samples/sentry-samples-android/src/main/AndroidManifest.xml +++ b/sentry-samples/sentry-samples-android/src/main/AndroidManifest.xml @@ -326,9 +326,8 @@ - + +