@@ -2,12 +2,9 @@ package io.sentry.compose.navigation3
22
33import io.sentry.Breadcrumb
44import io.sentry.Hint
5- import io.sentry.ITransaction
65import io.sentry.SentryIntegrationPackageStorage
7- import io.sentry.SentryLevel.DEBUG
86import io.sentry.SentryLevel.INFO
97import io.sentry.SentryOptions
10- import io.sentry.SpanStatus
118import io.sentry.TransactionContext
129import io.sentry.TransactionOptions
1310import io.sentry.compose.navigation3.BackStackConverter.RetentionPolicy
@@ -16,6 +13,7 @@ import io.sentry.compose.navigation3.PreparedChange.BackStackHasSameTop
1613import io.sentry.compose.navigation3.PreparedChange.BackStackIsEmpty
1714import io.sentry.compose.navigation3.lifecycle.INavScope
1815import io.sentry.compose.navigation3.lifecycle.INavScopes
16+ import io.sentry.compose.navigation3.lifecycle.INavTransaction
1917import io.sentry.compose.navigation3.lifecycle.NAVIGATION_CONTEXT_KEY
2018import io.sentry.protocol.App
2119import io.sentry.protocol.TransactionNameSource
@@ -59,7 +57,7 @@ internal class BackStackObserver<T : Any>(
5957
6058 private val backStackConverter = BackStackConverter (entryMapper, scopes.options.logger)
6159
62- private val navTransaction = NavTransaction (scopes)
60+ private val navTransactions = NavTransactions (scopes)
6361 private val navBreadcrumbs = NavBreadcrumbs (scopes)
6462 private val navScreen = NavScreen ()
6563 private val navContext = NavContext (scopes, options)
@@ -83,7 +81,7 @@ internal class BackStackObserver<T : Any>(
8381 }
8482
8583 /* *
86- * Updates Sentry nav data based on the provided [backStack].
84+ * Updates Sentry nav state based on the provided [backStack].
8785 *
8886 * **Data generated**
8987 *
@@ -113,7 +111,7 @@ internal class BackStackObserver<T : Any>(
113111 }
114112
115113 /* *
116- * Clears the nav data this observer recorded.
114+ * Clears the nav state this observer recorded.
117115 *
118116 * Call it when observation ends so that no stale screen, nav context, or nav transaction outlives
119117 * it.
@@ -194,10 +192,10 @@ internal class BackStackObserver<T : Any>(
194192 navBreadcrumbs.emit(fromEntry = previousTop, toEntry = currentBackStack.topEntryNormalized)
195193 }
196194
197- navTransaction .stop(scope)
195+ navTransactions .stop(scope)
198196
199197 if (areNavigationTransactionsEnabled) {
200- navTransaction
198+ navTransactions
201199 .start(
202200 scope,
203201 currentTop.name,
@@ -231,7 +229,7 @@ internal class BackStackObserver<T : Any>(
231229 }
232230
233231 private fun tearDown (scope : INavScope ) {
234- navTransaction .stop(scope)
232+ navTransactions .stop(scope)
235233 navContext.clear(scope)
236234 navScreen.clear(scope)
237235 clearPreviousTop()
@@ -277,32 +275,22 @@ private data class BackStackData<T>(
277275)
278276
279277/* * A helper class for managing nav transactions. */
280- private class NavTransaction (private val scopes : INavScopes ) {
278+ private class NavTransactions (private val scopes : INavScopes ) {
281279
282280 private companion object {
283281 private const val TRANSACTION_ORIGIN = " auto.navigation.nav3"
284282 }
285283
286- private var activeNavTransaction: ITransaction ? = null
287-
288- /* * Starts an idle navigation transaction, or no-ops if another transaction is already active. */
284+ /* *
285+ * Starts an idle navigation transaction, or no-ops if another transaction is already active.
286+ *
287+ * [Stop][stop] the current navigation transaction first. See [INavScope.startNavTransaction].
288+ */
289289 fun start (
290290 scope : INavScope ,
291291 name : String ,
292292 arguments : Map <String , Any ?>,
293- ): ITransaction ? {
294- scope.clearFinishedTransaction()
295-
296- if (scope.transaction != null ) {
297- scopes.options.logger.log(
298- DEBUG ,
299- " Nav3 transaction for route %s won't be created because another transaction is active." ,
300- name,
301- )
302-
303- return null
304- }
305-
293+ ): INavTransaction ? {
306294 val transactionOptions =
307295 TransactionOptions ().also {
308296 it.isWaitForChildren = true
@@ -314,36 +302,25 @@ private class NavTransaction(private val scopes: INavScopes) {
314302 }
315303
316304 val transaction =
317- scopes.startTransaction (
305+ scope.startNavTransaction (
318306 TransactionContext (name, TransactionNameSource .ROUTE , NAVIGATION_OP ),
319307 transactionOptions,
320- )
308+ ) ? : return null
321309
322- // Not an error: INavScopes.startTransaction may decline to start a transaction by design.
323- if (transaction.isNoOp) {
324- return null
310+ if (arguments.isNotEmpty()) {
311+ transaction.setData(" arguments" , arguments)
325312 }
326313
327- activeNavTransaction = transaction
328-
329- transaction.apply {
330- if (arguments.isNotEmpty()) {
331- setData(" arguments" , arguments)
332- }
333- }
334-
335- scope.bindTransaction(transaction)
336-
337314 return transaction
338315 }
339316
340- /* * Finishes and unsets the active navigation transaction, if one exists. */
317+ /* *
318+ * Finishes and unsets the active navigation transaction, if one exists.
319+ *
320+ * See [INavScope.finishNavTransaction].
321+ */
341322 fun stop (scope : INavScope ) {
342- val transaction = activeNavTransaction ? : return
343- val status = transaction.status ? : SpanStatus .OK
344- transaction.finish(status)
345- scope.unbindTransaction(transaction)
346- activeNavTransaction = null
323+ scope.finishNavTransaction()
347324 }
348325}
349326
@@ -377,15 +354,15 @@ private class NavContext(private val scopes: INavScopes, private val options: Se
377354 * proper values to the transaction context instead.
378355 */
379356 fun <T : Any > updateTransaction (
380- transaction : ITransaction ,
357+ transaction : INavTransaction ,
381358 scope : INavScope ,
382359 backStack : BackStackData <T >,
383360 ) {
384361 if (scopes.options.isEnableScreenTracking) {
385- val appContext = transaction.contexts.app ? : scope.app ? : App ()
362+ val appContext = scope.app ? : App ()
386363
387364 appContext.viewNames = listOf (backStack.topEntryNormalized.name)
388- transaction.contexts. setApp(appContext)
365+ transaction.setApp(appContext)
389366 }
390367
391368 if (options.captureBackStack && backStack.capturedEntriesNormalized.isNotEmpty()) {
0 commit comments