Skip to content

Commit c861ba9

Browse files
buenaflorclaude
andcommitted
refactor(extend-app-start): Name app start branching booleans by intent
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d87e908 commit c861ba9

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,23 +265,23 @@ private void startTracing(final @NotNull Activity activity) {
265265
transactionOptions.setAppStartTransaction(appStartSamplingDecision != null);
266266
setSpanOrigin(transactionOptions);
267267

268-
// Guards the headless-start check below with !extensionActive so the eager extension's
268+
// Guards the headless-start check below with !isExtensionActive so the eager extension's
269269
// stored trace id isn't mistaken for a finished headless start.
270-
final boolean extensionActive =
270+
final boolean isExtensionActive =
271271
AppStartMetrics.getInstance().getAppStartExtension().isActive();
272272

273273
final @Nullable SentryId storedAppStartTraceId =
274274
AppStartMetrics.getInstance().getAppStartTraceId();
275275
final boolean isFollowingHeadlessAppStart =
276-
!extensionActive && (storedAppStartTraceId != null);
276+
!isExtensionActive && (storedAppStartTraceId != null);
277277

278278
final boolean isAppStart =
279279
!(firstActivityCreated || appStartTime == null || coldStart == null);
280280
final boolean createStandaloneAppStart =
281281
isAppStart
282282
&& options.isEnableStandaloneAppStartTracing()
283283
&& !isFollowingHeadlessAppStart
284-
&& !extensionActive;
284+
&& !isExtensionActive;
285285

286286
if (createStandaloneAppStart) {
287287
final TransactionOptions appStartTransactionOptions = new TransactionOptions();
@@ -312,7 +312,7 @@ private void startTracing(final @NotNull Activity activity) {
312312
continueSentryTrace = appStartTransaction.toSentryTrace().getValue();
313313
final @Nullable BaggageHeader baggageHeader = appStartTransaction.toBaggageHeader(null);
314314
continueBaggage = baggageHeader == null ? null : baggageHeader.getValue();
315-
} else if (extensionActive
315+
} else if (isExtensionActive
316316
|| (isFollowingHeadlessAppStart && isWithinAppStartContinuationWindow(ttidStartTime))) {
317317
continueSentryTrace = AppStartMetrics.getInstance().getAppStartSentryTraceHeader();
318318
continueBaggage = AppStartMetrics.getInstance().getAppStartBaggageHeader();
@@ -321,7 +321,7 @@ private void startTracing(final @NotNull Activity activity) {
321321
continueBaggage = null;
322322
}
323323

324-
if (extensionActive && isAppStart) {
324+
if (isExtensionActive && isAppStart) {
325325
// Only the launch activity sets the screen, so a later activity can't overwrite it. A
326326
// screen also keeps the processor from classifying the eager app.start as headless.
327327
AppStartMetrics.getInstance()
@@ -348,7 +348,7 @@ private void startTracing(final @NotNull Activity activity) {
348348
transactionOptions);
349349
}
350350

351-
if (isFollowingHeadlessAppStart || extensionActive) {
351+
if (isFollowingHeadlessAppStart || isExtensionActive) {
352352
// Consume the stored app-start trace so a later activity doesn't reuse it.
353353
AppStartMetrics.getInstance().setAppStartTraceId(null);
354354
AppStartMetrics.getInstance().setAppStartSentryTraceHeader(null);

sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) {
106106
final long naturalDurationMs = appStartTimeSpan.getDurationMs();
107107

108108
final long appStartUpDurationMs;
109-
// Not ready (duration 0 on a non-extended start) leaves it for a later transaction.
110-
final boolean appStartReady;
109+
final boolean shouldAttachAppStartSpans;
110+
final boolean reportAppStartMeasurement;
111111
final @NotNull AppStartExtension extension = appStartMetrics.getAppStartExtension();
112112
if (extension.isExtended()) {
113113
final @Nullable SentryDate extendedEnd = extension.getExtendedEndTime();
@@ -118,20 +118,23 @@ public SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) {
118118
TimeUnit.NANOSECONDS.toMillis(extendedEnd.nanoTimestamp())
119119
- appStartTimeSpan.getStartTimestampMs();
120120
appStartUpDurationMs = Math.max(naturalDurationMs, extendedDurationMs);
121-
appStartReady = appStartUpDurationMs != 0;
121+
shouldAttachAppStartSpans = appStartUpDurationMs != 0;
122+
reportAppStartMeasurement = shouldAttachAppStartSpans;
122123
} else {
123-
// Deadline (null) or no valid start: suppress the measurement to avoid an inflated
124-
// value, but still finalize the spans.
124+
// Deadline (null) or no valid start: attach the spans but suppress the measurement so
125+
// it isn't inflated.
125126
appStartUpDurationMs = 0;
126-
appStartReady = appStartTimeSpan.hasStarted();
127+
shouldAttachAppStartSpans = appStartTimeSpan.hasStarted();
128+
reportAppStartMeasurement = false;
127129
}
128130
} else {
129131
appStartUpDurationMs = naturalDurationMs;
130-
appStartReady = appStartUpDurationMs != 0;
132+
shouldAttachAppStartSpans = appStartUpDurationMs != 0;
133+
reportAppStartMeasurement = shouldAttachAppStartSpans;
131134
}
132135

133-
if (appStartReady) {
134-
if (appStartUpDurationMs != 0) {
136+
if (shouldAttachAppStartSpans) {
137+
if (reportAppStartMeasurement) {
135138
final MeasurementValue value =
136139
new MeasurementValue(
137140
(float) appStartUpDurationMs, MeasurementUnit.Duration.MILLISECOND.apiName());

0 commit comments

Comments
 (0)