Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d996425
feat(extend-app-start): Eagerly create the extended App Start transacโ€ฆ
buenaflor Jun 24, 2026
51e4969
chore(extend-app-start): Drop the redundant foreground-check comment โ€ฆ
buenaflor Jun 25, 2026
4c1f0d7
test(extend-app-start): Replace the no-op finish test with isExtendedโ€ฆ
buenaflor Jun 25, 2026
48bb3a1
test(extend-app-start): Drop the no-value getAppStartExtension test aโ€ฆ
buenaflor Jun 25, 2026
9fa64fd
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 25, 2026
38f83e1
chore(extend-app-start): Trim and de-duplicate comments in the eager โ€ฆ
buenaflor Jun 25, 2026
55decba
chore(extend-app-start): Clarify the extensionActive comment
buenaflor Jun 25, 2026
f0a85b0
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 25, 2026
66cd87d
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 25, 2026
571416e
ref(extend-app-start): Rename extended app start span op to app.startโ€ฆ
buenaflor Jun 25, 2026
b4f34ce
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 26, 2026
1eb12d5
fix(extend-app-start): Fix headless app start end time and duplicate txn
buenaflor Jun 26, 2026
b5bf4ec
style(extend-app-start): Trim low-value comments in the headless fix
buenaflor Jun 26, 2026
bb88dad
style(extend-app-start): Drop redundant extend-listener comment
buenaflor Jun 26, 2026
85e23d8
style(extend-app-start): Trim redundant comments in onActivityCreated
buenaflor Jun 26, 2026
f2d1c34
style(extend-app-start): Remove explanatory comments in app start paths
buenaflor Jun 26, 2026
d2df48b
fix(extend-app-start): Consume stored app start trace on the extensioโ€ฆ
buenaflor Jun 26, 2026
142a9d2
fix(extend-app-start): Only the launch activity attaches the app starโ€ฆ
buenaflor Jun 26, 2026
dd7b3e0
Format code
getsentry-bot Jun 26, 2026
b7da10f
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 26, 2026
0de722b
style(extend-app-start): Trim verbose comments in app start paths
buenaflor Jun 26, 2026
c2cdb14
Merge remote-tracking branch 'origin/feat/app-start-extension-materiaโ€ฆ
buenaflor Jun 26, 2026
2a02616
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 29, 2026
df8cfe4
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 29, 2026
b442c1e
style(extend-app-start): Drop two line-narrating test comments
buenaflor Jun 29, 2026
642cfb0
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 29, 2026
e12f7b0
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 29, 2026
9ebdd09
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 29, 2026
824c12f
test(extend-app-start): Drop narrating comments from app start tests
buenaflor Jun 29, 2026
d87e908
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 29, 2026
c861ba9
refactor(extend-app-start): Name app start branching booleans by intent
buenaflor Jun 29, 2026
d8ffbbc
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโ€ฆ
buenaflor Jun 29, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public final class ActivityLifecycleIntegration
static final String APP_START_COLD = "app.start.cold";
static final String TTID_OP = "ui.load.initial_display";
static final String TTFD_OP = "ui.load.full_display";
static final String APP_START_EXTENDED_OP = "app.start.extended";
static final String APP_START_EXTENDED_DESC = "Extended App Start";
static final long TTFD_TIMEOUT_MILLIS = 25000;
// If a headless app start and the following activity's ui.load are more than this far apart, they
// are treated as unrelated and not connected into the same trace.
Expand Down Expand Up @@ -139,7 +141,9 @@ public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions
application.registerActivityLifecycleCallbacks(this);

if (performanceEnabled && this.options.isEnableStandaloneAppStartTracing()) {
AppStartMetrics.getInstance().setHeadlessAppStartListener(this::onHeadlessAppStart);
final @NotNull AppStartMetrics metrics = AppStartMetrics.getInstance();
metrics.setHeadlessAppStartListener(this::onHeadlessAppStart);
metrics.getAppStartExtension().setExtendAppStartListener(this::onExtendAppStartRequested);
addIntegrationToSdkVersion("StandaloneAppStart");
}

Expand All @@ -154,7 +158,9 @@ private boolean isPerformanceEnabled(final @NotNull SentryAndroidOptions options
@Override
public void close() throws IOException {
application.unregisterActivityLifecycleCallbacks(this);
AppStartMetrics.getInstance().setHeadlessAppStartListener(null);
final @NotNull AppStartMetrics metrics = AppStartMetrics.getInstance();
metrics.setHeadlessAppStartListener(null);
metrics.getAppStartExtension().setExtendAppStartListener(null);

if (options != null) {
options.getLogger().log(SentryLevel.DEBUG, "ActivityLifecycleIntegration removed.");
Expand Down Expand Up @@ -259,17 +265,23 @@ private void startTracing(final @NotNull Activity activity) {
transactionOptions.setAppStartTransaction(appStartSamplingDecision != null);
setSpanOrigin(transactionOptions);

// Guards the headless-start check below with !isExtensionActive so the eager extension's
// stored trace id isn't mistaken for a finished headless start.
final boolean isExtensionActive =
AppStartMetrics.getInstance().getAppStartExtension().isActive();
Comment thread
buenaflor marked this conversation as resolved.

final @Nullable SentryId storedAppStartTraceId =
AppStartMetrics.getInstance().getAppStartTraceId();
final boolean isFollowingHeadlessAppStart = (storedAppStartTraceId != null);
final boolean isFollowingHeadlessAppStart =
!isExtensionActive && (storedAppStartTraceId != null);

final boolean isAppStart =
!(firstActivityCreated || appStartTime == null || coldStart == null);
// Foreground starts create app.start first; ui.load then shares its trace.
final boolean createStandaloneAppStart =
isAppStart
&& options.isEnableStandaloneAppStartTracing()
&& !isFollowingHeadlessAppStart;
&& !isFollowingHeadlessAppStart
&& !isExtensionActive;

if (createStandaloneAppStart) {
final TransactionOptions appStartTransactionOptions = new TransactionOptions();
Expand Down Expand Up @@ -300,15 +312,23 @@ private void startTracing(final @NotNull Activity activity) {
continueSentryTrace = appStartTransaction.toSentryTrace().getValue();
final @Nullable BaggageHeader baggageHeader = appStartTransaction.toBaggageHeader(null);
continueBaggage = baggageHeader == null ? null : baggageHeader.getValue();
} else if (isFollowingHeadlessAppStart
&& isWithinAppStartContinuationWindow(ttidStartTime)) {
} else if (isExtensionActive
|| (isFollowingHeadlessAppStart && isWithinAppStartContinuationWindow(ttidStartTime))) {
continueSentryTrace = AppStartMetrics.getInstance().getAppStartSentryTraceHeader();
continueBaggage = AppStartMetrics.getInstance().getAppStartBaggageHeader();
} else {
continueSentryTrace = null;
continueBaggage = null;
}

if (isExtensionActive && isAppStart) {
// Only the launch activity sets the screen, so a later activity can't overwrite it. A
// screen also keeps the processor from classifying the eager app.start as headless.
AppStartMetrics.getInstance()
.getAppStartExtension()
.setData(APP_START_SCREEN_DATA, activityName);
Comment thread
cursor[bot] marked this conversation as resolved.
Comment thread
buenaflor marked this conversation as resolved.
}
Comment thread
buenaflor marked this conversation as resolved.

final @Nullable TransactionContext continuedContext =
continueSentryTrace == null
? null
Expand All @@ -328,8 +348,8 @@ && isWithinAppStartContinuationWindow(ttidStartTime)) {
transactionOptions);
}

if (isFollowingHeadlessAppStart) {
// Consume the stored headless app-start trace so it isn't reused by another activity.
if (isFollowingHeadlessAppStart || isExtensionActive) {
// Consume the stored app-start trace so a later activity doesn't reuse it.
AppStartMetrics.getInstance().setAppStartTraceId(null);
AppStartMetrics.getInstance().setAppStartSentryTraceHeader(null);
AppStartMetrics.getInstance().setAppStartBaggageHeader(null);
Expand Down Expand Up @@ -967,6 +987,9 @@ private void finishAppStartSpan(final @Nullable SentryDate endDate) {
if (appStartTransaction != null && !appStartTransaction.isFinished()) {
appStartTransaction.finish(SpanStatus.OK, appStartEndTime);
}
// Finish the eager extended transaction at the natural first-frame end. waitForChildren keeps
// it open until the extended span finishes; no-op if the app start was not extended.
AppStartMetrics.getInstance().getAppStartExtension().finishTransaction(appStartEndTime);
}
}

Expand Down Expand Up @@ -994,17 +1017,53 @@ private void onHeadlessAppStart() {
return;
}

// Persist the end time so a later ui.load can tell whether it is close enough to continue this
// trace; without it the continuation window is unbounded.
metrics.setAppStartEndTime(endTime);

final @NotNull AppStartExtension extension = metrics.getAppStartExtension();
if (extension.isActive()) {
extension.finishTransaction(endTime);
return;
}
if (!metrics.shouldSendStartMeasurements(true)) {
return;
Comment thread
cursor[bot] marked this conversation as resolved.
}

final @NotNull ITransaction transaction =
createStandaloneAppStartTransaction(startTime, null, false);
transaction.finish(SpanStatus.OK, endTime);
Comment thread
cursor[bot] marked this conversation as resolved.
}

/**
* Creates the standalone {@code app.start} transaction (not bound to the scope) and persists its
* trace headers so a later {@code ui.load} can share the same trace. Shared by the headless path
* and the eager extension path. When {@code holdOpenForExtension} is true, the transaction waits
* for its children and gets a deadline so it stays open until the extended span finishes.
*/
private @NotNull ITransaction createStandaloneAppStartTransaction(
final @NotNull SentryDate startTime,
final @Nullable TracesSamplingDecision samplingDecision,
final boolean holdOpenForExtension) {
final @NotNull AppStartMetrics metrics = AppStartMetrics.getInstance();

final TransactionOptions txnOptions = new TransactionOptions();
txnOptions.setBindToScope(false);
txnOptions.setStartTimestamp(startTime);
txnOptions.setOrigin(APP_START_TRACE_ORIGIN);
txnOptions.setAppStartTransaction(samplingDecision != null);
if (holdOpenForExtension) {
txnOptions.setWaitForChildren(true);
final long deadlineTimeoutMillis = options.getDeadlineTimeout();
txnOptions.setDeadlineTimeout(deadlineTimeoutMillis <= 0 ? null : deadlineTimeoutMillis);
}

final @NotNull TransactionContext txnContext =
new TransactionContext(
STANDALONE_APP_START_NAME,
TransactionNameSource.COMPONENT,
STANDALONE_APP_START_OP,
null);
samplingDecision);

final @NotNull ITransaction transaction = scopes.startTransaction(txnContext, txnOptions);
final @Nullable String appStartReason = metrics.getAppStartReason();
Expand All @@ -1016,10 +1075,51 @@ private void onHeadlessAppStart() {
metrics.setAppStartSentryTraceHeader(transaction.toSentryTrace().getValue());
final @Nullable BaggageHeader baggageHeader = transaction.toBaggageHeader(null);
metrics.setAppStartBaggageHeader(baggageHeader == null ? null : baggageHeader.getValue());
// Persist the end time so a later activity can decide whether its ui.load is close enough in
// time to continue this trace.
metrics.setAppStartEndTime(endTime);
return transaction;
Comment thread
cursor[bot] marked this conversation as resolved.
}

transaction.finish(SpanStatus.OK, endTime);
/**
* Handles {@code Sentry.extendAppStart()}: eagerly creates the standalone app.start transaction
* and the extended child span (we have scopes here), then hands both to the {@link
* AppStartExtension}, which owns them. The transaction is held open ({@code waitForChildren})
* until the user calls {@code Sentry.finishExtendedAppStart()} or the deadline forces it.
* Standalone-only: this is only registered as a listener when standalone app start tracing is
* enabled.
*/
private @Nullable AppStartExtension.ExtendedAppStart onExtendAppStartRequested() {
if (scopes == null
|| options == null
|| !performanceEnabled
|| !options.isEnableStandaloneAppStartTracing()) {
return null;
}
final @NotNull AppStartMetrics metrics = AppStartMetrics.getInstance();

final @NotNull TimeSpan appStartTimeSpan =
metrics.getAppStartTimeSpan().hasStarted()
? metrics.getAppStartTimeSpan()
: metrics.getSdkInitTimeSpan();
final @Nullable SentryDate startTime = appStartTimeSpan.getStartTimestamp();
if (startTime == null) {
return null;
}

final @Nullable TracesSamplingDecision samplingDecision = metrics.getAppStartSamplingDecision();
metrics.setAppStartSamplingDecision(null);

final @NotNull ITransaction transaction =
createStandaloneAppStartTransaction(startTime, samplingDecision, true);

final SpanOptions spanOptions = new SpanOptions();
setSpanOrigin(spanOptions);
final @NotNull ISpan extendedSpan =
transaction.startChild(
APP_START_EXTENDED_OP,
APP_START_EXTENDED_DESC,
AndroidDateUtils.getCurrentSentryDateTime(),
Instrumenter.SENTRY,
spanOptions);

return new AppStartExtension.ExtendedAppStart(transaction, extendedSpan);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.sentry.Hint;
import io.sentry.ISentryLifecycleToken;
import io.sentry.MeasurementUnit;
import io.sentry.SentryDate;
import io.sentry.SentryEvent;
import io.sentry.SpanContext;
import io.sentry.SpanDataConvention;
Expand All @@ -29,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -101,20 +103,49 @@ public SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) {
isHeadlessStandaloneAppStartTxn
? appStartMetrics.getAppStartTimeSpanForHeadless()
: appStartMetrics.getAppStartTimeSpanWithFallback(options);
final long appStartUpDurationMs = appStartTimeSpan.getDurationMs();
Comment thread
buenaflor marked this conversation as resolved.
final long naturalDurationMs = appStartTimeSpan.getDurationMs();

Comment thread
buenaflor marked this conversation as resolved.
final long appStartUpDurationMs;
final boolean shouldAttachAppStartSpans;
final boolean reportAppStartMeasurement;
final @NotNull AppStartExtension extension = appStartMetrics.getAppStartExtension();
if (extension.isExtended()) {
final @Nullable SentryDate extendedEnd = extension.getExtendedEndTime();
if (extendedEnd != null && appStartTimeSpan.hasStarted()) {
// Measure to the extended end, but never shorter than the natural first-frame
// duration.
final long extendedDurationMs =
TimeUnit.NANOSECONDS.toMillis(extendedEnd.nanoTimestamp())
- appStartTimeSpan.getStartTimestampMs();
appStartUpDurationMs = Math.max(naturalDurationMs, extendedDurationMs);
Comment thread
buenaflor marked this conversation as resolved.
shouldAttachAppStartSpans = appStartUpDurationMs != 0;
reportAppStartMeasurement = shouldAttachAppStartSpans;
} else {
// Deadline (null) or no valid start: attach the spans but suppress the measurement so
// it isn't inflated.
appStartUpDurationMs = 0;
shouldAttachAppStartSpans = appStartTimeSpan.hasStarted();
reportAppStartMeasurement = false;
}
} else {
appStartUpDurationMs = naturalDurationMs;
shouldAttachAppStartSpans = appStartUpDurationMs != 0;
reportAppStartMeasurement = shouldAttachAppStartSpans;
}
Comment thread
sentry[bot] marked this conversation as resolved.

// if appStartUpDurationMs is 0, metrics are not ready to be sent
if (appStartUpDurationMs != 0) {
final MeasurementValue value =
new MeasurementValue(
(float) appStartUpDurationMs, MeasurementUnit.Duration.MILLISECOND.apiName());
if (shouldAttachAppStartSpans) {
if (reportAppStartMeasurement) {
final MeasurementValue value =
new MeasurementValue(
(float) appStartUpDurationMs, MeasurementUnit.Duration.MILLISECOND.apiName());

final String appStartKey =
appStartMetrics.getAppStartType() == AppStartMetrics.AppStartType.COLD
? MeasurementValue.KEY_APP_START_COLD
: MeasurementValue.KEY_APP_START_WARM;
final String appStartKey =
appStartMetrics.getAppStartType() == AppStartMetrics.AppStartType.COLD
? MeasurementValue.KEY_APP_START_COLD
: MeasurementValue.KEY_APP_START_WARM;

transaction.getMeasurements().put(appStartKey, value);
transaction.getMeasurements().put(appStartKey, value);
}
Comment thread
buenaflor marked this conversation as resolved.

attachAppStartSpans(appStartMetrics, transaction);
appStartMetrics.onAppStartSpansSent();
Expand Down
Loading
Loading