Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- 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))
- 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))

- 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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public interface BeforeCaptureCallback {
*/
private boolean attachRawTombstone = false;

private boolean enableStandaloneAppStartTracing = false;
private boolean enableStandaloneAppStartTracing = true;

private @Nullable SentryFrameMetricsCollector frameMetricsCollector;

Expand Down Expand Up @@ -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.
*
* <p>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.
*
* <p>The SDK reports app start through these paths:
*
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ public void clear() {
appStartEndTime = null;
cachedStartInfo = null;
appStartExtension.clear();
appStartExtension.setExtendAppStartListener(null);
}

public @Nullable ITransactionProfiler getAppStartProfiler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test assumes one ui.load transaction

Medium Severity

This test calls setAppStartTime() without disabling isEnableStandaloneAppStartTracing. With the new default, onActivityCreated starts both an app.start and a ui.load transaction, so the implicit single-call verify on startTransaction (and the ui.load op check) no longer holds. Nearby child-span tests were updated; this one was not.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bugbot

Reviewed by Cursor Bugbot for commit 6f0879b. Configure here.

it.tracesSampleRate = 1.0
it.isEnableStandaloneAppStartTracing = false
}
sut.register(fixture.scopes, fixture.options)

setAppStartTime()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -1828,7 +1828,7 @@ class ManifestMetadataReaderTest {

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

assertFalse(fixture.options.isEnableStandaloneAppStartTracing)
assertTrue(fixture.options.isEnableStandaloneAppStartTracing)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class EnvelopeTests : BaseUiTest() {

transaction.finish()
relay.assert {
assertAppStartTransaction()
findEnvelope {
assertEnvelopeTransaction(it.items.toList(), AndroidLogger()).transaction ==
"ProfilingSampleActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class SdkInitTests : BaseUiTest() {
transaction2.finish()

relay.assert {
assertAppStartTransaction()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App start assert races with re-init

Medium Severity

doubleInitWithSameOptionsDoesNotThrow now requires exactly one App Start envelope, but it re-inits Sentry immediately after launchActivity. App start is often finished on first frame, which can still be pending after RESUMED, and MockRelay never counts those envelopes toward idling. assertAppStartTransaction() then fails when the list is empty, or if a delayed headless start arrives as well.

Additional Locations (2)
Fix in Cursor Fix in Web

Triggered by project rule: AGENTS.md

Reviewed by Cursor Bugbot for commit a151e1b. Configure here.

findEnvelope {
assertEnvelopeTransaction(it.items.toList(), AndroidLogger()).transaction == "e2etests"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class MockRelay(
/** List of unasserted requests sent to the [envelopePath]. */
private val unassertedEnvelopes = mutableListOf<RelayAsserter.RelayResponse>()

/** Standalone app start transactions, kept out of [unassertedEnvelopes]. */
private val appStartEnvelopes = mutableListOf<RelayAsserter.RelayResponse>()

/** List of responses to return when a request is sent. */
private val responses = mutableListOf<(RecordedRequest) -> MockResponse?>()

Expand All @@ -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()
Expand Down Expand Up @@ -133,6 +147,6 @@ class MockRelay(
}
}
}
assertion(RelayAsserter(unassertedEnvelopes))
assertion(RelayAsserter(unassertedEnvelopes, appStartEnvelopes))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<RelayResponse>) {
class RelayAsserter(
private val unassertedEnvelopes: MutableList<RelayResponse>,
private val appStartEnvelopes: List<RelayResponse>,
) {
private val originalUnassertedEnvelopes: MutableList<RelayResponse> =
ArrayList(unassertedEnvelopes)

Expand Down Expand Up @@ -43,6 +49,19 @@ class RelayAsserter(private val unassertedEnvelopes: MutableList<RelayResponse>)
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()) {
Expand All @@ -59,12 +78,19 @@ class RelayAsserter(private val unassertedEnvelopes: MutableList<RelayResponse>)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,8 @@
<!-- how to disable sentry -->
<!-- <meta-data android:name="io.sentry.enabled" android:value="false" /> -->

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

<meta-data
android:name="io.sentry.session-replay.screenshot-strategy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public void onCreate() {
}

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

Expand Down
Loading