File tree Expand file tree Collapse file tree
main/java/io/sentry/android/core
test/java/io/sentry/android/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -193,6 +193,8 @@ public final class io/sentry/android/core/AppStartExtension : io/sentry/IAppStar
193193 public fun getExtendedAppStartSpan ()Lio/sentry/ISpan;
194194 public fun getExtendedEndTime ()Lio/sentry/SentryDate;
195195 public fun isActive ()Z
196+ public fun isExtended ()Z
197+ public fun setData (Ljava/lang/String;Ljava/lang/Object;)V
196198 public fun setExtendAppStartListener (Lio/sentry/android/core/AppStartExtension$ExtendAppStartListener;)V
197199}
198200
Original file line number Diff line number Diff line change @@ -80,6 +80,19 @@ public void extendAppStart() {
8080 }
8181 }
8282
83+ /**
84+ * Sets data on the owned (eager) transaction if it is still open. Used to attach the screen name
85+ * once the first activity is known, since the transaction is created in {@code onCreate} before
86+ * any activity exists.
87+ */
88+ public void setData (final @ NotNull String key , final @ Nullable Object value ) {
89+ try (final @ NotNull ISentryLifecycleToken ignored = lock .acquire ()) {
90+ if (extendedTransaction != null && !extendedTransaction .isFinished ()) {
91+ extendedTransaction .setData (key , value );
92+ }
93+ }
94+ }
95+
8396 @ Override
8497 public void finishExtendedAppStart () {
8598 try (final @ NotNull ISentryLifecycleToken ignored = lock .acquire ()) {
@@ -108,6 +121,16 @@ public boolean isActive() {
108121 }
109122 }
110123
124+ /**
125+ * Whether this app start was extended at all, regardless of finish or deadline state. Used by the
126+ * event processor to decide whether to apply the never-shorten vital logic.
127+ */
128+ public boolean isExtended () {
129+ try (final @ NotNull ISentryLifecycleToken ignored = lock .acquire ()) {
130+ return extendedSpan != null ;
131+ }
132+ }
133+
111134 public void finishTransaction (final @ NotNull SentryDate endTimestamp ) {
112135 try (final @ NotNull ISentryLifecycleToken ignored = lock .acquire ()) {
113136 final @ Nullable ITransaction transaction = extendedTransaction ;
Original file line number Diff line number Diff line change @@ -135,6 +135,18 @@ class AppStartExtensionTest {
135135 assertFalse(ext.isActive)
136136 }
137137
138+ @Test
139+ fun `isExtended stays true once extended, even after the transaction finishes` () {
140+ val ext = extension(windowOpen = true )
141+ assertFalse(ext.isExtended)
142+ val (txn, _) = ext.registerHandOver()
143+ ext.extendAppStart()
144+ assertTrue(ext.isExtended)
145+ whenever(txn.isFinished).thenReturn(true )
146+ assertFalse(ext.isActive)
147+ assertTrue(ext.isExtended)
148+ }
149+
138150 @Test
139151 fun `finishTransaction finishes the transaction at the given timestamp` () {
140152 val ext = extension(windowOpen = true )
You can’t perform that action at this time.
0 commit comments