-
-
Notifications
You must be signed in to change notification settings - Fork 475
feat(extend-app-start): [3/4] Eagerly create the extended app start transaction #5608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
buenaflor
wants to merge
34
commits into
feat/app-start-extension-android
Choose a base branch
from
feat/app-start-extension-materialize
base: feat/app-start-extension-android
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
d996425
feat(extend-app-start): Eagerly create the extended App Start transacโฆ
buenaflor 51e4969
chore(extend-app-start): Drop the redundant foreground-check comment โฆ
buenaflor 4c1f0d7
test(extend-app-start): Replace the no-op finish test with isExtendedโฆ
buenaflor 48bb3a1
test(extend-app-start): Drop the no-value getAppStartExtension test aโฆ
buenaflor 9fa64fd
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor 38f83e1
chore(extend-app-start): Trim and de-duplicate comments in the eager โฆ
buenaflor 55decba
chore(extend-app-start): Clarify the extensionActive comment
buenaflor f0a85b0
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor 66cd87d
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor 571416e
ref(extend-app-start): Rename extended app start span op to app.startโฆ
buenaflor b4f34ce
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor 1eb12d5
fix(extend-app-start): Fix headless app start end time and duplicate txn
buenaflor b5bf4ec
style(extend-app-start): Trim low-value comments in the headless fix
buenaflor bb88dad
style(extend-app-start): Drop redundant extend-listener comment
buenaflor 85e23d8
style(extend-app-start): Trim redundant comments in onActivityCreated
buenaflor f2d1c34
style(extend-app-start): Remove explanatory comments in app start paths
buenaflor d2df48b
fix(extend-app-start): Consume stored app start trace on the extensioโฆ
buenaflor 142a9d2
fix(extend-app-start): Only the launch activity attaches the app starโฆ
buenaflor dd7b3e0
Format code
getsentry-bot b7da10f
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor 0de722b
style(extend-app-start): Trim verbose comments in app start paths
buenaflor c2cdb14
Merge remote-tracking branch 'origin/feat/app-start-extension-materiaโฆ
buenaflor 2a02616
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor df8cfe4
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor b442c1e
style(extend-app-start): Drop two line-narrating test comments
buenaflor 642cfb0
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor e12f7b0
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor 9ebdd09
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor 824c12f
test(extend-app-start): Drop narrating comments from app start tests
buenaflor d87e908
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor c861ba9
refactor(extend-app-start): Name app start branching booleans by intent
buenaflor d8ffbbc
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor fd32a34
Merge branch 'feat/app-start-extension-android' into feat/app-start-eโฆ
buenaflor 3d4d55a
test(extend-app-start): Assert null extended span now that getExtendeโฆ
buenaflor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
|
@@ -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"); | ||
| } | ||
|
|
||
|
|
@@ -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."); | ||
|
|
@@ -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(); | ||
|
|
||
| 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(); | ||
|
|
@@ -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); | ||
|
cursor[bot] marked this conversation as resolved.
buenaflor marked this conversation as resolved.
|
||
| } | ||
|
buenaflor marked this conversation as resolved.
|
||
|
|
||
| final @Nullable TransactionContext continuedContext = | ||
| continueSentryTrace == null | ||
| ? null | ||
|
|
@@ -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); | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| final @NotNull ITransaction transaction = | ||
| createStandaloneAppStartTransaction(startTime, null, false); | ||
| transaction.finish(SpanStatus.OK, endTime); | ||
|
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(); | ||
|
|
@@ -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; | ||
|
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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we document why are we setting this to |
||
|
|
||
| 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.